oop.go 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162
  1. package oop
  2. import (
  3. "bufio"
  4. "bytes"
  5. "context"
  6. "crypto/md5"
  7. "crypto/tls"
  8. b64 "encoding/base64"
  9. "encoding/hex"
  10. "encoding/json"
  11. "errors"
  12. "fmt"
  13. "io"
  14. "io/ioutil"
  15. "math/rand"
  16. "net/http"
  17. "net/url"
  18. "os"
  19. "os/exec"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "time"
  24. "unicode/utf8"
  25. "golang.org/x/net/http2"
  26. "github.com/bashery/botline/channel"
  27. "github.com/bashery/botline/hashmap"
  28. "github.com/bashery/botline/modcompact"
  29. "github.com/bashery/thrift"
  30. "github.com/tidwall/gjson"
  31. talkservice "github.com/bashery/linethrift"
  32. "github.com/imroc/req"
  33. )
  34. func HashToMap(mas *hashmap.HashMap) map[string]interface{} {
  35. ama := map[string]interface{}{}
  36. aa := mas.Listing() //.Listing()
  37. for _, ma := range aa {
  38. ama[ma.Key.(string)] = ma.Value
  39. }
  40. return ama
  41. }
  42. type (
  43. tagdata struct {
  44. S string `json:"S"`
  45. E string `json:"E"`
  46. M string `json:"M"`
  47. }
  48. mentions struct {
  49. MENTIONEES []struct {
  50. Start string `json:"S"`
  51. End string `json:"E"`
  52. Mid string `json:"M"`
  53. } `json:"MENTIONEES"`
  54. }
  55. SaveJoin struct {
  56. User []string
  57. Time []int64
  58. }
  59. Helper struct {
  60. Rngcmd map[string]int
  61. }
  62. ProfileCoverStruct struct {
  63. Code int `json:"code"`
  64. Message string `json:"message"`
  65. Result struct {
  66. HomeId string `json:"homeId"`
  67. HomeType string `json:"homeType"`
  68. HasNewPost bool `json:"hasNewPost"`
  69. CoverObsInfo struct {
  70. ObsNamespace string `json:"obsNamespace"`
  71. ServiceName string `json:"serviceName"`
  72. ObjectId string `json:"objectId"`
  73. } `json:"coverObsInfo"`
  74. VideoCoverObsInfo struct {
  75. ObsNamespace string `json:"obsNamespace"`
  76. ServiceName string `json:"serviceName"`
  77. ObjectId string `json:"objectId"`
  78. } `json:"videoCoverObsInfo"`
  79. PostCount int `json:"postCount"`
  80. FollowSummaryInfo struct {
  81. FollowingCount int `json:"followingCount"`
  82. FollowerCount int `json:"followerCount"`
  83. Following bool `json:"following"`
  84. AllowFollow bool `json:"allowFollow"`
  85. ShowFollowList bool `json:"showFollowList"`
  86. } `json:"followSummaryInfo"`
  87. GiftShopInfo struct {
  88. GiftShopScheme string `json:"giftShopScheme"`
  89. BirthdayGiftShopScheme string `json:"birthdayGiftShopScheme"`
  90. GiftShopUrl string `json:"giftShopUrl"`
  91. IsGiftShopAvailable bool `json:"isGiftShopAvailable"`
  92. } `json:"giftShopInfo"`
  93. UserStyleMedia struct {
  94. MenuInfo struct {
  95. LatestEditTime int64 `json:"latestEditTime"`
  96. } `json:"menuInfo"`
  97. AvatarMenuInfo struct {
  98. LatestEditTime int64 `json:"latestEditTime"`
  99. } `json:"avatarMenuInfo"`
  100. } `json:"userStyleMedia"`
  101. Meta struct {
  102. } `json:"meta"`
  103. } `json:"result"`
  104. }
  105. Account struct {
  106. AuthToken string
  107. AppName string
  108. UserAgent string
  109. Host string
  110. MID string
  111. Shnall string
  112. Limited bool
  113. Frez bool
  114. Limitadd bool
  115. Waitadd bool
  116. Seq int32
  117. Carrier string
  118. Akick int
  119. Ainvite int
  120. CustomPoint int
  121. KickCount int
  122. CancelCount int
  123. InvCount int
  124. Curtime int64
  125. TempKick int
  126. TempInv int
  127. KickPoint int
  128. Add int
  129. Acancel int
  130. Namebot string
  131. IpProxy string
  132. Numar int
  133. Ckick int
  134. SessionPoll *thrift.THttpClient
  135. Transport *http.Transport
  136. Timeadd time.Time
  137. TimeBan time.Time
  138. Lastkick time.Time
  139. Lastinvite time.Time
  140. Lastcancel time.Time
  141. Lastadd time.Time
  142. CountDay int
  143. Locale string
  144. HttpHeader http.Header
  145. hc *http.Client
  146. UrS4 string
  147. UrP5 string
  148. Cinvite int
  149. Ccancel int
  150. SHani int
  151. Count int32
  152. Revision int64
  153. GRevision int64
  154. Ctx context.Context
  155. reqSeqMessage int32
  156. IRevision int64
  157. Cpoll int
  158. Squads []string
  159. Backup []string
  160. }
  161. BanUser struct {
  162. Banlist []string
  163. Fucklist []string
  164. Mutelist []string
  165. }
  166. Access struct {
  167. Creator []string
  168. Seller []string
  169. Buyer []string
  170. Owner []string
  171. Master []string
  172. Admin []string
  173. Bot []string
  174. }
  175. LineRoom struct {
  176. Name string
  177. Id string
  178. Lurk bool
  179. Announce bool
  180. Userlurk []string
  181. NameLurk string
  182. Leavebool bool
  183. Backleave bool
  184. MsgLeave string
  185. MsgLurk string
  186. ProKick bool
  187. ProQr bool
  188. ProName bool
  189. ImageLurk bool
  190. ProInvite bool
  191. ProJoin bool
  192. ProCancel bool
  193. Limit bool
  194. Welcome bool
  195. WelcomeMsg string
  196. AntiTag bool
  197. Automute bool
  198. LeaveBack []string
  199. Gowner []string
  200. ListInvited []string
  201. Gadmin []string
  202. Gban []string
  203. Exe *Account
  204. Bot []string
  205. GoMid []string
  206. Client []*Account
  207. Ava []*Ava
  208. GoClient []*Account
  209. HaveClient []*Account
  210. Invite int
  211. Kick int
  212. Cancel int
  213. Fight time.Time
  214. Leave time.Time
  215. Backup bool
  216. Qr bool
  217. Purge bool
  218. }
  219. Ava struct {
  220. Client *Account
  221. Exist bool
  222. Mid string
  223. }
  224. Command struct {
  225. Botname string
  226. Upallimage string
  227. Upallcover string
  228. Unsend string
  229. Upvallimage string
  230. Upvallcover string
  231. Appname string
  232. Useragent string
  233. Hostname string
  234. Friends string
  235. Adds string
  236. Limits string
  237. Addallbots string
  238. Addallsquads string
  239. Leave string
  240. Respon string
  241. Ping string
  242. Count string
  243. Limitout string
  244. Access string
  245. Allbanlist string
  246. Allgaccess string
  247. Gaccess string
  248. Checkram string
  249. Backups string
  250. Upimage string
  251. Upcover string
  252. Upvimage string
  253. Upvcover string
  254. Bringall string
  255. Purgeall string
  256. Banlist string
  257. Clearban string
  258. Stayall string
  259. Clearchat string
  260. Here string
  261. Speed string
  262. Status string
  263. Tagall string
  264. Kick string
  265. Max string
  266. None string
  267. Kickall string
  268. Cancelall string
  269. }
  270. )
  271. var (
  272. Random bool
  273. Waitadd = []*Account{}
  274. BlockAdd = &hashmap.HashMap{}
  275. CoverVideo = ""
  276. PathProxy = ""
  277. GetBlock = &hashmap.HashMap{}
  278. GetBlockAdd = &hashmap.HashMap{}
  279. limiterBot = map[string]time.Time{}
  280. KickBans = []*Account{}
  281. SquadRoom = []*LineRoom{}
  282. Room = &LineRoom{}
  283. err error
  284. AccessUser = []*Access{}
  285. ListProxy = []string{}
  286. )
  287. func Loadproxy(base string) {
  288. fn := base + ".json"
  289. file, err := os.Open(fn)
  290. if err != nil {
  291. fmt.Println(err)
  292. return
  293. }
  294. scanner := bufio.NewScanner(file)
  295. scanner.Split(bufio.ScanLines)
  296. var txtlines []string
  297. for scanner.Scan() {
  298. txtlines = append(txtlines, scanner.Text())
  299. }
  300. file.Close()
  301. asu := strings.Join(txtlines, "\n")
  302. getcan := gjson.Get(asu, "proxy")
  303. if getcan.Exists() {
  304. for _, a := range getcan.Array() {
  305. ListProxy = append(ListProxy, a.String())
  306. }
  307. }
  308. }
  309. //---------Access----------------
  310. func (self *Access) AddCreator(user string) {
  311. defer PanicOnly()
  312. if !InArray(self.Creator, user) {
  313. self.Creator = append(self.Creator, user)
  314. }
  315. }
  316. func (self *Access) DelCreator(user string) {
  317. defer PanicOnly()
  318. if InArray(self.Creator, user) {
  319. self.Creator = Remove(self.Creator, user)
  320. }
  321. }
  322. func (self *Access) GetCreator(user string) bool {
  323. defer PanicOnly()
  324. if InArray(self.Creator, user) {
  325. return true
  326. }
  327. return false
  328. }
  329. func (self *Access) ClearCreator() {
  330. defer PanicOnly()
  331. self.Creator = []string{}
  332. }
  333. //------------------------
  334. func (self *Access) AddSeller(user string) {
  335. defer PanicOnly()
  336. if !InArray(self.Seller, user) {
  337. self.Seller = append(self.Seller, user)
  338. }
  339. }
  340. func (self *Access) DelSeller(user string) {
  341. defer PanicOnly()
  342. if InArray(self.Seller, user) {
  343. self.Seller = Remove(self.Seller, user)
  344. }
  345. }
  346. func (self *Access) GetSeller(user string) bool {
  347. defer PanicOnly()
  348. if InArray(self.Seller, user) {
  349. return true
  350. }
  351. return false
  352. }
  353. func (self *Access) ClearSeller() {
  354. defer PanicOnly()
  355. self.Seller = []string{}
  356. }
  357. //------------------------
  358. func (self *Access) AddBuyer(user string) {
  359. defer PanicOnly()
  360. if !InArray(self.Buyer, user) {
  361. self.Buyer = append(self.Buyer, user)
  362. }
  363. }
  364. func (self *Access) DelBuyer(user string) {
  365. defer PanicOnly()
  366. if InArray(self.Buyer, user) {
  367. self.Buyer = Remove(self.Buyer, user)
  368. }
  369. }
  370. func (self *Access) GetBuyer(user string) bool {
  371. defer PanicOnly()
  372. if InArray(self.Buyer, user) {
  373. return true
  374. }
  375. return false
  376. }
  377. func (self *Access) ClearBuyer() {
  378. defer PanicOnly()
  379. self.Buyer = []string{}
  380. }
  381. //------------------------
  382. func (self *Access) AddOwner(user string) {
  383. defer PanicOnly()
  384. if !InArray(self.Owner, user) {
  385. self.Owner = append(self.Owner, user)
  386. }
  387. }
  388. func (self *Access) DelOwner(user string) {
  389. defer PanicOnly()
  390. if InArray(self.Owner, user) {
  391. self.Owner = Remove(self.Owner, user)
  392. }
  393. }
  394. func (self *Access) GetOwner(user string) bool {
  395. defer PanicOnly()
  396. if InArray(self.Owner, user) {
  397. return true
  398. }
  399. return false
  400. }
  401. func (self *Access) ClearOwner() {
  402. defer PanicOnly()
  403. self.Owner = []string{}
  404. }
  405. //------------------------
  406. func (self *Access) AddMaster(user string) {
  407. defer PanicOnly()
  408. if !InArray(self.Master, user) {
  409. self.Master = append(self.Master, user)
  410. }
  411. }
  412. func (self *Access) DelMaster(user string) {
  413. defer PanicOnly()
  414. if InArray(self.Master, user) {
  415. self.Master = Remove(self.Master, user)
  416. }
  417. }
  418. func (self *Access) GetMaster(user string) bool {
  419. defer PanicOnly()
  420. if InArray(self.Master, user) {
  421. return true
  422. }
  423. return false
  424. }
  425. func (self *Access) ClearMaster() {
  426. defer PanicOnly()
  427. self.Master = []string{}
  428. }
  429. //------------------------
  430. func (self *Access) AddAdmin(user string) {
  431. defer PanicOnly()
  432. if !InArray(self.Admin, user) {
  433. self.Admin = append(self.Admin, user)
  434. }
  435. }
  436. func (self *Access) DelAdmin(user string) {
  437. defer PanicOnly()
  438. if InArray(self.Admin, user) {
  439. self.Admin = Remove(self.Admin, user)
  440. }
  441. }
  442. func (self *Access) GetAdmin(user string) bool {
  443. defer PanicOnly()
  444. if InArray(self.Admin, user) {
  445. return true
  446. }
  447. return false
  448. }
  449. func (self *Access) ClearAdmin() {
  450. defer PanicOnly()
  451. self.Admin = []string{}
  452. }
  453. //------------------------
  454. func (self *Access) AddBot(user string) {
  455. defer PanicOnly()
  456. if !InArray(self.Bot, user) {
  457. self.Bot = append(self.Bot, user)
  458. }
  459. }
  460. func (self *Access) DelBot(user string) {
  461. defer PanicOnly()
  462. if InArray(self.Bot, user) {
  463. self.Bot = Remove(self.Bot, user)
  464. }
  465. }
  466. func (self *Access) GetBot(user string) bool {
  467. defer PanicOnly()
  468. if InArray(self.Bot, user) {
  469. return true
  470. }
  471. return false
  472. }
  473. func (self *Access) ClearBot() {
  474. defer PanicOnly()
  475. self.Bot = []string{}
  476. }
  477. //------------------------
  478. func (self *BanUser) AddBan(user string) {
  479. defer PanicOnly()
  480. if !InArray(self.Banlist, user) && user != "" {
  481. self.Banlist = append(self.Banlist, user)
  482. }
  483. }
  484. func (self *BanUser) DelBan(user string) {
  485. defer PanicOnly()
  486. if InArray(self.Banlist, user) {
  487. self.Banlist = Remove(self.Banlist, user)
  488. }
  489. }
  490. func (self *BanUser) GetBan(user string) bool {
  491. defer PanicOnly()
  492. if InArray(self.Banlist, user) {
  493. return true
  494. }
  495. return false
  496. }
  497. func (self *BanUser) AddFuck(user string) {
  498. defer PanicOnly()
  499. if !InArray(self.Fucklist, user) && user != "" {
  500. self.Fucklist = append(self.Fucklist, user)
  501. }
  502. }
  503. func (self *BanUser) DelFuck(user string) {
  504. defer PanicOnly()
  505. if InArray(self.Fucklist, user) {
  506. self.Fucklist = Remove(self.Fucklist, user)
  507. }
  508. }
  509. func (self *BanUser) GetFuck(user string) bool {
  510. defer PanicOnly()
  511. if InArray(self.Fucklist, user) {
  512. return true
  513. }
  514. return false
  515. }
  516. func (self *BanUser) AddMute(user string) {
  517. defer PanicOnly()
  518. if !InArray(self.Mutelist, user) && user != "" {
  519. self.Mutelist = append(self.Mutelist, user)
  520. }
  521. }
  522. func (self *BanUser) DelMute(user string) {
  523. defer PanicOnly()
  524. if InArray(self.Mutelist, user) {
  525. self.Mutelist = Remove(self.Mutelist, user)
  526. }
  527. }
  528. func (self *BanUser) GetMute(user string) bool {
  529. defer PanicOnly()
  530. if InArray(self.Mutelist, user) {
  531. return true
  532. }
  533. return false
  534. }
  535. func (cl *Account) SendImageWithURL(to string, url string) {
  536. res, err := http.Get("https://minz-restapi.xyz/sendimgurl?authtoken=" + cl.AuthToken + "&to=" + to + "&url=" + url)
  537. if err != nil {
  538. fmt.Println("Failed")
  539. return
  540. }
  541. if res.StatusCode == 200 {
  542. }
  543. }
  544. func (s *Account) CountKick() {
  545. var asu int
  546. var cokss int
  547. cokss = s.SHani + 1
  548. asu = s.Ckick + 1
  549. s.Ckick = asu
  550. s.SHani = cokss
  551. }
  552. func (s *Account) CCancel() {
  553. var asu int
  554. asu = s.Ccancel + 1
  555. s.Ccancel = asu
  556. }
  557. func (s *Account) CInvite() {
  558. var asu int
  559. asu = s.Cinvite + 1
  560. s.Cinvite = asu
  561. }
  562. func InArray(ArrList []string, rstr string) bool {
  563. for _, x := range ArrList {
  564. if x == rstr {
  565. return true
  566. }
  567. }
  568. return false
  569. }
  570. func InArrayInt(arr []int, str int) bool {
  571. for _, tar := range arr {
  572. if tar == str {
  573. return true
  574. }
  575. }
  576. return false
  577. }
  578. func CheckEqual(list1 []string, list2 []string) bool {
  579. for _, v := range list1 {
  580. if InArray(list2, v) {
  581. return true
  582. }
  583. }
  584. return false
  585. }
  586. func Randint(min int, max int) int {
  587. return rand.Intn(max-min) + min
  588. }
  589. func IsMember(members map[string]int64, mid string) bool {
  590. for x := range members {
  591. if x == mid {
  592. return true
  593. }
  594. }
  595. return false
  596. }
  597. func Checkmulti(list1 []string, list2 []string) bool {
  598. for _, v := range list1 {
  599. if InArray(list2, v) {
  600. return true
  601. }
  602. }
  603. return false
  604. }
  605. func IndexOf(data []string, element string) int {
  606. for k, v := range data {
  607. if element == v {
  608. return k
  609. break
  610. }
  611. }
  612. return -1
  613. }
  614. func (self *Account) Getcontactuser(id string) (err error) {
  615. defer PanicOnly()
  616. client := self.Talk()
  617. _, err = client.GetContact(self.Ctx, id)
  618. if err != nil {
  619. return err
  620. }
  621. return err
  622. }
  623. func (self *Account) GetGroup(groupId string) (r *talkservice.Group) {
  624. defer PanicOnly()
  625. client := self.Talk()
  626. r, _ = client.GetGroup(self.Ctx, groupId)
  627. return r
  628. }
  629. func (client *Account) SendPollMention(to string, jenis string, memlist []string) {
  630. defer PanicOnly()
  631. ta := false
  632. tx := ""
  633. tag := []string{}
  634. z := len(memlist) / 20
  635. y := z + 1
  636. for i := 0; i < y; i++ {
  637. if !ta {
  638. tx += fmt.Sprintf("%s\n", jenis)
  639. ta = true
  640. }
  641. if i == z {
  642. tag = memlist[i*20:]
  643. no := i * 20
  644. no += 1
  645. for i := 0; i < len(tag); i++ {
  646. iki := no + i
  647. tx += fmt.Sprintf("\n%v. @!", iki)
  648. }
  649. } else {
  650. tag = memlist[i*20 : (i+1)*20]
  651. no := i * 20
  652. no += 1
  653. for i := 0; i < len(tag); i++ {
  654. iki := no + i
  655. if iki < 10 {
  656. tx += fmt.Sprintf("\n%v. @!", iki)
  657. } else {
  658. tx += fmt.Sprintf("\n%v. @!", iki)
  659. }
  660. }
  661. }
  662. if len(tag) != 0 {
  663. client.SendMention(to, tx, tag)
  664. }
  665. tx = ""
  666. }
  667. }
  668. func (self *Account) LeaveGroup(groupId string) (err error) {
  669. req := &talkservice.DeleteSelfFromChatRequest{
  670. ChatMid: groupId,
  671. ReqSeq: self.Seq,
  672. LastSeenMessageDeliveredTime: 0,
  673. LastSeenMessageId: "",
  674. LastMessageDeliveredTime: 0,
  675. LastMessageId: "",
  676. }
  677. _, err = self.Talk().DeleteSelfFromChat(context.TODO(), req)
  678. self.Seq++
  679. return err
  680. }
  681. func (s *Account) UnsendChatnume(toId string, text string) (err error) {
  682. client := s.Talk()
  683. err = client.UnsendMessage(s.Ctx, int32(0), text)
  684. return err
  685. }
  686. func (s *Account) RemoveAllMessage(lastMessageId string) {
  687. client := s.Talk()
  688. client.RemoveAllMessages(s.Ctx, s.Seq, lastMessageId)
  689. }
  690. func InArrayCl(List []*Account, self *Account) bool {
  691. for _, x := range List {
  692. if x == self {
  693. return true
  694. }
  695. }
  696. return false
  697. }
  698. func CheckErr(self *Account, e error, s string, t string) int {
  699. val := GetCode(e)
  700. if val == 35 {
  701. if !InArrayCl(KickBans, self) {
  702. KickBans = append(KickBans, self)
  703. self.TimeBan = time.Now()
  704. }
  705. self.Limited = true
  706. if _, ok := GetBlock.Get(self.MID); !ok {
  707. GetBlock.Set(self.MID, time.Now())
  708. }
  709. } else if val == 20 {
  710. if strings.Contains(e.Error(), "suspended") {
  711. if !InArrayCl(KickBans, self) {
  712. KickBans = append(KickBans, self)
  713. self.TimeBan = time.Now()
  714. }
  715. self.Limited = true
  716. self.Frez = true
  717. }
  718. }
  719. return val
  720. }
  721. func GetCode(e error) int {
  722. jos := e.Error()
  723. if strings.Contains(jos, "ABUSE_BLOCK") {
  724. return 35
  725. } else if strings.Contains(jos, "INTERNAL_ERROR") || strings.Contains(jos, "suspended") {
  726. return 20
  727. } else {
  728. return 0
  729. }
  730. }
  731. func (s *Account) UpdateProfilePicture(path, tipe string) error {
  732. fl, err := os.Open(path)
  733. if err != nil {
  734. return err
  735. }
  736. defer fl.Close()
  737. of, err := fl.Stat()
  738. if err != nil {
  739. return err
  740. }
  741. var size int64 = of.Size()
  742. bytess := make([]byte, size)
  743. buffer := bufio.NewReader(fl)
  744. _, err = buffer.Read(bytess)
  745. if err != nil {
  746. return err
  747. }
  748. dataa := ""
  749. nama := filepath.Base(path)
  750. if tipe == "vp" {
  751. dataa = fmt.Sprintf(`{"name": "%s", "oid": "%s", "type": "image", "ver": "2.0", "cat": "vp.mp4"}`, nama, s.MID)
  752. } else {
  753. dataa = fmt.Sprintf(`{"name": "%s", "oid": "%s", "type": "image", "ver": "2.0"}`, nama, s.MID)
  754. }
  755. sDec := b64.StdEncoding.EncodeToString([]byte(dataa))
  756. cl := s.hc
  757. req, _ := http.NewRequest("POST", "https://obs-sg.line-apps.com/talk/p/upload.nhn", bytes.NewBuffer(bytess))
  758. for k, v := range map[string]string{
  759. "User-Agent": s.UserAgent,
  760. "X-Line-Application": s.AppName,
  761. "X-Line-Access": s.AuthToken,
  762. "x-lal": s.Locale,
  763. "x-lpv": "1",
  764. } {
  765. req.Header.Set(k, v)
  766. }
  767. req.Header.Set("x-obs-params", string(sDec))
  768. req.ContentLength = int64(len(bytess))
  769. res, err := cl.Do(req)
  770. if err != nil {
  771. return err
  772. }
  773. defer res.Body.Close()
  774. return nil
  775. }
  776. func (p *Account) DownloadObjectMsg(msgid string, t ...string) (string, error) {
  777. var tipe string
  778. if len(t) == 0 {
  779. tipe = "jpg"
  780. } else {
  781. tipe = t[0]
  782. }
  783. client := p.hc
  784. req, _ := http.NewRequest("GET", "https://obs-sg.line-apps.com/talk/m/download.nhn?oid="+msgid, nil)
  785. req.Header.Set("User-Agent", p.UserAgent)
  786. req.Header.Set("X-Line-Application", p.AppName)
  787. req.Header.Set("X-Line-Access", p.AuthToken)
  788. res, _ := client.Do(req)
  789. defer res.Body.Close()
  790. file, err := os.Create("download/" + msgid + "-dl." + tipe)
  791. if err != nil {
  792. return "", err
  793. }
  794. io.Copy(file, res.Body)
  795. file.Close()
  796. return file.Name(), nil
  797. }
  798. func (self *Account) FindAndAddContactsByMidnew2(mid string) (r map[string]*talkservice.Contact, err error) {
  799. if self.MID == mid || self.Limitadd {
  800. return map[string]*talkservice.Contact{}, nil
  801. } else if self.Frez {
  802. return map[string]*talkservice.Contact{}, nil
  803. }
  804. var TS *talkservice.TalkServiceClient
  805. TS = self.Talk()
  806. res, err := TS.FindAndAddContactsByMid(self.Ctx, self.Seq, mid, 0, "")
  807. if err != nil {
  808. e := GetCode(err)
  809. if e == 35 {
  810. if !InArrayCl(Waitadd, self) {
  811. Waitadd = append(Waitadd, self)
  812. self.Timeadd = time.Now()
  813. }
  814. self.Limitadd = true
  815. if _, ok := BlockAdd.Get(self.MID); !ok {
  816. BlockAdd.Set(self.MID, time.Now())
  817. }
  818. }
  819. }
  820. return res, err
  821. }
  822. func (self *Account) FindAndAddContactsByMidnew(mid string) (r map[string]*talkservice.Contact, err error) {
  823. if self.MID == mid || self.Limitadd {
  824. return map[string]*talkservice.Contact{}, nil
  825. } else if self.Frez {
  826. return map[string]*talkservice.Contact{}, nil
  827. }
  828. var TS *talkservice.TalkServiceClient
  829. AddCount(self, "add")
  830. TS = self.Talk()
  831. res, err := TS.FindAndAddContactsByMid(self.Ctx, self.Seq, mid, 0, "")
  832. if err != nil {
  833. e := GetCode(err)
  834. if e == 35 {
  835. if !InArrayCl(Waitadd, self) {
  836. Waitadd = append(Waitadd, self)
  837. self.Timeadd = time.Now()
  838. }
  839. self.Limitadd = true
  840. if _, ok := BlockAdd.Get(self.MID); !ok {
  841. BlockAdd.Set(self.MID, time.Now())
  842. }
  843. }
  844. }
  845. return res, err
  846. }
  847. func AddCount(user *Account, t string) {
  848. if t == "kick" {
  849. user.KickCount += 1
  850. user.TempKick += 1
  851. user.KickPoint += 1
  852. user.CountDay += 1
  853. user.Lastkick = time.Now()
  854. if user.TempKick >= 40 || user.CountDay >= 150 {
  855. if !InArrayCl(KickBans, user) {
  856. KickBans = append(KickBans, user)
  857. user.TimeBan = time.Now()
  858. }
  859. user.Limited = true
  860. }
  861. } else if t == "c" {
  862. user.CancelCount += 1
  863. user.Lastcancel = time.Now()
  864. } else if t == "add" {
  865. user.Add += 1
  866. user.Lastadd = time.Now()
  867. if user.Add >= 10 {
  868. if !InArrayCl(Waitadd, user) {
  869. Waitadd = append(Waitadd, user)
  870. user.Timeadd = time.Now()
  871. }
  872. user.Limitadd = true
  873. }
  874. } else {
  875. user.InvCount += 1
  876. user.TempInv += 1
  877. user.KickPoint += 1
  878. user.Lastinvite = time.Now()
  879. if user.TempInv >= 40 {
  880. if !InArrayCl(KickBans, user) {
  881. KickBans = append(KickBans, user)
  882. user.TimeBan = time.Now()
  883. }
  884. user.Limited = true
  885. }
  886. }
  887. if Random {
  888. Random = false
  889. } else {
  890. Random = true
  891. }
  892. }
  893. func (s *Account) UpdateProfilePictureVideo(pict, vid string) error {
  894. fl, err := os.Open(vid)
  895. if err != nil {
  896. return err
  897. }
  898. defer fl.Close()
  899. of, err := fl.Stat()
  900. if err != nil {
  901. return err
  902. }
  903. var size int64 = of.Size()
  904. bytess := make([]byte, size)
  905. buffer := bufio.NewReader(fl)
  906. _, err = buffer.Read(bytess)
  907. if err != nil {
  908. return err
  909. }
  910. dataa := fmt.Sprintf(`{"name": "%s", "oid": "%s", "ver": "2.0", "type": "video", "cat": "vp.mp4"}`, filepath.Base(vid), s.MID)
  911. sDec := b64.StdEncoding.EncodeToString([]byte(dataa))
  912. cl := s.hc
  913. req, _ := http.NewRequest("POST", "https://obs-sg.line-apps.com/talk/vp/upload.nhn", bytes.NewBuffer(bytess))
  914. for k, v := range map[string]string{
  915. "User-Agent": s.UserAgent,
  916. "X-Line-Application": s.AppName,
  917. "X-Line-Access": s.AuthToken,
  918. "x-lal": s.Locale,
  919. "x-lpv": "1",
  920. } {
  921. req.Header.Set(k, v)
  922. }
  923. req.Header.Set("x-obs-params", string(sDec))
  924. req.ContentLength = int64(len(bytess))
  925. res, err := cl.Do(req)
  926. if err != nil {
  927. return err
  928. }
  929. defer res.Body.Close()
  930. return s.UpdateProfilePicture(pict, "vp")
  931. }
  932. func (s *Account) UnsendChat(toId string) (err error) {
  933. client := s.Talk()
  934. Nganu, _ := client.GetRecentMessagesV2(s.Ctx, toId, int32(100000000))
  935. Mid := []string{}
  936. for _, chat := range Nganu {
  937. if chat.From_ == s.MID {
  938. Mid = append(Mid, chat.ID)
  939. }
  940. }
  941. for i := 0; i < len(Mid); i++ {
  942. err = client.UnsendMessage(s.Ctx, int32(0), Mid[i])
  943. }
  944. return err
  945. }
  946. func (cl *Account) TimeLineGet(url string) (string, error) {
  947. req, err := http.NewRequest("GET", url, nil)
  948. if err != nil {
  949. return "", err
  950. }
  951. cl.DefaultTimelineHeader(req)
  952. client := cl.hc
  953. resp, err := client.Do(req)
  954. if err != nil {
  955. return "", err
  956. }
  957. defer resp.Body.Close()
  958. cvt, _ := ioutil.ReadAll(resp.Body)
  959. return string(cvt), err
  960. }
  961. func (cl *Account) GetProfileDetail(mid string) string {
  962. url := AddParam("https://"+cl.Host+".line.naver.jp/mh/api/v45/post/list.json?", map[string]string{
  963. "userMid": mid,
  964. })
  965. tr, _ := cl.TimeLineGet(url)
  966. return tr
  967. }
  968. func AddParam(urls string, param map[string]string) string {
  969. p := url.Values{}
  970. for k, v := range param {
  971. p.Add(k, v)
  972. }
  973. return urls + p.Encode()
  974. }
  975. func (s *Account) DownloadFileURL(url string) (string, error) {
  976. req, _ := http.NewRequest("GET", url, nil)
  977. y := s.hc
  978. res, err := y.Do(req)
  979. if err != nil {
  980. fmt.Println(err)
  981. return "", err
  982. }
  983. defer res.Body.Close()
  984. var tp string
  985. if strings.Contains(res.Header.Get("Content-Type"), "image") {
  986. tp = "jpg"
  987. } else if strings.Contains(res.Header.Get("Content-Type"), "video") {
  988. tp = "mp4"
  989. } else if strings.Contains(res.Header.Get("Content-Type"), "audio") {
  990. tp = "mp3"
  991. } else {
  992. tp = "bin"
  993. }
  994. tmpfile, err := ioutil.TempFile("/tmp", "DL-*."+tp)
  995. if err != nil {
  996. fmt.Println(err)
  997. return "", err
  998. }
  999. defer tmpfile.Close()
  1000. if _, err := io.Copy(tmpfile, res.Body); err != nil {
  1001. fmt.Println(err)
  1002. return "", err
  1003. }
  1004. return tmpfile.Name(), nil
  1005. }
  1006. func (s *Account) ChangeProfileVideo(to string, msgid string) {
  1007. prof, _ := s.GetProfile()
  1008. path_p, _ := s.DownloadFileURL("https://obs.line-scdn.net/" + prof.PictureStatus)
  1009. if _, err := os.Stat(path_p); os.IsNotExist(err) {
  1010. s.SendMessage(to, "Update profile error.")
  1011. return
  1012. }
  1013. path, _ := s.DownloadObjectMsg(msgid, "bin")
  1014. if _, err := os.Stat(path); os.IsNotExist(err) {
  1015. s.SendMessage(to, "Update profile error.")
  1016. return
  1017. }
  1018. _ = s.UpdateProfilePictureVideo(path_p, path)
  1019. s.SendMessage(to, "Success update profile video.")
  1020. }
  1021. func (s *Account) UpdateProfileCoverById(objId string, coverVideo bool) error {
  1022. chtoken, _ := s.ApproveChannelAndIssueChannelToken("1341209850")
  1023. header := make(http.Header)
  1024. for k, v := range map[string]string{
  1025. "Content-Type": "application/json; charset=UTF-8",
  1026. "User-Agent": s.UserAgent,
  1027. "X-Line-Mid": s.MID,
  1028. "X-Line-Access": s.AuthToken,
  1029. "X-Line-Application": s.AppName,
  1030. "X-Line-ChannelToken": chtoken.ChannelAccessToken,
  1031. "x-lal": s.Locale,
  1032. "x-lpv": "1",
  1033. "x-lsr": "JP",
  1034. "x-line-bdbtemplateversion": "v1",
  1035. "x-line-global-config": "discover.enable=true; follow.enable=true",
  1036. } {
  1037. header.Set(k, v)
  1038. }
  1039. data := map[string]string{
  1040. "homeId": s.MID,
  1041. "coverObjectId": objId,
  1042. "storyShare": "false",
  1043. }
  1044. if coverVideo == true {
  1045. data["videoCoverObjectId"] = objId
  1046. }
  1047. _, err := req.Post("https://"+s.Host+".line.naver.jp/hm/api/v1/home/cover.json", header, req.BodyJSON(data))
  1048. return err
  1049. }
  1050. func genObsParam(dict map[string]string) string {
  1051. marshal, _ := json.Marshal(dict)
  1052. return b64.StdEncoding.EncodeToString(marshal)
  1053. }
  1054. func (s *Account) UploadObjHome(path, tipe, objId string) (string, error) {
  1055. chtoken, _ := s.ApproveChannelAndIssueChannelToken("1341209850")
  1056. header := make(http.Header)
  1057. for k, v := range map[string]string{
  1058. "Content-Type": "application/json; charset=UTF-8",
  1059. "User-Agent": s.UserAgent,
  1060. "X-Line-Mid": s.MID,
  1061. "X-Line-Access": s.AuthToken,
  1062. "X-Line-Application": s.AppName,
  1063. "X-Line-ChannelToken": chtoken.ChannelAccessToken,
  1064. "x-lal": s.Locale,
  1065. "x-lpv": "1",
  1066. "x-lsr": "JP",
  1067. "x-line-bdbtemplateversion": "v1",
  1068. "x-line-global-config": "discover.enable=true; follow.enable=true",
  1069. } {
  1070. header.Set(k, v)
  1071. }
  1072. var ctype string
  1073. var endpoint string
  1074. if tipe == "image" {
  1075. ctype = "image/jpeg"
  1076. endpoint = "/r/myhome/c/"
  1077. } else {
  1078. ctype = "video/mp4"
  1079. endpoint = "/r/myhome/vc/"
  1080. }
  1081. if objId == "objid" {
  1082. hstr := fmt.Sprintf("Line_%d", time.Now().Unix())
  1083. objId = fmt.Sprintf("%x", md5.Sum([]byte(hstr)))
  1084. }
  1085. file, _ := os.Open(path)
  1086. fi, err := file.Stat()
  1087. if err != nil {
  1088. return "", err
  1089. }
  1090. for k, v := range map[string]string{
  1091. "x-obs-params": genObsParam(map[string]string{
  1092. "name": fmt.Sprintf("%d", time.Now().Unix()),
  1093. "userid": s.MID,
  1094. "oid": objId,
  1095. "type": tipe,
  1096. "ver": "1.0",
  1097. }),
  1098. "Content-Type": ctype,
  1099. "Content-Length": fmt.Sprintf("%d", fi.Size()),
  1100. } {
  1101. header.Set(k, v)
  1102. }
  1103. _, err = req.Post("https://obs-sg.line-apps.com"+endpoint+objId, file, header)
  1104. if err != nil {
  1105. return "", err
  1106. }
  1107. return objId, nil
  1108. }
  1109. func (s *Account) ChangeCoverPicture(to string, msgid string) {
  1110. path, _ := s.DownloadObjectMsg(msgid, "bin")
  1111. if _, err := os.Stat(path); os.IsNotExist(err) {
  1112. s.SendMessage(to, "Update cover error.")
  1113. return
  1114. }
  1115. oid, err := s.UploadObjHome(path, "image", "objid")
  1116. if err != nil {
  1117. fmt.Println(err)
  1118. return
  1119. }
  1120. _ = s.UpdateProfileCoverById(oid, false)
  1121. s.SendMessage(to, "Success update cover.")
  1122. }
  1123. func GetMD5Hash(text string) string {
  1124. hash := md5.Sum([]byte(text))
  1125. return hex.EncodeToString(hash[:])
  1126. }
  1127. func (cl *Account) DefaultLineHeader(req *http.Request) {
  1128. req.Header.Set("User-Agent", cl.UserAgent)
  1129. req.Header.Set("X-Line-Application", cl.AppName)
  1130. req.Header.Set("X-Line-Access", cl.AuthToken)
  1131. req.Header.Set("X-Line-Carrier", "51010")
  1132. req.Header.Set("x-lal", cl.Locale)
  1133. }
  1134. func RandomString(n int) string {
  1135. rand.Seed(time.Now().UTC().UnixNano())
  1136. st := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  1137. b := make([]byte, n)
  1138. for i := range b {
  1139. b[i] = st[rand.Intn(len(st))]
  1140. }
  1141. return string(b)
  1142. }
  1143. func hed(r *http.Request, heder map[string]string) {
  1144. for k, v := range heder {
  1145. r.Header.Set(k, v)
  1146. }
  1147. }
  1148. func (cl *Account) ApproveChannelAndIssueChannelToken(chanid string) (*channel.ChannelToken, error) {
  1149. return cl.LoadChannel().ApproveChannelAndIssueChannelToken(cl.Ctx, chanid)
  1150. }
  1151. func (cl *Account) DefaultTimelineHeader(req *http.Request) {
  1152. chtoken, _ := cl.ApproveChannelAndIssueChannelToken("1341209850")
  1153. mp := map[string]string{
  1154. `Content-Type`: `application/json`,
  1155. `User-Agent`: cl.UserAgent,
  1156. `X-Line-Mid`: cl.MID,
  1157. `X-Line-Carrier`: "51010",
  1158. `X-Line-Application`: cl.AppName,
  1159. `X-Line-ChannelToken`: chtoken.ChannelAccessToken,
  1160. }
  1161. hed(req, mp)
  1162. }
  1163. func (cl *Account) UpdateCoverById(objId, tipe string) error {
  1164. defer PanicOnly()
  1165. var js []byte
  1166. if tipe == "p" {
  1167. js, _ = json.Marshal(map[string]interface{}{
  1168. "homeId": cl.MID,
  1169. "coverObjectId": objId,
  1170. "storyShare": false,
  1171. "meta": map[string]string{},
  1172. })
  1173. } else if tipe == "v" {
  1174. js, _ = json.Marshal(map[string]interface{}{
  1175. "homeId": cl.MID,
  1176. "coverObjectId": objId,
  1177. "storyShare": false,
  1178. "meta": map[string]string{},
  1179. "videoCoverObjectId": CoverVideo,
  1180. })
  1181. //dataa = fmt.Sprintf(`{"homeId": %s, "coverObjectId": %s, "storyShare": "false", "meta":{}, :"%s", "videoCoverObjectId":%s%}`,cl.Mid,objId,objId)
  1182. } else {
  1183. js, _ = json.Marshal(map[string]interface{}{
  1184. "homeId": tipe,
  1185. "coverObjectId": objId,
  1186. "storyShare": false,
  1187. "meta": map[string]string{},
  1188. })
  1189. req, err := http.NewRequest("POST", "https://"+cl.Host+".line.naver.jp/hm/api/v1/home/groupprofile/defaultimages.json", bytes.NewBuffer(js))
  1190. if err != nil {
  1191. return err
  1192. }
  1193. client := cl.hc
  1194. cl.DefaultTimelineHeader(req)
  1195. for {
  1196. res, err := client.Do(req)
  1197. if err != nil {
  1198. ef := err.Error()
  1199. if strings.Contains(ef, "EOF") {
  1200. continue
  1201. } else {
  1202. return err
  1203. }
  1204. } else {
  1205. defer res.Body.Close()
  1206. return nil
  1207. }
  1208. }
  1209. return nil
  1210. }
  1211. req, err := http.NewRequest("POST", "https://"+cl.Host+".line.naver.jp/hm/api/v1/home/cover.json", bytes.NewBuffer(js))
  1212. if err != nil {
  1213. return err
  1214. }
  1215. cl.DefaultTimelineHeader(req)
  1216. resp, err := cl.hc.Do(req)
  1217. if err != nil {
  1218. return err
  1219. }
  1220. defer resp.Body.Close()
  1221. return nil
  1222. }
  1223. func SetHeader(z *http.Request) {
  1224. z.Header.Set("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36")
  1225. z.Header.Set("authority", "scrapeme.live")
  1226. z.Header.Set("upgrade-insecure-requests", "1")
  1227. z.Header.Set("dnt", "1")
  1228. z.Header.Set("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
  1229. z.Header.Set("sec-fetch-mode", "navigate")
  1230. z.Header.Set("sec-fetch-user", "?1")
  1231. z.Header.Set("sec-fetch-dest", "document")
  1232. z.Header.Set("accept-language", "en-GB,en-US;q=0.9,en;q=0.8")
  1233. }
  1234. func (p *Account) Downloads(url string, tp string) (string, error) {
  1235. req, _ := http.NewRequest("GET", url, nil)
  1236. SetHeader(req)
  1237. y := p.hc
  1238. res, err := y.Do(req)
  1239. if err != nil {
  1240. return "", err
  1241. }
  1242. defer res.Body.Close()
  1243. if strings.Contains(res.Header.Get("Content-Type"), "image") {
  1244. tp = "jpg"
  1245. } else if strings.Contains(res.Header.Get("Content-Type"), "video") {
  1246. tp = "mp4"
  1247. } else if strings.Contains(res.Header.Get("Content-Type"), "audio") {
  1248. tp = "mp3"
  1249. }
  1250. tmpfile, err := ioutil.TempFile("download", "DL-*."+tp)
  1251. if err != nil {
  1252. return "", err
  1253. }
  1254. defer tmpfile.Close()
  1255. if _, err := io.Copy(tmpfile, res.Body); err != nil {
  1256. return "", err
  1257. }
  1258. return tmpfile.Name(), nil
  1259. }
  1260. func (y *Account) UpdateCover(path string) error {
  1261. objId := RandomString(32)
  1262. fl, err := os.Open(path)
  1263. if err != nil {
  1264. return err
  1265. }
  1266. defer fl.Close()
  1267. of, err := fl.Stat()
  1268. if err != nil {
  1269. return err
  1270. }
  1271. var size int64 = of.Size()
  1272. bytess := make([]byte, size)
  1273. buffer := bufio.NewReader(fl)
  1274. _, err = buffer.Read(bytess)
  1275. if err != nil {
  1276. return err
  1277. }
  1278. nama := filepath.Base(path)
  1279. dataa := fmt.Sprintf(`
  1280. {
  1281. "name": "%s",
  1282. "oid": "%s",
  1283. "type": "image",
  1284. "userid": "%s",
  1285. "ver": "2.0"
  1286. }`, nama, objId, y.MID)
  1287. sDec := b64.StdEncoding.EncodeToString([]byte(dataa))
  1288. client := y.hc
  1289. req, _ := http.NewRequest("POST", "https://obs-sg.line-apps.com/r/myhome/c/"+objId, bytes.NewBuffer(bytess))
  1290. y.DefaultTimelineHeader(req)
  1291. req.Header.Set("x-obs-params", string(sDec))
  1292. req.Header.Set("X-Line-PostShare", "false")
  1293. req.Header.Set("X-Line-StoryShare", "false")
  1294. req.Header.Set("x-line-signup-region", "ID")
  1295. req.Header.Set("content-type", "image/png")
  1296. req.ContentLength = int64(len(bytess))
  1297. res, err := client.Do(req)
  1298. if err != nil {
  1299. return err
  1300. }
  1301. defer res.Body.Close()
  1302. return y.UpdateCoverById(objId, "p")
  1303. }
  1304. func (y *Account) UpdatePictureProfile(path, tipe string) error {
  1305. fl, err := os.Open(path)
  1306. if err != nil {
  1307. return err
  1308. }
  1309. defer fl.Close()
  1310. of, err := fl.Stat()
  1311. if err != nil {
  1312. return err
  1313. }
  1314. var size int64 = of.Size()
  1315. bytess := make([]byte, size)
  1316. buffer := bufio.NewReader(fl)
  1317. _, err = buffer.Read(bytess)
  1318. if err != nil {
  1319. return err
  1320. }
  1321. tim := fmt.Sprintf("%s%s", filepath.Base(path), time.Now().UnixNano()/1000)
  1322. nama := GetMD5Hash(tim)
  1323. dataa := fmt.Sprintf(`{"name": "%s", "quality": "100", "type": "image"`, nama)
  1324. if tipe == "v" {
  1325. dataa += `, "ver": "2.0", "cat": "vp.mp4"}`
  1326. } else {
  1327. dataa += `, "ver": "2.0"}`
  1328. }
  1329. sDec := b64.StdEncoding.EncodeToString([]byte(dataa))
  1330. client := y.hc
  1331. req, _ := http.NewRequest("POST", "https://obs.line-apps.com/r/talk/p/"+y.MID, bytes.NewBuffer(bytess))
  1332. y.DefaultLineHeader(req)
  1333. req.Header.Set("x-obs-params", string(sDec))
  1334. req.ContentLength = int64(len(bytess))
  1335. for {
  1336. res, err := client.Do(req)
  1337. if err != nil {
  1338. ef := err.Error()
  1339. if strings.Contains(ef, "EOF") {
  1340. continue
  1341. } else {
  1342. return err
  1343. }
  1344. } else {
  1345. defer res.Body.Close()
  1346. return nil
  1347. }
  1348. }
  1349. return nil
  1350. }
  1351. func (y *Account) UpdateCoverVideo(path string) error {
  1352. objId := RandomString(32)
  1353. fl, err := os.Open(path)
  1354. if err != nil {
  1355. return err
  1356. }
  1357. defer fl.Close()
  1358. of, err := fl.Stat()
  1359. if err != nil {
  1360. return err
  1361. }
  1362. var size int64 = of.Size()
  1363. bytess := make([]byte, size)
  1364. buffer := bufio.NewReader(fl)
  1365. _, err = buffer.Read(bytess)
  1366. if err != nil {
  1367. return err
  1368. }
  1369. nama := filepath.Base(path)
  1370. dataa := fmt.Sprintf(`
  1371. {
  1372. "name": "%s",
  1373. "oid": "%s",
  1374. "type": "video",
  1375. "userid": "%s",
  1376. "ver": "2.0"
  1377. }`, nama, objId, y.MID)
  1378. sDec := b64.StdEncoding.EncodeToString([]byte(dataa))
  1379. client := y.hc
  1380. req, _ := http.NewRequest("POST", "https://obs-sg.line-apps.com/r/myhome/vc/"+objId, bytes.NewBuffer(bytess))
  1381. y.DefaultTimelineHeader(req)
  1382. req.Header.Set("x-obs-params", string(sDec))
  1383. req.Header.Set("X-Line-PostShare", "false")
  1384. req.Header.Set("X-Line-StoryShare", "false")
  1385. req.Header.Set("x-line-signup-region", "ID")
  1386. req.Header.Set("content-type", "video/mp4")
  1387. req.ContentLength = int64(len(bytess))
  1388. res, err := client.Do(req)
  1389. if err != nil {
  1390. return err
  1391. }
  1392. defer res.Body.Close()
  1393. CoverVideo = objId
  1394. return nil
  1395. }
  1396. func (y *Account) UpdateCoverWithVideo(path string) error {
  1397. objId := RandomString(32)
  1398. fl, err := os.Open(path)
  1399. if err != nil {
  1400. return err
  1401. }
  1402. defer fl.Close()
  1403. of, err := fl.Stat()
  1404. if err != nil {
  1405. return err
  1406. }
  1407. var size int64 = of.Size()
  1408. bytess := make([]byte, size)
  1409. buffer := bufio.NewReader(fl)
  1410. _, err = buffer.Read(bytess)
  1411. if err != nil {
  1412. return err
  1413. }
  1414. nama := filepath.Base(path)
  1415. dataa := fmt.Sprintf(`
  1416. {
  1417. "name": "%s",
  1418. "oid": "%s",
  1419. "type": "image",
  1420. "userid": "%s",
  1421. "ver": "2.0"
  1422. }`, nama, objId, y.MID)
  1423. sDec := b64.StdEncoding.EncodeToString([]byte(dataa))
  1424. client := y.hc
  1425. req, _ := http.NewRequest("POST", "https://obs-sg.line-apps.com/r/myhome/c/"+objId, bytes.NewBuffer(bytess))
  1426. y.DefaultTimelineHeader(req)
  1427. req.Header.Set("x-obs-params", string(sDec))
  1428. req.Header.Set("X-Line-PostShare", "false")
  1429. req.Header.Set("X-Line-StoryShare", "false")
  1430. req.Header.Set("x-line-signup-region", "ID")
  1431. req.Header.Set("content-type", "image/png")
  1432. req.ContentLength = int64(len(bytess))
  1433. res, err := client.Do(req)
  1434. if err != nil {
  1435. return err
  1436. }
  1437. defer res.Body.Close()
  1438. return y.UpdateCoverById(objId, "v")
  1439. }
  1440. func (y *Account) UpdateVideoProfile(vid string) error {
  1441. fl, err := os.Open(vid)
  1442. if err != nil {
  1443. return err
  1444. }
  1445. defer fl.Close()
  1446. of, err := fl.Stat()
  1447. if err != nil {
  1448. return err
  1449. }
  1450. var size int64 = of.Size()
  1451. bytess := make([]byte, size)
  1452. buffer := bufio.NewReader(fl)
  1453. _, err = buffer.Read(bytess)
  1454. if err != nil {
  1455. return err
  1456. }
  1457. tim := fmt.Sprintf("%s%s", filepath.Base(vid), time.Now().UnixNano()/1000)
  1458. nama := GetMD5Hash(tim)
  1459. dataa := fmt.Sprintf(`{"name": "%s", "ver": "2.0", "type": "video", "cat": "vp.mp4"}`, nama)
  1460. sDec := b64.StdEncoding.EncodeToString([]byte(dataa))
  1461. client := y.hc
  1462. req, _ := http.NewRequest("POST", "https://obs.line-apps.com/r/talk/vp/"+y.MID, bytes.NewBuffer(bytess))
  1463. y.DefaultLineHeader(req)
  1464. req.Header.Set("x-obs-params", string(sDec))
  1465. req.ContentLength = int64(len(bytess))
  1466. res, err := client.Do(req)
  1467. if err != nil {
  1468. return err
  1469. }
  1470. defer res.Body.Close()
  1471. return nil
  1472. }
  1473. func Clearcache() {
  1474. fmt.Println("CACHE_CLEARED")
  1475. exec.Command("sync;", "echo", "1", ">", "/proc/sys/vm/drop_caches").Run()
  1476. exec.Command("sync;", "echo", "2", ">", "/proc/sys/vm/drop_caches").Run()
  1477. exec.Command("sync;", "echo", "3", ">", "/proc/sys/vm/drop_caches").Run()
  1478. }
  1479. func setHC() *http.Client {
  1480. return &http.Client{
  1481. Transport: &http.Transport{},
  1482. }
  1483. }
  1484. func removeEndNewLine(input string) string {
  1485. defer PanicOnly()
  1486. if len(input) == 0 {
  1487. return input
  1488. }
  1489. if input[len(input)-1:] == "\n" {
  1490. return input[:len(input)-1]
  1491. }
  1492. return input
  1493. }
  1494. func (s *Account) SendMessage(to string, text string) {
  1495. s.Sendnewmsg(to, removeEndNewLine(text))
  1496. }
  1497. func deBug(where string, err error) bool {
  1498. if err != nil {
  1499. fmt.Printf("\033[33m#%s\nReason:\n%s\n\n\033[39m", where, err)
  1500. return false
  1501. }
  1502. return true
  1503. }
  1504. func (self *Account) ReissueChatTickets(groupId string) (tiket string, err error) {
  1505. defer PanicOnly()
  1506. req := &talkservice.ReissueChatTicketRequest{
  1507. GroupMid: groupId,
  1508. ReqSeq: self.Seq,
  1509. }
  1510. self.Seq++
  1511. res, err := self.Talk().ReissueChatTicket(self.Ctx, req)
  1512. if err != nil {
  1513. return "", err
  1514. }
  1515. return res.TicketId, err
  1516. }
  1517. func (self *Account) GetGroupMember(groupId string) (string, map[string]int64) {
  1518. defer PanicOnly()
  1519. res, err := self.Talk().GetChats(context.TODO(), &talkservice.GetChatsRequest{
  1520. ChatMids: []string{groupId},
  1521. WithInvitees: false,
  1522. WithMembers: true,
  1523. })
  1524. if err != nil {
  1525. CheckErr(self, err, groupId, "GetGroupMember")
  1526. return "", map[string]int64{}
  1527. }
  1528. if len(res.Chats) != 0 {
  1529. ch := res.Chats[0]
  1530. mem := ch.Extra.GroupExtra.MemberMids
  1531. return ch.ChatName, mem
  1532. }
  1533. return "", map[string]int64{}
  1534. }
  1535. func (s *Account) GetChat(targets []string, opsiMembers bool, opsiPendings bool) (r *talkservice.GetChatsResponse) {
  1536. defer PanicOnly()
  1537. client := s.Talk()
  1538. fst := talkservice.NewGetChatsRequest()
  1539. fst.ChatMids = targets
  1540. fst.WithMembers = opsiMembers
  1541. fst.WithInvitees = opsiPendings
  1542. r, e := client.GetChats(s.Ctx, fst)
  1543. if e != nil {
  1544. CheckErr(s, e, "none", "GetChat")
  1545. }
  1546. return r
  1547. }
  1548. func (self *Account) GetChatListMem(groupId string) (mem []string) {
  1549. defer PanicOnly()
  1550. res, _ := self.Talk().GetChats(self.Ctx, &talkservice.GetChatsRequest{
  1551. ChatMids: []string{groupId},
  1552. WithInvitees: true,
  1553. WithMembers: true,
  1554. })
  1555. if len(res.Chats) != 0 {
  1556. ch := res.Chats[0]
  1557. for a, _ := range ch.Extra.GroupExtra.MemberMids {
  1558. mem = append(mem, a)
  1559. }
  1560. return mem
  1561. }
  1562. return []string{}
  1563. }
  1564. func (self *Account) GetChatListinv(groupId string) (inv []string) {
  1565. defer PanicOnly()
  1566. res, _ := self.Talk().GetChats(self.Ctx, &talkservice.GetChatsRequest{
  1567. ChatMids: []string{groupId},
  1568. WithInvitees: true,
  1569. WithMembers: true,
  1570. })
  1571. if len(res.Chats) != 0 {
  1572. ch := res.Chats[0]
  1573. for a, _ := range ch.Extra.GroupExtra.InviteeMids {
  1574. inv = append(inv, a)
  1575. }
  1576. return inv
  1577. }
  1578. return []string{}
  1579. }
  1580. func IsPending(client *Account, to string, mid string) bool {
  1581. defer PanicOnly()
  1582. pend := client.GetChatListinv(to)
  1583. if len(pend) != 0 {
  1584. for i := range pend {
  1585. if pend[i] == mid {
  1586. return true
  1587. break
  1588. }
  1589. }
  1590. }
  1591. return false
  1592. }
  1593. func IsMembers(client *Account, to string, mid string) bool {
  1594. defer PanicOnly()
  1595. memlist := client.GetChatListMem(to)
  1596. for i := range memlist {
  1597. if memlist[i] == mid {
  1598. return true
  1599. break
  1600. }
  1601. }
  1602. return false
  1603. }
  1604. func (self *Account) FindAndAddContactsByMid4(mid string) (r map[string]*talkservice.Contact, err error) {
  1605. if self.MID == mid || self.Limitadd {
  1606. return map[string]*talkservice.Contact{}, nil
  1607. } else if self.Frez {
  1608. return map[string]*talkservice.Contact{}, nil
  1609. }
  1610. var TS *talkservice.TalkServiceClient
  1611. TS = self.Talk()
  1612. self.Add += 1
  1613. self.Lastadd = time.Now()
  1614. if self.Add >= 10 {
  1615. if !InArrayCl(Waitadd, self) {
  1616. Waitadd = append(Waitadd, self)
  1617. self.Timeadd = time.Now()
  1618. BlockAdd.Set(self.MID, time.Now())
  1619. }
  1620. self.Limitadd = true
  1621. return map[string]*talkservice.Contact{}, errors.New("limit goblok")
  1622. }
  1623. res, err := TS.FindAndAddContactsByMid(context.TODO(), self.Seq, mid, talkservice.ContactType_MID, `{"screen":"friendAdd:recommend","spec":"native"}`)
  1624. if err != nil {
  1625. e := GetCode(err)
  1626. fmt.Println(err)
  1627. if e == 35 {
  1628. if _, ok := GetBlockAdd.Get(self.MID); !ok {
  1629. GetBlockAdd.Set(self.MID, time.Now())
  1630. }
  1631. self.Limitadd = true
  1632. }
  1633. }
  1634. return res, err
  1635. }
  1636. func AddContact3(cl *Account, con string) int {
  1637. fl, _ := cl.GetAllContactIds()
  1638. if !InArray(fl, con) {
  1639. if con != cl.MID && !cl.Limitadd {
  1640. _, err := cl.FindAndAddContactsByMidnew(con)
  1641. if err != nil {
  1642. println(fmt.Sprintf("%v", err.Error()))
  1643. return 0
  1644. }
  1645. return 1
  1646. } else {
  1647. return 0
  1648. }
  1649. }
  1650. return 1
  1651. }
  1652. func SetRoutine(ms time.Duration) (context.Context, context.CancelFunc) {
  1653. ctx, deadline := context.WithDeadline(context.Background(), time.Now().Add(ms))
  1654. return ctx, deadline
  1655. }
  1656. func (s *Account) SendMention(toID string, msgText string, mids []string) {
  1657. defer PanicOnly()
  1658. client := s.Talk()
  1659. arr := []*tagdata{}
  1660. mentionee := "@lined"
  1661. texts := strings.Split(msgText, "@!")
  1662. textx := ""
  1663. for i := 0; i < len(mids); i++ {
  1664. textx += texts[i]
  1665. arr = append(arr, &tagdata{S: strconv.Itoa(len(textx)), E: strconv.Itoa(len(textx) + 6), M: mids[i]})
  1666. textx += mentionee
  1667. }
  1668. textx += texts[len(texts)-1]
  1669. allData, _ := json.MarshalIndent(arr, "", " ")
  1670. msg := talkservice.NewMessage()
  1671. msg.ContentType = 0
  1672. msg.To = toID
  1673. msg.Text = textx
  1674. msg.ContentMetadata = map[string]string{"MENTION": "{\"MENTIONEES\":" + string(allData) + "}"}
  1675. msg.RelatedMessageId = "0"
  1676. _, e := client.SendMessage(s.Ctx, s.Seq, msg)
  1677. deBug("SendMention", e)
  1678. }
  1679. func (self *Account) SendMention3(to string, text string, mids []string) (err error) {
  1680. defer PanicOnly()
  1681. if to != self.MID {
  1682. arr := []*tagdata{}
  1683. mentionee := "@Linebots2022"
  1684. texts := strings.Split(text, "%v")
  1685. if len(mids) == 0 || len(texts) < len(mids) {
  1686. return errors.New("Invalid mids.")
  1687. }
  1688. textx := ""
  1689. for i := 0; i < len(mids); i++ {
  1690. textx += texts[i]
  1691. uni := strconv.QuoteToASCII(string(textx))
  1692. asswdx := utf8.RuneCountInString(textx)
  1693. if strings.Contains(uni, "U0") {
  1694. asswdx += strings.Count(uni, "U0")
  1695. }
  1696. asqqq := asswdx + 13
  1697. slen := fmt.Sprintf("%v", asswdx)
  1698. elen := fmt.Sprintf("%v", asqqq)
  1699. arr = append(arr, &tagdata{S: slen, E: elen, M: mids[i]})
  1700. textx += mentionee
  1701. }
  1702. textx += texts[len(texts)-1]
  1703. arrData, _ := json.MarshalIndent(arr, "", " ")
  1704. metas := map[string]string{"MENTION": "{\"MENTIONEES\":" + string(arrData) + "}"}
  1705. M := &talkservice.Message{
  1706. From_: self.MID,
  1707. To: to,
  1708. ToType: 2,
  1709. Text: textx,
  1710. ContentType: 0,
  1711. ContentMetadata: metas,
  1712. RelatedMessageId: "0",
  1713. }
  1714. self.Seq++
  1715. ctx, cancel := SetRoutine(10 * time.Second)
  1716. defer cancel()
  1717. _, err = self.Talk().SendMessage(ctx, self.Seq, M)
  1718. }
  1719. return err
  1720. }
  1721. func (self *Account) SendMention4(to string, text string, mids []string) (err error) {
  1722. defer PanicOnly()
  1723. if to != self.MID {
  1724. arr := []*tagdata{}
  1725. mentionee := "@Linebots2022"
  1726. texts := strings.Split(text, "!@")
  1727. if len(mids) == 0 || len(texts) < len(mids) {
  1728. return errors.New("Invalid mids.")
  1729. }
  1730. textx := ""
  1731. for i := 0; i < len(mids); i++ {
  1732. textx += texts[i]
  1733. uni := strconv.QuoteToASCII(string(textx))
  1734. asswdx := utf8.RuneCountInString(textx)
  1735. if strings.Contains(uni, "U0") {
  1736. asswdx += strings.Count(uni, "U0")
  1737. }
  1738. asqqq := asswdx + 13
  1739. slen := fmt.Sprintf("%v", asswdx)
  1740. elen := fmt.Sprintf("%v", asqqq)
  1741. arr = append(arr, &tagdata{S: slen, E: elen, M: mids[i]})
  1742. textx += mentionee
  1743. }
  1744. textx += texts[len(texts)-1]
  1745. arrData, _ := json.MarshalIndent(arr, "", " ")
  1746. metas := map[string]string{"MENTION": "{\"MENTIONEES\":" + string(arrData) + "}"}
  1747. M := &talkservice.Message{
  1748. From_: self.MID,
  1749. To: to,
  1750. ToType: 2,
  1751. Text: textx,
  1752. ContentType: 0,
  1753. ContentMetadata: metas,
  1754. RelatedMessageId: "0",
  1755. }
  1756. self.Seq++
  1757. ctx, cancel := SetRoutine(10 * time.Second)
  1758. defer cancel()
  1759. _, err = self.Talk().SendMessage(ctx, self.Seq, M)
  1760. }
  1761. return err
  1762. }
  1763. func (self *Account) SendMention2(to string, text string, mids []string) (err error) {
  1764. defer PanicOnly()
  1765. if to != self.MID {
  1766. arr := []*tagdata{}
  1767. mentionee := "@LineD2022"
  1768. texts := strings.Split(text, "TAGHERE")
  1769. if len(mids) == 0 || len(texts) < len(mids) {
  1770. return errors.New("Invalid mids.")
  1771. }
  1772. textx := ""
  1773. for i := 0; i < len(mids); i++ {
  1774. textx += texts[i]
  1775. uni := strconv.QuoteToASCII(string(textx))
  1776. asswdx := utf8.RuneCountInString(textx)
  1777. if strings.Contains(uni, "U0") {
  1778. asswdx += strings.Count(uni, "U0")
  1779. }
  1780. asqqq := asswdx + 13
  1781. slen := fmt.Sprintf("%v", asswdx)
  1782. elen := fmt.Sprintf("%v", asqqq)
  1783. arr = append(arr, &tagdata{S: slen, E: elen, M: mids[i]})
  1784. textx += mentionee
  1785. }
  1786. textx += texts[len(texts)-1]
  1787. arrData, _ := json.MarshalIndent(arr, "", " ")
  1788. metas := map[string]string{"MENTION": "{\"MENTIONEES\":" + string(arrData) + "}"}
  1789. M := &talkservice.Message{
  1790. From_: self.MID,
  1791. To: to,
  1792. ToType: 2,
  1793. Text: textx,
  1794. ContentType: 0,
  1795. ContentMetadata: metas,
  1796. RelatedMessageId: "0",
  1797. }
  1798. self.Seq++
  1799. ctx, cancel := SetRoutine(10 * time.Second)
  1800. defer cancel()
  1801. _, err = self.Talk().SendMessage(ctx, self.Seq, M)
  1802. }
  1803. return err
  1804. }
  1805. func (self *Account) UnFriend(mid string) {
  1806. err := self.Talk().UpdateContactSetting(context.TODO(), self.Seq, mid, talkservice.ContactSetting_CONTACT_SETTING_DELETE, "True")
  1807. if err != nil {
  1808. CheckErr(self, err, "none", "UnFriend")
  1809. }
  1810. }
  1811. func (self *Account) AcceptTicket(groupMid string, ticketId string) (err error) {
  1812. if self.Limited == false {
  1813. _, err = self.Talk().AcceptChatInvitationByTicket(self.Ctx, &talkservice.AcceptChatInvitationByTicketRequest{
  1814. ChatMid: groupMid,
  1815. ReqSeq: self.Seq,
  1816. TicketId: ticketId,
  1817. })
  1818. if err != nil {
  1819. CheckErr(self, err, groupMid, "joinQr")
  1820. }
  1821. self.Seq++
  1822. }
  1823. return err
  1824. }
  1825. func (self *Account) CancelChatInvitations(groupId string, contactIds string) (err error) {
  1826. if self.Limited == false {
  1827. self.Talk().CancelChatInvitation(self.Ctx, &talkservice.CancelChatInvitationRequest{
  1828. ChatMid: groupId,
  1829. ReqSeq: self.Seq,
  1830. TargetUserMids: []string{contactIds},
  1831. })
  1832. AddCount(self, "c")
  1833. GetRoom(groupId).Fight = time.Now()
  1834. if err != nil {
  1835. CheckErr(self, err, groupId, "Cancel")
  1836. }
  1837. self.Seq++
  1838. }
  1839. return err
  1840. }
  1841. func (self *Account) InviteIntoGroupNormal(groupId string, contactIds []string) (err error) {
  1842. if self.Limited == false {
  1843. _, err = self.Talk().InviteIntoChat(self.Ctx, &talkservice.InviteIntoChatRequest{
  1844. ChatMid: groupId,
  1845. ReqSeq: self.Seq,
  1846. TargetUserMids: contactIds,
  1847. })
  1848. AddCount(self, "invite")
  1849. GetRoom(groupId).Fight = time.Now()
  1850. if err != nil {
  1851. CheckErr(self, err, groupId, "invite")
  1852. }
  1853. self.Seq++
  1854. }
  1855. return err
  1856. }
  1857. func (self *Account) NormalDeleteOtherFromChats(to string, contactIds string) (err error) {
  1858. _, err = self.Talk().DeleteOtherFromChat(self.Ctx, &talkservice.DeleteOtherFromChatRequest{
  1859. ReqSeq: 0,
  1860. ChatMid: to,
  1861. TargetUserMids: []string{contactIds},
  1862. })
  1863. if err != nil {
  1864. CheckErr(self, err, to, "checkban")
  1865. }
  1866. return err
  1867. }
  1868. func (self *Account) DeleteOtherFromChats(groupId string, contactIds string) (err error) {
  1869. if self.Limited == false {
  1870. _, err = self.Talk().DeleteOtherFromChat(self.Ctx, &talkservice.DeleteOtherFromChatRequest{
  1871. ChatMid: groupId,
  1872. ReqSeq: self.Seq,
  1873. TargetUserMids: []string{contactIds},
  1874. })
  1875. AddCount(self, "kick")
  1876. GetRoom(groupId).Fight = time.Now()
  1877. if err != nil {
  1878. CheckErr(self, err, groupId, "kick")
  1879. }
  1880. self.Seq++
  1881. }
  1882. return err
  1883. }
  1884. func (s *Account) GetGroupWithoutMembers(groupId string) (r *talkservice.Group) {
  1885. client := s.Talk()
  1886. r, _ = client.GetGroupWithoutMembers(s.Ctx, groupId)
  1887. return r
  1888. }
  1889. func (s *Account) UpdateGroup(groupOBJ *talkservice.Group) {
  1890. client := s.Talk()
  1891. e := client.UpdateGroup(s.Ctx, s.Seq, groupOBJ)
  1892. deBug("ReissueChatTicket", e)
  1893. }
  1894. func (self *Account) GetGroupMembers(groupId string) (error, string, map[string]int64) {
  1895. res, err := self.Talk().GetChats(self.Ctx, &talkservice.GetChatsRequest{
  1896. ChatMids: []string{groupId},
  1897. WithInvitees: false,
  1898. WithMembers: true,
  1899. })
  1900. if err != nil {
  1901. return err, "", map[string]int64{}
  1902. }
  1903. if len(res.Chats) != 0 {
  1904. ch := res.Chats[0]
  1905. mem := ch.Extra.GroupExtra.MemberMids
  1906. return err, ch.ChatName, mem
  1907. }
  1908. return err, "", map[string]int64{}
  1909. }
  1910. func (self *Account) GetChatList(groupId string) (name string, mem, inv []string) {
  1911. defer PanicOnly()
  1912. res, _ := self.Talk().GetChats(self.Ctx, &talkservice.GetChatsRequest{
  1913. ChatMids: []string{groupId},
  1914. WithInvitees: true,
  1915. WithMembers: true,
  1916. })
  1917. if len(res.Chats) != 0 {
  1918. ch := res.Chats[0]
  1919. for a, _ := range ch.Extra.GroupExtra.MemberMids {
  1920. mem = append(mem, a)
  1921. }
  1922. for a, _ := range ch.Extra.GroupExtra.InviteeMids {
  1923. inv = append(inv, a)
  1924. }
  1925. return ch.ChatName, mem, inv
  1926. }
  1927. return "", []string{}, []string{}
  1928. }
  1929. func (self *Account) GetGroups(groupId []string) (r []*talkservice.Chat, err error) {
  1930. defer PanicOnly()
  1931. tux := [][]string{}
  1932. if len(groupId) > 100 {
  1933. for {
  1934. if len(groupId) != 0 {
  1935. if len(groupId) < 99 {
  1936. tux = append(tux, groupId)
  1937. groupId = []string{}
  1938. } else {
  1939. tux = append(tux, groupId[:99])
  1940. groupId = groupId[99:]
  1941. }
  1942. } else {
  1943. break
  1944. }
  1945. }
  1946. } else {
  1947. tux = append(tux, groupId)
  1948. }
  1949. for _, lis := range tux {
  1950. res, _ := self.Talk().GetChats(context.TODO(), &talkservice.GetChatsRequest{
  1951. ChatMids: lis,
  1952. WithInvitees: true,
  1953. WithMembers: true,
  1954. })
  1955. r = append(r, res.Chats...)
  1956. }
  1957. return r, err
  1958. }
  1959. func (cl *Account) Sendnewmsg(to string, text string) (*talkservice.Message, error) {
  1960. defer PanicOnly()
  1961. M := &talkservice.Message{
  1962. To: to,
  1963. ContentType: 0,
  1964. Text: text,
  1965. RelatedMessageId: "0",
  1966. }
  1967. return cl.Talk().SendMessage(cl.Ctx, 0, M)
  1968. }
  1969. func (self *Account) GetGroupIdsJoined() ([]string, error) {
  1970. defer PanicOnly()
  1971. req := &talkservice.GetAllChatMidsRequest{
  1972. WithInvitedChats: false,
  1973. WithMemberChats: true,
  1974. }
  1975. res, err := self.Talk().GetAllChatMids(context.TODO(), req, talkservice.SyncReason_UNKNOWN)
  1976. return res.MemberChatMids, err
  1977. }
  1978. func (self *Account) UpdateProfileName(name string) (err error) {
  1979. if len(name) < 1 {
  1980. return err
  1981. }
  1982. var TS *talkservice.TalkServiceClient
  1983. TS = self.Talk()
  1984. self.Seq++
  1985. for {
  1986. err = TS.UpdateProfileAttribute(context.TODO(), self.Seq, 2, name)
  1987. if err == nil {
  1988. self.Namebot = name
  1989. return err
  1990. } else if strings.Contains(err.Error(), "EOF") {
  1991. continue
  1992. } else {
  1993. return err
  1994. }
  1995. }
  1996. return err
  1997. }
  1998. func (p *Account) GetE2EEPublicKeys() (r []*talkservice.E2EEPublicKey, err error) {
  1999. r, err = p.Talk().GetE2EEPublicKeys(p.Ctx)
  2000. return r, err
  2001. }
  2002. func (client *Account) RemoveLeterSelling() {
  2003. a, _ := client.GetE2EEPublicKeys()
  2004. for _, x := range a {
  2005. err := client.RemoveE2EEPublicKey(x)
  2006. if err != nil {
  2007. fmt.Println(err)
  2008. }
  2009. }
  2010. }
  2011. func (p *Account) RemoveE2EEPublicKey(a *talkservice.E2EEPublicKey) (err error) {
  2012. err = p.Talk().RemoveE2EEPublicKey(p.Ctx, a)
  2013. return err
  2014. }
  2015. func (self *Account) GetChatListMap(groupId string) (mem, inv map[string]int64) {
  2016. res, err := self.Talk().GetChats(context.TODO(), &talkservice.GetChatsRequest{
  2017. ChatMids: []string{groupId},
  2018. WithInvitees: true,
  2019. WithMembers: true,
  2020. })
  2021. if err != nil {
  2022. return mem, inv
  2023. }
  2024. if len(res.Chats) != 0 {
  2025. ch := res.Chats[0]
  2026. return ch.Extra.GroupExtra.MemberMids, ch.Extra.GroupExtra.InviteeMids
  2027. }
  2028. return map[string]int64{}, map[string]int64{}
  2029. }
  2030. func RemoveCl(items []*Account, item *Account) []*Account {
  2031. defer PanicOnly()
  2032. newitems := []*Account{}
  2033. for _, i := range items {
  2034. if i != item {
  2035. newitems = append(newitems, i)
  2036. }
  2037. }
  2038. return newitems
  2039. }
  2040. func Randint2(a []int) []int {
  2041. defer PanicOnly()
  2042. rand.Seed(time.Now().UnixNano())
  2043. rand.Shuffle(len(a), func(i, j int) { a[i], a[j] = a[j], a[i] })
  2044. return a
  2045. }
  2046. func GetNewTransport() *http.Transport {
  2047. certs, _ := tls.LoadX509KeyPair("rensmtcert.crt", "rensmtcert.key")
  2048. tr := &http.Transport{
  2049. TLSClientConfig: &tls.Config{
  2050. Certificates: []tls.Certificate{certs},
  2051. InsecureSkipVerify: true,
  2052. },
  2053. }
  2054. http2.ConfigureTransport(tr)
  2055. return tr
  2056. }
  2057. func (cl *Account) SettingUpHeader() {
  2058. cl.HttpHeader = map[string][]string{"Content-Type": {"application/x-thrift"}}
  2059. cl.HttpHeader.Add("user-agent", cl.UserAgent)
  2060. cl.HttpHeader.Add("x-line-application", cl.AppName)
  2061. cl.HttpHeader.Add("x-line-access", cl.AuthToken)
  2062. }
  2063. func (cl *Account) SetLocaleAccount() {
  2064. sets, err := cl.GetSettings()
  2065. if err == nil {
  2066. cl.Locale = sets.PreferenceLocale
  2067. cl.HttpHeader.Add("x-lal", cl.Locale)
  2068. } else {
  2069. cl.Locale = "in_ID"
  2070. cl.HttpHeader.Add("x-lal", "in_ID")
  2071. }
  2072. }
  2073. func CreateNewLogin(token string, num int, mids string, app string, ua string, host string) (*Account, error) {
  2074. Hosts4 := fmt.Sprintf("https://%s.line.naver.jp/S4", host)
  2075. SostP5 := fmt.Sprintf("https://%s.line.naver.jp/P5", host)
  2076. SotShnal := fmt.Sprintf("https://%s.line.naver.jp/CH4", host)
  2077. Urs4, _ := url.Parse(Hosts4)
  2078. Urp5, _ := url.Parse(SostP5)
  2079. Shna, _ := url.Parse(SotShnal)
  2080. s := new(Account)
  2081. s = &Account{
  2082. AuthToken: token,
  2083. AppName: app,
  2084. UserAgent: ua,
  2085. Host: host,
  2086. MID: mids,
  2087. Limited: false,
  2088. Frez: false,
  2089. Limitadd: false,
  2090. Waitadd: false,
  2091. Seq: 0,
  2092. Akick: 0,
  2093. KickPoint: 0,
  2094. Ainvite: 0,
  2095. Transport: GetNewTransport(),
  2096. Acancel: 0,
  2097. Namebot: "",
  2098. Numar: num,
  2099. hc: setHC(),
  2100. Shnall: Shna.String(),
  2101. UrS4: Urs4.String(),
  2102. UrP5: Urp5.String(),
  2103. Ckick: 0,
  2104. Cinvite: 0,
  2105. TimeBan: time.Now(),
  2106. Ccancel: 0,
  2107. SHani: 0,
  2108. Count: 50,
  2109. CustomPoint: 0,
  2110. GRevision: 0,
  2111. Cpoll: 0,
  2112. Ctx: context.Background(),
  2113. reqSeqMessage: 0,
  2114. IRevision: 0,
  2115. Squads: []string{},
  2116. Backup: []string{},
  2117. }
  2118. s.SettingUpHeader()
  2119. s.SetLocaleAccount()
  2120. s.Revision, _ = s.GetLastOpRevision()
  2121. prof, err := s.GetProfile()
  2122. if err == nil {
  2123. s.Namebot = prof.DisplayName
  2124. }
  2125. return s, err
  2126. }
  2127. func GetE2EE() (string, string, string) {
  2128. out, _ := exec.Command("python3", "enc.py", "1").Output()
  2129. //stdout, err := cmd.StdoutPipe()
  2130. s := strings.Split(string(out), "\n")
  2131. return s[0], s[1], s[2]
  2132. }
  2133. func GetIntBytes(n int) (valo []byte) {
  2134. var bits = 64
  2135. zigzag := ((n << 1) ^ (n >> (bits - 1)))
  2136. for {
  2137. if zigzag&-128 == 0 {
  2138. valo = append(valo, byte(zigzag))
  2139. break
  2140. } else {
  2141. valo = append(valo, byte((zigzag&0xff)|0x80))
  2142. zigzag >>= 7
  2143. }
  2144. }
  2145. return valo
  2146. }
  2147. func PanicOnly() {
  2148. if r := recover(); r != nil {
  2149. return
  2150. }
  2151. }
  2152. func Remove(s []string, r string) []string {
  2153. new := make([]string, len(s))
  2154. copy(new, s)
  2155. for i, v := range new {
  2156. if v == r {
  2157. return append(new[:i], new[i+1:]...)
  2158. }
  2159. }
  2160. return s
  2161. }
  2162. func IsFriends(client *Account, from string) bool {
  2163. defer PanicOnly()
  2164. friendsip, _ := client.GetAllContactIds()
  2165. for _, a := range friendsip {
  2166. if a == from {
  2167. return true
  2168. break
  2169. }
  2170. }
  2171. return false
  2172. }
  2173. func (self *Account) GetGroupIdsInvited() (r []string, err error) {
  2174. defer PanicOnly()
  2175. req := &talkservice.GetAllChatMidsRequest{
  2176. WithInvitedChats: true,
  2177. WithMemberChats: false,
  2178. }
  2179. rs, err := self.Talk().GetAllChatMids(context.TODO(), req, talkservice.SyncReason_UNKNOWN)
  2180. return rs.InvitedChatMids, err
  2181. }
  2182. func (cl *Account) SendContact(to string, mid string) error {
  2183. fOB := []byte{130, 33, 3, 11, 115, 101, 110, 100, 77, 101, 115, 115, 97, 103, 101, 21, 0, 28, 40, 33}
  2184. fOB = append(fOB, GetStringBytes(to)...)
  2185. fOB = append(fOB, []byte{213, 26, 59, 1, 136, 3, 109, 105, 100, 33}...)
  2186. fOB = append(fOB, GetStringBytes(mid)...)
  2187. fOB = append(fOB, []byte{0, 0}...)
  2188. HTTP, _ := thrift.NewTHttpClient(cl.UrS4, cl.Transport)
  2189. transport := HTTP.(*thrift.THttpClient)
  2190. transport.SetHeader("user-agent", cl.UserAgent)
  2191. transport.SetHeader("x-line-application", cl.AppName)
  2192. transport.SetHeader("x-line-access", cl.AuthToken)
  2193. transport.SetHeader("x-lal", cl.Locale)
  2194. transport.Write(fOB)
  2195. return transport.Flush(cl.Ctx)
  2196. }
  2197. func (cl *Account) UpdateChatQrV2(chatId string, typevar bool) error {
  2198. HTTP, _ := thrift.NewTHttpClient(cl.UrS4, cl.Transport)
  2199. transport := HTTP.(*thrift.THttpClient)
  2200. transport.SetHeader("User-Agent", cl.UserAgent)
  2201. transport.SetHeader("X-Line-Application", cl.AppName)
  2202. transport.SetHeader("X-Line-Access", cl.AuthToken)
  2203. transport.SetHeader("x-lal", cl.Locale)
  2204. var x string
  2205. if typevar {
  2206. x = "!"
  2207. }
  2208. transport.Write([]byte("\x82!\x00\nupdateChat\x1c\x15\x00\x1c(!" + chatId + "l\x1c" + x + "\x00\x00\x00\x15\x08\x00\x00"))
  2209. return transport.Flush(cl.Ctx)
  2210. }
  2211. func (cl *Account) SettingUpFetch() {
  2212. cl.SessionPoll = thrift.ModHttpClient(cl.UrP5, cl.Transport, cl.HttpHeader)
  2213. cl.SessionPoll.SetMoreCompact(true)
  2214. }
  2215. func (cl *Account) FetchOps(count int32) (res []*talkservice.Operation, err *modcompact.ExceptionMod) {
  2216. var fOB = []byte{130, 33, 1, 8, 102, 101, 116, 99, 104, 79, 112, 115, 38}
  2217. fOB = append(fOB, GetIntBytes(int(cl.Revision))...)
  2218. fOB = append(fOB, 21)
  2219. fOB = append(fOB, GetIntBytes(int(count))...)
  2220. fOB = append(fOB, 22)
  2221. fOB = append(fOB, GetIntBytes(int(cl.GRevision))...)
  2222. fOB = append(fOB, 22)
  2223. fOB = append(fOB, GetIntBytes(int(cl.IRevision))...)
  2224. fOB = append(fOB, 0)
  2225. cl.SettingUpFetch()
  2226. cl.SessionPoll.Write(fOB)
  2227. Times := time.Now().Unix()
  2228. b, errS := cl.SessionPoll.FlushMod(cl.Ctx)
  2229. if errS != nil {
  2230. cl.Transport = GetNewTransport()
  2231. cl.Curtime = Times
  2232. } else if len(b) > 0 {
  2233. tmcp := modcompact.TMoreCompactProtocolGoods(b)
  2234. res, err = tmcp.GETOPS()
  2235. }
  2236. if len(res) == 0 || (Times-cl.Curtime) > 300 {
  2237. cl.Transport = GetNewTransport()
  2238. cl.Curtime = Times
  2239. }
  2240. return res, err
  2241. }
  2242. func (cl *Account) Talk() *talkservice.TalkServiceClient {
  2243. compact := thrift.NewTCompactProtocol(thrift.ModHttpClient(cl.UrS4, cl.Transport, cl.HttpHeader))
  2244. return talkservice.NewTalkServiceClient(thrift.NewTStandardClient(compact, compact))
  2245. }
  2246. func (cl *Account) LoadChannel() *channel.ChannelServiceClient {
  2247. compact := thrift.NewTCompactProtocol(thrift.ModHttpClient(cl.Shnall, cl.Transport, cl.HttpHeader))
  2248. return channel.NewChannelServiceClient(thrift.NewTStandardClient(compact, compact))
  2249. }
  2250. func (cl *Account) UpdateChatName(chatId string, name string) error {
  2251. var fOB = []byte{130, 33, 1, 10, 117, 112, 100, 97, 116, 101, 67, 104, 97, 116, 28, 21, 0, 28, 21, 0, 24, 33}
  2252. fOB = append(fOB, []byte(chatId)...)
  2253. fOB = append(fOB, []byte{22, 0, 18, 22, 0, 24, byte(len(name))}...)
  2254. fOB = append(fOB, []byte(name)...)
  2255. fOB = append(fOB, []byte{24, 0, 0, 21, 2, 0, 0}...)
  2256. HTTP, _ := thrift.NewTHttpClient(cl.UrS4, cl.Transport)
  2257. transport := HTTP.(*thrift.THttpClient)
  2258. transport.SetHeader("User-Agent", cl.UserAgent)
  2259. transport.SetHeader("X-Line-Application", cl.AppName)
  2260. transport.SetHeader("X-Line-Access", cl.AuthToken)
  2261. transport.SetHeader("x-lal", cl.Locale)
  2262. transport.Write(fOB)
  2263. return transport.Flush(cl.Ctx)
  2264. }
  2265. func random() string {
  2266. rand.Seed(time.Now().UnixNano())
  2267. return strconv.Itoa(rand.Intn(30000) + 30000)
  2268. }
  2269. func MaxRevision(a, b int64) int64 {
  2270. if a > b {
  2271. return a
  2272. }
  2273. return b
  2274. }
  2275. func FetchRev(client *Account, op *talkservice.Operation) {
  2276. if op.Param2 != "" {
  2277. a := strings.Split(op.Param2, "\x1e")
  2278. res, err := strconv.ParseInt(a[0], 10, 64)
  2279. if err == nil {
  2280. client.GRevision = MaxRevision(client.GRevision, res)
  2281. } else {
  2282. println(op.Param2)
  2283. }
  2284. }
  2285. if op.Param1 != "" {
  2286. a := strings.Split(op.Param1, "\x1e")
  2287. res, err := strconv.ParseInt(a[0], 10, 64)
  2288. if err == nil {
  2289. client.IRevision = MaxRevision(client.IRevision, res)
  2290. } else {
  2291. println(op.Param2)
  2292. }
  2293. }
  2294. }
  2295. func (cl *Account) CorrectRevision(op *talkservice.Operation, local bool, global bool, individual bool) {
  2296. if global {
  2297. if op.Revision == -1 && op.Param2 != "" {
  2298. s := strings.Split(op.Param2, "\x1e")
  2299. cl.GRevision, _ = strconv.ParseInt(s[0], 10, 64)
  2300. }
  2301. }
  2302. if individual {
  2303. if op.Revision == -1 && op.Param1 != "" {
  2304. s := strings.Split(op.Param1, "\x1e")
  2305. cl.IRevision, _ = strconv.ParseInt(s[0], 10, 64)
  2306. }
  2307. }
  2308. if local {
  2309. if op.Revision > cl.Revision {
  2310. cl.Revision = op.Revision
  2311. }
  2312. }
  2313. }
  2314. func (cl *Account) GetLastOpRevision() (r int64, err error) {
  2315. return cl.Talk().GetLastOpRevision(cl.Ctx)
  2316. }
  2317. func (self *Account) UpdateProfileBio(bio string) (err error) {
  2318. if len(bio) < 1 {
  2319. return err
  2320. }
  2321. var TS *talkservice.TalkServiceClient
  2322. TS = self.Talk()
  2323. self.Seq++
  2324. for {
  2325. err = TS.UpdateProfileAttribute(context.TODO(), self.Seq, 16, bio)
  2326. if err == nil {
  2327. return err
  2328. } else if strings.Contains(err.Error(), "EOF") {
  2329. continue
  2330. } else {
  2331. return err
  2332. }
  2333. }
  2334. return err
  2335. }
  2336. func (cl *Account) GetContact(mid string) (*talkservice.Contact, error) {
  2337. return cl.Talk().GetContact(cl.Ctx, mid)
  2338. }
  2339. func (cl *Account) SendText(to string, text string) (*talkservice.Message, error) {
  2340. M := &talkservice.Message{
  2341. To: to,
  2342. ContentType: 0,
  2343. Text: text,
  2344. RelatedMessageId: "0",
  2345. }
  2346. return cl.Talk().SendMessage(context.TODO(), 0, M)
  2347. }
  2348. func GetStringBytes(str string) []byte {
  2349. var va []byte
  2350. for a := range str {
  2351. va = append(va, byte(int(str[a])))
  2352. }
  2353. return va
  2354. }
  2355. func (cl *Account) FindAndAddContactsByMid(mid string) error {
  2356. _, err := cl.Talk().FindAndAddContactsByMid(cl.Ctx, 0, mid, 0, "")
  2357. return err
  2358. }
  2359. func (self *Account) GetGroup3(groupId string) (r *talkservice.Chat, err error) {
  2360. res, err := self.Talk().GetChats(context.TODO(), &talkservice.GetChatsRequest{
  2361. ChatMids: []string{groupId},
  2362. WithInvitees: true,
  2363. WithMembers: true,
  2364. })
  2365. if err != nil {
  2366. CheckErr(self, err, groupId, "GetGroup3")
  2367. }
  2368. return res.Chats[0], err
  2369. }
  2370. func (self *Account) GetRecentMessagesV2(gid string) (r []*talkservice.Message, err error) {
  2371. ls, err := self.Talk().GetRecentMessagesV2(self.Ctx, gid, int32(100000000))
  2372. if err != nil {
  2373. CheckErr(self, err, gid, "GetRecentMessagesV2")
  2374. }
  2375. return ls, err
  2376. }
  2377. func (cl *Account) UpdateProfileAttribute(a talkservice.ProfileAttribute, v string) error {
  2378. return cl.Talk().UpdateProfileAttribute(cl.Ctx, 0, a, v)
  2379. }
  2380. func (cl *Account) UpdateProfileAttributes(a talkservice.ProfileAttribute, v string) error {
  2381. D := make(map[talkservice.ProfileAttribute]*talkservice.ProfileContent)
  2382. D[a] = &talkservice.ProfileContent{Value: v}
  2383. return cl.Talk().UpdateProfileAttributes(cl.Ctx, 0, &talkservice.UpdateProfileAttributesRequest{ProfileAttributes: D})
  2384. }
  2385. func (cl *Account) GetProfile() (*talkservice.Profile, error) {
  2386. return cl.Talk().GetProfile(cl.Ctx, 3)
  2387. }
  2388. func (cl *Account) GetAllContactIds() ([]string, error) {
  2389. return cl.Talk().GetAllContactIds(cl.Ctx, 1)
  2390. }
  2391. func (cl *Account) AcceptChatInvitationByTicket(to string, ticket string) error {
  2392. _, err = cl.Talk().AcceptChatInvitationByTicket(cl.Ctx, &talkservice.AcceptChatInvitationByTicketRequest{
  2393. ReqSeq: 0,
  2394. ChatMid: to,
  2395. TicketId: ticket,
  2396. })
  2397. return err
  2398. }
  2399. func (cl *Account) DeleteSelfFromChat(to string) error {
  2400. _, err = cl.Talk().DeleteSelfFromChat(cl.Ctx, &talkservice.DeleteSelfFromChatRequest{
  2401. ReqSeq: 0,
  2402. ChatMid: to,
  2403. })
  2404. return err
  2405. }
  2406. func (s *Account) FindChatByTicket(ticketId string) (r *talkservice.FindChatByTicketResponse) {
  2407. client := s.Talk()
  2408. v := talkservice.NewFindChatByTicketRequest()
  2409. v.TicketId = ticketId
  2410. r, e := client.FindChatByTicket(s.Ctx, v)
  2411. deBug("ReissueChatTicket", e)
  2412. return r
  2413. }
  2414. func (self *Account) GetSettings() (r *talkservice.Settings, err error) {
  2415. var TS *talkservice.TalkServiceClient
  2416. TS = self.Talk()
  2417. res, err := TS.GetSettings(self.Ctx, talkservice.SyncReason_UNKNOWN)
  2418. return res, err
  2419. }
  2420. func (cl *Account) InviteIntoChatPollVer(to string, mid []string) {
  2421. if len(mid) > 3 {
  2422. var b []string
  2423. for x, v := range mid {
  2424. x++
  2425. b = append(b, v)
  2426. if x%3 == 0 {
  2427. go cl.InviteIntoGroupNormal(to, b)
  2428. b = []string{}
  2429. }
  2430. }
  2431. if len(b) > 0 {
  2432. go cl.InviteIntoGroupNormal(to, b)
  2433. }
  2434. time.Sleep(5 * time.Millisecond)
  2435. } else {
  2436. cl.InviteIntoGroupNormal(to, mid)
  2437. }
  2438. }
  2439. func (self *Account) GetChats(groups []string) (*talkservice.GetChatsResponse, error) {
  2440. return self.Talk().GetChats(self.Ctx, &talkservice.GetChatsRequest{
  2441. ChatMids: groups,
  2442. WithMembers: true,
  2443. WithInvitees: true,
  2444. })
  2445. }
  2446. func (self *Account) RejectChatInvitation(chatMid string) error {
  2447. req := talkservice.NewRejectChatInvitationRequest()
  2448. req.ReqSeq = self.Seq
  2449. self.Seq++
  2450. req.ChatMid = chatMid
  2451. _, err := self.Talk().RejectChatInvitation(self.Ctx, req)
  2452. return err
  2453. }
  2454. func (self *Account) GetGroupsInvited() (r []string, err error) {
  2455. req := &talkservice.GetAllChatMidsRequest{
  2456. WithInvitedChats: true,
  2457. WithMemberChats: false,
  2458. }
  2459. rs, err := self.Talk().GetAllChatMids(self.Ctx, req, talkservice.SyncReason_UNKNOWN)
  2460. return rs.InvitedChatMids, err
  2461. }
  2462. func (self *Account) ReissueChatTicket(groupId string) (tiket string, err error) {
  2463. req := &talkservice.ReissueChatTicketRequest{
  2464. GroupMid: groupId,
  2465. ReqSeq: self.Seq,
  2466. }
  2467. self.Seq++
  2468. res, err := self.Talk().ReissueChatTicket(self.Ctx, req)
  2469. if err != nil {
  2470. CheckErr(self, err, groupId, "ReissueChatTicket")
  2471. return "", err
  2472. }
  2473. return res.TicketId, err
  2474. }
  2475. func (self *Account) GetGroupInvitation(groupId string) (string, map[string]int64) {
  2476. res, err := self.Talk().GetChats(context.TODO(), &talkservice.GetChatsRequest{
  2477. ChatMids: []string{groupId},
  2478. WithInvitees: true,
  2479. WithMembers: false,
  2480. })
  2481. if err != nil {
  2482. CheckErr(self, err, groupId, "GET_GROUP")
  2483. return "", map[string]int64{}
  2484. }
  2485. ch := res.Chats[0]
  2486. mem := ch.Extra.GroupExtra.InviteeMids
  2487. return ch.ChatName, mem
  2488. }
  2489. func (cl *Account) GetSameJoiningTime(to string, enemy string) []string {
  2490. defer PanicOnly()
  2491. memlist, _ := cl.GetChatListMap(to)
  2492. var together []string
  2493. var tj string
  2494. if IsMember(memlist, enemy) {
  2495. tj = strconv.FormatInt(memlist[enemy], 10)[:9]
  2496. for k, v := range memlist {
  2497. if strconv.FormatInt(v, 10)[:9] == tj {
  2498. together = append(together, k)
  2499. }
  2500. }
  2501. }
  2502. return together
  2503. }
  2504. func (cl *Account) GetTargetKickall(to string) []string {
  2505. c, err := cl.GetChats([]string{to})
  2506. if err != nil {
  2507. return []string{}
  2508. }
  2509. zxc := c.Chats[0].Extra.GroupExtra.MemberMids
  2510. var together []string
  2511. for k, _ := range zxc {
  2512. if k != cl.MID {
  2513. together = append(together, k)
  2514. }
  2515. }
  2516. return together
  2517. }
  2518. func (cl *Account) GetTargetCancelall(to string) []string {
  2519. c, err := cl.GetChats([]string{to})
  2520. if err != nil {
  2521. return []string{}
  2522. }
  2523. zxc := c.Chats[0].Extra.GroupExtra.InviteeMids
  2524. var together []string
  2525. for k, _ := range zxc {
  2526. if k != cl.MID {
  2527. together = append(together, k)
  2528. }
  2529. }
  2530. return together
  2531. }
  2532. func GETBackup(Midlist []string, mid string) int {
  2533. for num, x := range Midlist {
  2534. if x == mid {
  2535. if num+1 == len(Midlist) {
  2536. return 0
  2537. }
  2538. return num + 1
  2539. }
  2540. }
  2541. return 404
  2542. }
  2543. func (self *Account) GetRecommendationIds() (r []string, err error) {
  2544. res, err := self.Talk().GetRecommendationIds(self.Ctx, talkservice.SyncReason_UNKNOWN)
  2545. return res, err
  2546. }
  2547. func (self *Account) GetContacts(id []string) (r []*talkservice.Contact, err error) {
  2548. res, err := self.Talk().GetContacts(self.Ctx, id)
  2549. return res, err
  2550. }
  2551. func (self *Account) AcceptGroupInvitationNormal(groupId string) (err error) {
  2552. self.Talk().AcceptChatInvitation(self.Ctx, &talkservice.AcceptChatInvitationRequest{
  2553. ChatMid: groupId,
  2554. ReqSeq: self.Seq,
  2555. })
  2556. return nil
  2557. }
  2558. func (self *Account) FindAndAddContactsByMid3(mid string) (r map[string]*talkservice.Contact, err error) {
  2559. if self.MID == mid || self.Limitadd {
  2560. return map[string]*talkservice.Contact{}, nil
  2561. } else if self.Frez {
  2562. return map[string]*talkservice.Contact{}, nil
  2563. }
  2564. var TS *talkservice.TalkServiceClient
  2565. TS = self.Talk()
  2566. self.Add += 1
  2567. self.Lastadd = time.Now()
  2568. if self.Add >= 10 {
  2569. if !InArrayCl(Waitadd, self) {
  2570. Waitadd = append(Waitadd, self)
  2571. self.Timeadd = time.Now()
  2572. BlockAdd.Set(self.MID, time.Now())
  2573. }
  2574. self.Limitadd = false
  2575. return map[string]*talkservice.Contact{}, errors.New("limit goblok")
  2576. }
  2577. res, err := TS.FindAndAddContactsByMid(context.TODO(), self.Seq, mid, talkservice.ContactType_MID, `{"screen":"friendAdd:recommend","spec":"native"}`) //`{"screen":"homeTab","spec":"native"}`)
  2578. if err != nil {
  2579. e := GetCode(err)
  2580. fmt.Println(err)
  2581. if e == 35 {
  2582. if _, ok := GetBlockAdd.Get(self.MID); !ok {
  2583. GetBlockAdd.Set(self.MID, time.Now())
  2584. }
  2585. self.Limitadd = false
  2586. }
  2587. }
  2588. return res, err
  2589. }
  2590. ///Rom
  2591. func RoomClear(item *LineRoom) {
  2592. defer PanicOnly()
  2593. newitems := []*LineRoom{}
  2594. for _, i := range SquadRoom {
  2595. if i.Id == item.Id {
  2596. newitems = append(newitems, i)
  2597. }
  2598. }
  2599. SquadRoom = newitems
  2600. }
  2601. func RemoveRoom(items []*LineRoom, item *LineRoom) []*LineRoom {
  2602. defer PanicOnly()
  2603. newitems := []*LineRoom{}
  2604. for _, i := range items {
  2605. if i.Id != item.Id {
  2606. newitems = append(newitems, i)
  2607. }
  2608. }
  2609. return newitems
  2610. }
  2611. func (self *Account) DeleteOtherFromChat(groupId string, contactIds string) int {
  2612. if self.Limited == false {
  2613. _, err = self.Talk().DeleteOtherFromChat(context.TODO(), &talkservice.DeleteOtherFromChatRequest{
  2614. ChatMid: groupId,
  2615. ReqSeq: self.Seq,
  2616. TargetUserMids: []string{contactIds},
  2617. })
  2618. var aa = 0
  2619. AddCount(self, "kick")
  2620. GetRoom(groupId).Fight = time.Now()
  2621. if err != nil {
  2622. aa = CheckErr(self, err, groupId, "KICK")
  2623. }
  2624. self.Seq++
  2625. return aa
  2626. }
  2627. return 35
  2628. }
  2629. func GetRoom(to string) *LineRoom {
  2630. for _, room := range SquadRoom {
  2631. if room.Id == to {
  2632. return room
  2633. }
  2634. }
  2635. new := &LineRoom{Id: to, Userlurk: []string{}, MsgLeave: "See you nix time", WelcomeMsg: "Hallo Welcome Join", MsgLurk: "Hallo I See You.", Gowner: []string{}, Gadmin: []string{}, Gban: []string{}, ListInvited: []string{}, Bot: []string{}, GoMid: []string{}, ProKick: false, Limit: false, ProQr: false, ProName: false, ProInvite: false, ProJoin: false, ProCancel: false, AntiTag: false, Automute: false, Lurk: false, Announce: false, Qr: false, Purge: false}
  2636. SquadRoom = append(SquadRoom, new)
  2637. return new
  2638. }
  2639. func Actor(to string) (anu []*Account) {
  2640. for _, room := range SquadRoom {
  2641. if room.Id == to {
  2642. return room.HaveClient
  2643. }
  2644. }
  2645. return anu
  2646. }
  2647. func Gones(to string, cl *Account) {
  2648. for _, room := range SquadRoom {
  2649. if room.Id == to {
  2650. room.HaveClient = RemoveCl(room.HaveClient, cl)
  2651. return
  2652. }
  2653. }
  2654. }
  2655. // TODO
  2656. // here HashToMap func
  2657. func (self *LineRoom) Reset() {
  2658. self.Qr = true
  2659. for _, cl := range self.Ava {
  2660. if !cl.Client.Limited {
  2661. cl.Exist = true
  2662. }
  2663. }
  2664. self.HaveClient = append([]*Account{}, self.Client...)
  2665. }
  2666. func SetAva(to string, list []string) {
  2667. for _, room := range SquadRoom {
  2668. if room.Id == to {
  2669. for _, cls := range room.Ava {
  2670. if !cls.Client.Limited {
  2671. if InArray(list, cls.Mid) {
  2672. cls.Exist = true
  2673. } else {
  2674. cls.Exist = false
  2675. }
  2676. } else {
  2677. cls.Exist = false
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. func (self *LineRoom) AddSquad(bot []string, cls []*Account, goclint []*Account, midgo []string) {
  2684. self.Bot = bot
  2685. self.Client = cls
  2686. self.HaveClient = []*Account{}
  2687. self.Ava = []*Ava{}
  2688. self.GoMid = midgo
  2689. self.GoClient = goclint
  2690. for _, cl := range cls {
  2691. if !cl.Limited {
  2692. self.Ava = append(self.Ava, &Ava{Client: cl, Exist: true, Mid: cl.MID})
  2693. self.HaveClient = append(self.HaveClient, cl)
  2694. } else {
  2695. self.Ava = append(self.Ava, &Ava{Client: cl, Exist: false, Mid: cl.MID})
  2696. }
  2697. }
  2698. }
  2699. func (self *LineRoom) DelGo(cl *Account) {
  2700. if InArray(self.GoMid, cl.MID) {
  2701. self.GoMid = Remove(self.GoMid, cl.MID)
  2702. }
  2703. if InArrayCl(self.GoClient, cl) {
  2704. self.GoClient = RemoveCl(self.GoClient, cl)
  2705. }
  2706. }
  2707. func (self *LineRoom) Choose(client *Account) *Account {
  2708. for _, cl := range self.Ava {
  2709. if cl.Exist && cl.Client.Limited {
  2710. return cl.Client
  2711. }
  2712. }
  2713. return client
  2714. }
  2715. func (self *LineRoom) Names() []string {
  2716. anu := []string{}
  2717. for _, cl := range self.Ava {
  2718. if cl.Exist {
  2719. anu = append(anu, cl.Client.Namebot)
  2720. }
  2721. }
  2722. return anu
  2723. }
  2724. func (self *LineRoom) Cans() []*Account {
  2725. anu := []*Account{}
  2726. for _, cl := range self.Ava {
  2727. if cl.Exist {
  2728. anu = append(anu, cl.Client)
  2729. }
  2730. }
  2731. return anu
  2732. }
  2733. func (self *LineRoom) Invites() []string {
  2734. anu := []string{}
  2735. for _, cl := range self.Ava {
  2736. if !cl.Exist {
  2737. anu = append(anu, cl.Client.MID)
  2738. }
  2739. }
  2740. return anu
  2741. }
  2742. func RemoveAva(items []*Ava, item *Ava) []*Ava {
  2743. defer PanicOnly()
  2744. newitems := []*Ava{}
  2745. for _, i := range items {
  2746. if i != item {
  2747. newitems = append(newitems, i)
  2748. }
  2749. }
  2750. return newitems
  2751. }
  2752. func (self *LineRoom) RevertGo(cl *Account) {
  2753. if InArray(self.Bot, cl.MID) {
  2754. self.Bot = Remove(self.Bot, cl.MID)
  2755. }
  2756. if InArrayCl(self.Client, cl) {
  2757. self.Client = RemoveCl(self.Client, cl)
  2758. }
  2759. if InArrayCl(self.HaveClient, cl) {
  2760. self.HaveClient = append(self.HaveClient, cl)
  2761. }
  2762. for _, ava := range self.Ava {
  2763. if ava.Client == cl {
  2764. self.Ava = RemoveAva(self.Ava, ava)
  2765. }
  2766. }
  2767. if !InArray(self.GoMid, cl.MID) {
  2768. self.GoMid = append(self.GoMid, cl.MID)
  2769. }
  2770. if !InArrayCl(self.GoClient, cl) {
  2771. self.GoClient = append(self.GoClient, cl)
  2772. }
  2773. }
  2774. func (self *LineRoom) ConvertGo(cl *Account) {
  2775. if !InArray(self.Bot, cl.MID) {
  2776. self.Bot = append(self.Bot, cl.MID)
  2777. }
  2778. if !InArrayCl(self.Client, cl) {
  2779. self.Client = append(self.Client, cl)
  2780. }
  2781. if !InArrayCl(self.HaveClient, cl) {
  2782. self.HaveClient = append(self.HaveClient, cl)
  2783. }
  2784. if !InArrayAva(self.Ava, cl) {
  2785. if cl.Limited {
  2786. self.Ava = append(self.Ava, &Ava{Client: cl, Exist: true, Mid: cl.MID})
  2787. } else {
  2788. self.Ava = append(self.Ava, &Ava{Client: cl, Exist: false, Mid: cl.MID})
  2789. }
  2790. }
  2791. if InArray(self.GoMid, cl.MID) {
  2792. self.GoMid = Remove(self.GoMid, cl.MID)
  2793. }
  2794. if InArrayCl(self.GoClient, cl) {
  2795. self.GoClient = RemoveCl(self.GoClient, cl)
  2796. }
  2797. }
  2798. func InArrayAva(arr []*Ava, str *Account) bool {
  2799. for _, tar := range arr {
  2800. if tar.Client == str {
  2801. return true
  2802. }
  2803. }
  2804. return false
  2805. }
  2806. func Archimed(s string, list []string) []string {
  2807. ln := len(list)
  2808. ls := []int{}
  2809. ind := []int{}
  2810. hasil := []string{}
  2811. if strings.Contains(s, ",") {
  2812. logics := strings.Split(s, ",")
  2813. for _, logic := range logics {
  2814. if strings.Contains(logic, ">") {
  2815. su := strings.TrimPrefix(logic, ">")
  2816. si, _ := strconv.Atoi(su)
  2817. si -= 1
  2818. for i := (si + 1); i > si && i <= ln; i++ {
  2819. ls = append(ls, i)
  2820. }
  2821. } else if strings.Contains(logic, "<") {
  2822. su := strings.TrimPrefix(logic, "<")
  2823. si, _ := strconv.Atoi(su)
  2824. si -= 1
  2825. for i := 0; i <= si; i++ {
  2826. ls = append(ls, i)
  2827. }
  2828. } else if strings.Contains(logic, "-") {
  2829. las := strings.Split(logic, "-")
  2830. si := las[0]
  2831. siu, _ := strconv.Atoi(si)
  2832. siu -= 1
  2833. sa := las[1]
  2834. sau, _ := strconv.Atoi(sa)
  2835. sau -= 1
  2836. for i := (siu); i >= siu && i <= sau; i++ {
  2837. ls = append(ls, i)
  2838. }
  2839. } else {
  2840. sau, _ := strconv.Atoi(logic)
  2841. sau -= 1
  2842. ls = append(ls, sau)
  2843. }
  2844. }
  2845. } else {
  2846. logic := s
  2847. if strings.Contains(logic, ">") {
  2848. su := strings.TrimPrefix(logic, ">")
  2849. si, _ := strconv.Atoi(su)
  2850. si -= 1
  2851. for i := (si + 1); i > si && i <= ln; i++ {
  2852. ls = append(ls, i)
  2853. }
  2854. } else if strings.Contains(logic, "<") {
  2855. su := strings.TrimPrefix(logic, "<")
  2856. si, _ := strconv.Atoi(su)
  2857. si -= 1
  2858. for i := 0; i <= si; i++ {
  2859. ls = append(ls, i)
  2860. }
  2861. } else if strings.Contains(logic, "-") {
  2862. las := strings.Split(logic, "-")
  2863. si := las[0]
  2864. siu, _ := strconv.Atoi(si)
  2865. siu -= 1
  2866. sa := las[1]
  2867. sau, _ := strconv.Atoi(sa)
  2868. sau -= 1
  2869. for i := (siu); i >= siu && i <= sau; i++ {
  2870. ls = append(ls, i)
  2871. }
  2872. } else {
  2873. sau, _ := strconv.Atoi(logic)
  2874. sau -= 1
  2875. ls = append(ls, sau)
  2876. }
  2877. }
  2878. for _, do := range ls {
  2879. if !InArrayInt(ind, do) && do < ln {
  2880. jo := list[do]
  2881. ind = append(ind, do)
  2882. hasil = append(hasil, jo)
  2883. }
  2884. }
  2885. return hasil
  2886. }
  2887. func (self *LineRoom) Joins(cl *Account) {
  2888. defer PanicOnly()
  2889. for _, cls := range self.Ava {
  2890. if cls.Client == cl {
  2891. if cl.Limited {
  2892. cls.Exist = true
  2893. }
  2894. return
  2895. }
  2896. }
  2897. }
  2898. func Checkarri(cl []*Account, self *Account) bool {
  2899. defer PanicOnly()
  2900. for _, cls := range cl {
  2901. if self == cls {
  2902. return true
  2903. }
  2904. }
  2905. return false
  2906. }
  2907. func Qrend(to string) {
  2908. for _, room := range SquadRoom {
  2909. if room.Id == to {
  2910. room.Qr = true
  2911. return
  2912. }
  2913. }
  2914. new := &LineRoom{Id: to, Userlurk: []string{}, MsgLeave: "See you nix time", WelcomeMsg: "Hallo Welcome Join", MsgLurk: "Hallo I See You.", ListInvited: []string{}, Gowner: []string{}, Gadmin: []string{}, Gban: []string{}, Bot: []string{}, GoMid: []string{}, ProKick: false, Limit: false, ProQr: false, ProName: false, ProInvite: false, ProJoin: false, ProCancel: false, AntiTag: false, Automute: false, Lurk: false, Announce: false, Qr: false, Purge: false}
  2915. SquadRoom = append(SquadRoom, new)
  2916. }
  2917. func ClearProtect() {
  2918. for _, room := range SquadRoom {
  2919. room.ProKick = false
  2920. room.ProCancel = false
  2921. room.ProName = false
  2922. room.ProInvite = false
  2923. room.ProJoin = false
  2924. room.ProQr = false
  2925. }
  2926. }
  2927. func (room *LineRoom) AutoBro() {
  2928. room.ProKick = true
  2929. room.ProCancel = true
  2930. room.ProName = true
  2931. room.ProInvite = true
  2932. room.ProQr = true
  2933. }
  2934. func ListProtect() string {
  2935. ret := "༗ 𝗟𝗶𝘀𝘁 𝗣𝗿𝗼𝘁𝗲𝗰𝘁 ༗"
  2936. for _, room := range SquadRoom {
  2937. ret += fmt.Sprintf("\n\n Group: %s\n", room.Name)
  2938. if room.ProQr {
  2939. ret += "\n 🟢 Pro QR"
  2940. } else {
  2941. ret += "\n 🔴 Pro QR"
  2942. }
  2943. if room.AntiTag {
  2944. ret += "\n 🟢 Antitag"
  2945. } else {
  2946. ret += "\n 🔴 Antitag"
  2947. }
  2948. if room.ProKick {
  2949. ret += "\n 🟢 Pro Kick"
  2950. } else {
  2951. ret += "\n 🔴 Pro Kick"
  2952. }
  2953. if room.ProInvite {
  2954. ret += "\n 🟢 Pro Invite"
  2955. } else {
  2956. ret += "\n 🔴 Pro Invite"
  2957. }
  2958. if room.ProCancel {
  2959. ret += "\n 🟢 Pro Cancel"
  2960. } else {
  2961. ret += "\n 🔴 Pro Cancel"
  2962. }
  2963. if room.ProJoin {
  2964. ret += "\n 🟢 Pro Join"
  2965. } else {
  2966. ret += "\n 🔴 Pro Join"
  2967. }
  2968. if room.ProName {
  2969. ret += "\n 🟢 Pro Name"
  2970. } else {
  2971. ret += "\n 🔴 Pro Name"
  2972. }
  2973. if len(room.GoMid) > 0 {
  2974. ret += "\n 🟢 Pro Ajs"
  2975. } else {
  2976. ret += "\n 🔴 Pro Ajs"
  2977. }
  2978. }
  2979. return ret
  2980. }
  2981. func Qrstart(to string) {
  2982. for _, room := range SquadRoom {
  2983. if room.Id == to {
  2984. room.Qr = false
  2985. return
  2986. }
  2987. }
  2988. new := &LineRoom{Id: to, Userlurk: []string{}, MsgLeave: "See you nix time", WelcomeMsg: "Hallo Welcome Join", MsgLurk: "Hallo I See You.", ListInvited: []string{}, Gowner: []string{}, Gadmin: []string{}, Gban: []string{}, Bot: []string{}, GoMid: []string{}, ProKick: false, Limit: false, ProQr: false, ProName: false, ProInvite: false, ProJoin: false, ProCancel: false, AntiTag: false, Automute: false, Lurk: false, Announce: false, Qr: false, Purge: false}
  2989. SquadRoom = append(SquadRoom, new)
  2990. }
  2991. func CheckSquadRoom() []*LineRoom {
  2992. return SquadRoom
  2993. }
  2994. func (room *LineRoom) WelsomeSet(cl *Account, to, mid string) {
  2995. if room.Welcome {
  2996. list := fmt.Sprintf("Group: %v\n\n", room.Name)
  2997. list += "!@ "
  2998. list += fmt.Sprintf("\n\n%v", room.WelcomeMsg)
  2999. cl.SendMention4(to, list, []string{mid})
  3000. }
  3001. }
  3002. func (room *LineRoom) LeaveSet(cl *Account, to, mid string) {
  3003. if room.Leavebool {
  3004. list := fmt.Sprintf("Group: %v\n\n", room.Name)
  3005. list += "!@ "
  3006. list += fmt.Sprintf("\n\n%v", room.MsgLeave)
  3007. cl.SendMention4(to, list, []string{mid})
  3008. }
  3009. }
  3010. func (room *LineRoom) CheckLurk(cl *Account, to, mid string) {
  3011. if !InArray(room.Userlurk, mid) {
  3012. if room.NameLurk == "name" {
  3013. room.Userlurk = append(room.Userlurk, mid)
  3014. x, _ := cl.GetContact(mid)
  3015. lis := "- %v "
  3016. lis += room.MsgLurk
  3017. list := fmt.Sprintf(lis, x.DisplayName)
  3018. cl.SendMessage(to, list)
  3019. } else if room.NameLurk == "mention" {
  3020. room.Userlurk = append(room.Userlurk, mid)
  3021. lis := "%v "
  3022. lis += room.MsgLurk
  3023. cl.SendMention3(to, lis, []string{mid})
  3024. } else if room.NameLurk == "hide" {
  3025. room.Userlurk = append(room.Userlurk, mid)
  3026. }
  3027. if room.ImageLurk == true {
  3028. x, _ := cl.GetContact(mid)
  3029. cl.SendImageWithURL(to, "https://profile.line-scdn.net/"+x.PicturePath)
  3030. }
  3031. }
  3032. }
  3033. func (room *LineRoom) CheckAnnounce(cl *Account, to string) {
  3034. chat, from := cl.GetChatRoomAnnouncements(to)
  3035. tx := fmt.Sprintf("Announced a message:\nFrom: @! \n\n %s", chat)
  3036. cl.SendMention(to, tx, []string{from})
  3037. }
  3038. func (cl *Account) GetChatRoomAnnouncements(roomId string) (chat string, mid string) {
  3039. ann, err := cl.Talk().GetChatRoomAnnouncements(cl.Ctx, roomId)
  3040. if err != nil {
  3041. fmt.Println(err)
  3042. return "", ""
  3043. }
  3044. if len(ann) != 0 {
  3045. chat = ann[0].Contents.Text
  3046. mid = ann[0].CreatorMid
  3047. return chat, mid
  3048. }
  3049. return "", ""
  3050. }
  3051. func IoGOBot(to string, cl *Account) bool {
  3052. for _, room := range SquadRoom {
  3053. if room.Id == to {
  3054. for _, cls := range room.GoClient {
  3055. if cl == cls {
  3056. return false
  3057. }
  3058. }
  3059. return true
  3060. }
  3061. }
  3062. return true
  3063. }
  3064. func (self *LineRoom) Act(cl *Account) bool {
  3065. for _, cls := range self.Ava {
  3066. if cls.Client == cl {
  3067. if cls.Exist {
  3068. return true
  3069. } else {
  3070. return false
  3071. }
  3072. }
  3073. }
  3074. return false
  3075. }