Created
November 27, 2017 15:41
-
-
Save galpt/763e554916223e3449fb9c47b39d7373 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from LineAlpha import LineClient | |
| from LineAlpha.LineApi import LineTracer | |
| from LineAlpha.LineThrift.ttypes import Message | |
| from LineAlpha.LineThrift.TalkService import Client | |
| import time, datetime, random ,sys, re, string, os, json | |
| reload(sys) | |
| sys.setdefaultencoding('utf-8') | |
| client = LineClient() | |
| client._qrLogin("line://au/q/") | |
| profile, setting, tracer = client.getProfile(), client.getSettings(), LineTracer(client) | |
| offbot, messageReq, wordsArray, waitingAnswer = [], {}, {}, {} | |
| print client._loginresult() | |
| wait = { | |
| 'readPoint':{}, | |
| 'readMember':{}, | |
| 'setTime':{}, | |
| 'ROM':{} | |
| } | |
| setTime = {} | |
| setTime = wait["setTime"] | |
| def sendMessage(to, text, contentMetadata={}, contentType=0): | |
| mes = Message() | |
| mes.to, mes.from_ = to, profile.mid | |
| mes.text = text | |
| mes.contentType, mes.contentMetadata = contentType, contentMetadata | |
| if to not in messageReq: | |
| messageReq[to] = -1 | |
| messageReq[to] += 1 | |
| client._client.sendMessage(messageReq[to], mes) | |
| def NOTIFIED_ADD_CONTACT(op): | |
| try: | |
| sendMessage(op.param1, client.getContact(op.param1).displayName + "Thanks for add") | |
| except Exception as e: | |
| print e | |
| print ("\n\nNOTIFIED_ADD_CONTACT\n\n") | |
| return | |
| tracer.addOpInterrupt(5,NOTIFIED_ADD_CONTACT) | |
| def NOTIFIED_ACCEPT_GROUP_INVITATION(op): | |
| #print op | |
| try: | |
| sendMessage(op.param1, client.getContact(op.param2).displayName + "WELCOME to " + group.name) | |
| except Exception as e: | |
| print e | |
| print ("\n\nNOTIFIED_ACCEPT_GROUP_INVITATION\n\n") | |
| return | |
| tracer.addOpInterrupt(17,NOTIFIED_ACCEPT_GROUP_INVITATION) | |
| def NOTIFIED_KICKOUT_FROM_GROUP(op): | |
| try: | |
| sendMessage(op.param1, client.getContact(op.param3).displayName + " Good Bye\n(*´・ω・*)") | |
| except Exception as e: | |
| print e | |
| print ("\n\nNOTIFIED_KICKOUT_FROM_GROUP\n\n") | |
| return | |
| tracer.addOpInterrupt(19,NOTIFIED_KICKOUT_FROM_GROUP) | |
| def NOTIFIED_LEAVE_GROUP(op): | |
| try: | |
| sendMessage(op.param1, client.getContact(op.param2).displayName + " Good Bye\n(*´・ω・*)") | |
| except Exception as e: | |
| print e | |
| print ("\n\nNOTIFIED_LEAVE_GROUP\n\n") | |
| return | |
| tracer.addOpInterrupt(15,NOTIFIED_LEAVE_GROUP) | |
| def NOTIFIED_READ_MESSAGE(op): | |
| #print op | |
| try: | |
| if op.param1 in wait['readPoint']: | |
| Name = client.getContact(op.param2).displayName | |
| if Name in wait['readMember'][op.param1]: | |
| pass | |
| else: | |
| wait['readMember'][op.param1] += "\n・" + Name | |
| wait['ROM'][op.param1][op.param2] = "・" + Name | |
| else: | |
| pass | |
| except: | |
| pass | |
| tracer.addOpInterrupt(55, NOTIFIED_READ_MESSAGE) | |
| def RECEIVE_MESSAGE(op): | |
| msg = op.message | |
| try: | |
| if msg.contentType == 0: | |
| try: | |
| if msg.to in wait['readPoint']: | |
| if msg.from_ in wait["ROM"][msg.to]: | |
| del wait["ROM"][msg.to][msg.from_] | |
| else: | |
| pass | |
| except: | |
| pass | |
| else: | |
| pass | |
| except KeyboardInterrupt: | |
| sys.exit(0) | |
| except Exception as error: | |
| print error | |
| print ("\n\nRECEIVE_MESSAGE\n\n") | |
| return | |
| tracer.addOpInterrupt(26, RECEIVE_MESSAGE) | |
| def SEND_MESSAGE(op): | |
| msg = op.message | |
| try: | |
| if msg.toType == 0: | |
| if msg.contentType == 0: | |
| if msg.text == "mid.gpt": | |
| sendMessage(msg.to, msg.to) | |
| if msg.text == "me.gpt": | |
| sendMessage(msg.to, text=None, contentMetadata={'mid': msg.from_}, contentType=13) | |
| if msg.text == "gift.gpt": | |
| sendMessage(msg.to, text="gift sent", contentMetadata=None, contentType=9) | |
| else: | |
| pass | |
| else: | |
| pass | |
| if msg.toType == 2: | |
| if msg.contentType == 0: | |
| if msg.text == "mid.gpt": | |
| sendMessage(msg.to, msg.from_) | |
| if msg.text == "gid.gpt": | |
| sendMessage(msg.to, msg.to) | |
| if msg.text == "ginfo.gpt": | |
| group = client.getGroup(msg.to) | |
| md = "[Group Name]\n" + group.name + "\n\n[gid]\n" + group.id + "\n\n[Group Picture]\nhttp://dl.profile.line-cdn.net/" + group.pictureStatus | |
| if group.preventJoinByTicket is False: md += "\n\nInvitationURL: Permitted\n" | |
| else: md += "\n\nInvitationURL: Refusing\n" | |
| if group.invitee is None: md += "\nMembers: " + str(len(group.members)) + "人\n\nInviting: 0People" | |
| else: md += "\nMembers: " + str(len(group.members)) + "People\nInvited: " + str(len(group.invitee)) + "People" | |
| sendMessage(msg.to,md) | |
| if "gname:" in msg.text: | |
| key = msg.text[22:] | |
| group = client.getGroup(msg.to) | |
| group.name = key | |
| client.updateGroup(group) | |
| sendMessage(msg.to,"Group Name"+key+"Canged to") | |
| if msg.text == "url.gpt": | |
| sendMessage(msg.to,"line://ti/g/" + client._client.reissueGroupTicket(msg.to)) | |
| if msg.text == "open.gpt": | |
| group = client.getGroup(msg.to) | |
| if group.preventJoinByTicket == False: | |
| sendMessage(msg.to, "already open") | |
| else: | |
| group.preventJoinByTicket = False | |
| client.updateGroup(group) | |
| sendMessage(msg.to, "URL Open") | |
| if msg.text == "close.gpt": | |
| group = client.getGroup(msg.to) | |
| if group.preventJoinByTicket == True: | |
| sendMessage(msg.to, "already close") | |
| else: | |
| group.preventJoinByTicket = True | |
| client.updateGroup(group) | |
| sendMessage(msg.to, "URL close") | |
| if "kick:" in msg.text: | |
| key = msg.text[5:] | |
| client.kickoutFromGroup(msg.to, [key]) | |
| contact = client.getContact(key) | |
| sendMessage(msg.to, ""+contact.displayName+"sorry") | |
| if "nk:" in msg.text: | |
| key = msg.text[3:] | |
| group = client.getGroup(msg.to) | |
| Names = [contact.displayName for contact in group.members] | |
| Mids = [contact.mid for contact in group.members] | |
| if key in Names: | |
| kazu = Names.index(key) | |
| sendMessage(msg.to, "Bye") | |
| client.kickoutFromGroup(msg.to, [""+Mids[kazu]+""]) | |
| contact = client.getContact(Mids[kazu]) | |
| sendMessage(msg.to, ""+contact.displayName+" Sorry") | |
| else: | |
| sendMessage(msg.to, "wtf?") | |
| if msg.text == "cancel.gpt": | |
| group = client.getGroup(msg.to) | |
| if group.invitee is None: | |
| sendMessage(op.message.to, "No one is inviting.") | |
| else: | |
| gInviMids = [contact.mid for contact in group.invitee] | |
| client.cancelGroupInvitation(msg.to, gInviMids) | |
| sendMessage(msg.to, str(len(group.invitee)) + " Done") | |
| if "invite:" in msg.text: | |
| key = msg.text[-33:] | |
| client.findAndAddContactsByMid(key) | |
| client.inviteIntoGroup(msg.to, [key]) | |
| contact = client.getContact(key) | |
| sendMessage(msg.to, ""+contact.displayName+" I invited you") | |
| if msg.text == "me.gpt": | |
| M = Message() | |
| M.to = msg.to | |
| M.contentType = 13 | |
| M.contentMetadata = {'mid': msg.from_} | |
| client.sendMessage(M) | |
| if "show:" in msg.text: | |
| key = msg.text[-33:] | |
| sendMessage(msg.to, text=None, contentMetadata={'mid': key}, contentType=13) | |
| contact = client.getContact(key) | |
| sendMessage(msg.to, ""+contact.displayName+"'s contact") | |
| if msg.text == "time.gpt": | |
| sendMessage(msg.to, "Current time is" + datetime.datetime.today().strftime('%Y年%m月%d日 %H:%M:%S') + "is") | |
| if msg.text == "gift.gpt": | |
| sendMessage(msg.to, text="gift sent", contentMetadata=None, contentType=9) | |
| if msg.text == "set.gpt": | |
| sendMessage(msg.to, "Ok.\n「read.gpt」") | |
| try: | |
| del wait['readPoint'][msg.to] | |
| del wait['readMember'][msg.to] | |
| except: | |
| pass | |
| wait['readPoint'][msg.to] = msg.id | |
| wait['readMember'][msg.to] = "" | |
| wait['setTime'][msg.to] = datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S') | |
| wait['ROM'][msg.to] = {} | |
| print wait | |
| if msg.text == "read.gpt": | |
| if msg.to in wait['readPoint']: | |
| if wait["ROM"][msg.to].items() == []: | |
| chiya = "" | |
| else: | |
| chiya = "" | |
| for rom in wait["ROM"][msg.to].items(): | |
| print rom | |
| chiya += rom[1] + "\n" | |
| sendMessage(msg.to, "Read by %s\nSilent reader(s)\n%s\n\nMarked date n time:\n[%s]" % (wait['readMember'][msg.to],chiya,setTime[msg.to])) | |
| else: | |
| sendMessage(msg.to, "No mark has been set.\n「set.gpt」 Mark will be created.") | |
| else: | |
| pass | |
| else: | |
| pass | |
| except Exception as e: | |
| print e | |
| print ("\n\nSEND_MESSAGE\n\n") | |
| return | |
| tracer.addOpInterrupt(25,SEND_MESSAGE) | |
| while True: | |
| tracer.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment