コード例 #1
0
ファイル: client.py プロジェクト: FukeKazki/python-bbs
def main():
    action = input('何をしますか?\n1: 読み込み\n2: 書き込み\n3: 削除\n')
    sock = Client(("localhost", 50000))

    if action == Action.WRITE.value:
        handle_name = input('handle_name: ')
        content = input('content: ')
        password = getpass('password: '******'書き込みに失敗しました。')
        else:
            print('書き込みに成功しました。')

    elif action == Action.READ.value:
        body = Body(action=Action.READ.value)

        sock.send_body(body)

        response = sock.recv_response()

        if response.state == State.FAILED.value:
            print('受信に失敗しました。')

        for message in response.messages:
            print('--------------------')
            print(f"ID: {message.id}")
            print(f"TIME: {message.time}")
            print(f"HANDLE NAME: {message.handle_name}")
            print(f"CONTENT: {message.content}")

    elif action == Action.DELETE.value:
        identify = input('id: ')
        password = getpass('password: '******'IDもしくはPASSWORDが間違っています。')
        else:
            print('削除に成功しました。')

    else:
        pass
コード例 #2
0
ファイル: server_socket.py プロジェクト: aeftimia/hexchat
    def send_disconnect_error(self,
                              key,
                              from_aliases,
                              to_alias,
                              message=False):
        '''called when a connection times out'''

        (local_address, remote_address) = (key[0], key[2])
        packet = format_header(local_address, remote_address,
                               ElementTree.Element("disconnect_error"))
        packet.attrib['xmlns'] = "hexchat:disconnect_error"
        packet = self.master.add_aliases(packet, from_aliases)
        logging.debug(
            "%s:%d" % local_address + \
            " sending disconnect_error request to %s:%d" % remote_address
            )

        if message:
            msg = Message()
            msg['type'] = 'chat'
        else:
            msg = Iq()
            msg['type'] = 'set'

        msg['to'] = to_alias
        msg.append(packet)

        self.master.send(msg, from_aliases, now=True)
コード例 #3
0
ファイル: pageblock.py プロジェクト: wyl-hit/job
 def __init__(self, crawler):
     super(PythonJavascript, self).__init__()
     print "PythonJavascript __init__ start"
     self.crawler = crawler
     self.message = Message(self.crawler.message_type, {
         "url": "",
         "vectors": []
     }).message
コード例 #4
0
ファイル: ui.py プロジェクト: sammiej/vpn
def sendClick():
    data = screen["dataToSend"].get()
    if data:
        screen["dataToSend"].set("")
        logger.info("sending: {}".format(data))
        try:
            msg = Message(Message.SEND, data)
            Q.put_nowait(msg)
        except Full:
            logger.error("Network queue is full!")
コード例 #5
0
ファイル: bot.py プロジェクト: pelusodan/ReactAnalytics
 def message_posted(slack_event):
     try:
         event = slack_event['event']
         channel_id = event['channel']
         user_id = event['user']
         time_stamp = event['ts']
         text = event['text']
         msg = Message('', channel_id, time_stamp, user_id, text)
         db.add_message(msg)
     except:
         logging.getLogger(__name__).error('Failed to unpack slack event')
コード例 #6
0
ファイル: client.py プロジェクト: FukeKazki/python-line
def write(sock):
    while True:
        content = input()

        message = Message(content=content)

        body = Body(message=message)

        sock.send_body(body)

        if content == 'bye':
            break
コード例 #7
0
ファイル: system.py プロジェクト: Flonki/MyBot
    def run(self, message, args: list):
        text = ""
        title = args[1]
        args.pop(0)
        args.pop(0)

        for arg in args:
            text = text + arg + " "
        embed = discord.Embed(title=title, description=text, color=0x00ff00)

        data.messages.append(
            Message(embed, data.client.get_channel(717753910865166376)))

        return "Created Message in Chat"
コード例 #8
0
ファイル: server_socket.py プロジェクト: aeftimia/hexchat
    def send_connect(self, key, aliases, message=False):
        '''Send a connect request'''

        (local_address, remote_address) = (key[0], key[2])
        packet = format_header(local_address, remote_address,
                               ElementTree.Element("connect"))
        packet.attrib['xmlns'] = "hexchat:connect"

        packet = self.master.add_aliases(packet, aliases)

        logging.debug("%s:%d" % local_address +
                      " sending connect request to %s:%d" % remote_address)

        if message:  #send by message
            msg = Message()
            msg['type'] = 'chat'
        else:  #send by iq
            msg = Iq()
            msg['type'] = 'set'

        msg['to'] = key[1]
        msg.append(packet)

        self.master.send(msg, aliases, now=True)
コード例 #9
0
    def on_chat_message(self, message):
        msg = Message(message)
        if not msg.istext:
            print('Chat:', msg.content_type, msg.chat_type, msg.chat_id)
            self.active = False
            return

        self.dataManager.write_message(msg.object)
        rawcommand = msg.raw
        command = msg.normalised
        self.sendername = msg.sendername
        try:
            print('Chat:', msg.chat_type, msg.chat_id, msg.normalised)
        except UnicodeDecodeError:
            print('Chat:', msg.chat_type, msg.chat_id, msg.normalised.encode('utf-8'))

        #slash commands first
        if msg.raw.startswith("/"):
            for k in self.slashcommands.keys():
                cmd = msg.raw.split()[0]
                if cmd[1:] == k:
                    msg.command = msg.raw[len(k)+2:].strip()
                    v = self.slashcommands[k](self, msg)
                    if v: self.sendMessage(msg.chat_id, v)
                    return

        #if modules.games.is_games_message(msg):
        #    modules.games.parse_message(self, msg)
        #    return
        
        #Morning message
        if msg.date-self.morning_message_timer> 3600*16: #16 hours since last message
            h = get_current_hour()
            if h>6 and h <12: #it is morning
                v = self.morning_message(self.homegroup,command)
                if v:
                    self.morning_message_timer = msg.date
                    self.sendMessage(self.homegroup,v)
                    return

        if msg.chat_id in self.silentchats:
            self.active = False
            return
        
        #now for the fun stuff :)

        #custom user responses
        c = prepare_query(msg.raw)
        if c in self.aliasdict:
            t = msg.date
            if t-self.lastupdate > 1800: #every half hour update my willingness to say stuff
                self.update_querycounts(int((t-self.lastupdate)/1800))
                self.lastupdate = t
            if self.react_to_query(c):
                p = self.pick(self.userresponses[self.aliasdict[c]])
                p = p.replace("!name", msg.sendername)
                if p: self.sendMessage(msg.chat_id, p)
                return
            
        #respond to cussing
        if startswith(msg.normalised.replace(", "," "), self.commands['cuss_out']):
            self.sendMessage(msg.chat_id, self.pick(self.responses['cuss_out']))
            return
        command = msg.normalised
        for i in self.commands['introductions']:
            if command.startswith(i):
                command = command[len(i)+1:].strip()
                break
        else:
            if not self.active: return #no introduction given and not active
        if command.startswith(","): command = command[1:].strip()
        if command.startswith("."): command = command[1:].strip()

        #No further command is given so we just say hi
        if not command:
            try:
                name = msg.sendername
                if name == "Olaf": name = "Slomp"
                val = self.pick(self.responses["hi"]).replace("!name",name)
                self.sendMessage(msg.chat_id, val)
                if probaccept(0.07):
                    time.sleep(1.0)
                    self.sendMessage(msg.chat_id, modules.entertainment.get_joke())
                return
            except KeyError:
                self.active = False
                return

        #check if the command corresponds to a module
        for cmd in self.commandcategories.keys():
            s = startswith(command, self.commands[cmd])
            if s:
                msg.command = command[len(s)+1:].strip()
                r = self.commandcategories[cmd](self, msg)
                if r and type(r)==str: self.sendMessage(msg.chat_id, r)
                return
        
        #try approximate custom matches
        options = difflib.get_close_matches(command,self.aliasdict.keys(),n=1,cutoff=0.9)
        if not options: options = difflib.get_close_matches(prepare_query(msg.raw),self.aliasdict.keys(),n=1,cutoff=0.9)
        if options:
            if self.react_to_query(options[0]):
                p = self.pick(self.userresponses[self.aliasdict[options[0]]])
                p = p.replace("!name", msg.sendername)
                if p: self.sendMessage(msg.chat_id, p)
                return

        #haha... kont
        if command.find("kont")!=-1:
            self.sendMessage(msg.chat_id, "Hahaha, je zei kont")
            return
        if command.find("cont")!=-1:
            self.sendMessage(msg.chat_id, "Hahaha, je zei cont")
            return
        
        #questions and other random reactions
        if len(command)>6:
            chat_id = msg.chat_id
            if command[-5:].find("?")!=-1 or command[-5:].find("/")!=-1 or command[-5:].find(">")!=-1: #? and common misspellings
                if (command.find("wat vind")!=-1 or command.find("hoe denk")!=-1 or command.find("vind je")!=-1
                    or command.find("wat is je mening")!=-1 or command.find("wat denk")!=-1):
                    self.sendMessage(chat_id, self.pick(self.responses["question_opinion"]))
                elif startswith(command, ["heb","ben ","zijn ","was ","waren ","is ","ga","zal ","moet "]):
                    self.sendMessage(chat_id, self.pick(self.responses["question_degree"]))
                elif command.find("hoeveel")!=-1 or command.find("hoe veel")!=-1 or command.find("hoe vaak")!=-1:
                    self.sendMessage(chat_id, self.pick(self.responses["question_amount"]))
                elif command.find("waarom")!=-1:
                    self.sendMessage(chat_id, self.pick(self.responses["question_why"]))
                elif command.find("wat ")!=-1:
                    self.sendMessage(chat_id, self.pick(self.responses["question_what"]))
                elif command.find("waarvoor ")!=-1:
                    self.sendMessage(chat_id, self.pick(self.responses["question_waarvoor"]))
                elif command.find("waar ")!=-1:
                    self.sendMessage(chat_id, self.pick(self.responses["question_where"]))
                elif command.find("wanneer")!=-1 or command.find("hoe laat")!=-1:
                    self.sendMessage(chat_id, self.pick(self.responses["question_when"]))
                elif command.find("hoe ")!=-1:
                    self.sendMessage(chat_id, self.pick(self.responses["question_how"]))
                elif command.find("welk")!=-1:
                    self.sendMessage(chat_id, self.pick(self.responses["question_which"]))
                elif command.find("wie")!=-1:
                    self.sendMessage(chat_id, self.pick(self.responses["question_who"]))
                else: #yes/no question
                    self.sendMessage(chat_id, self.pick(self.responses["question_degree"]))
                return
            self.active = False
            if probaccept(0.05):
                self.sendMessage(chat_id, modules.entertainment.get_openingline())
            elif probaccept(0.15):
                self.sendMessage(chat_id,self.pick(self.responses["negative_response"]))
            elif probaccept(0.08):
                r = random.randint(0,len(self.userresponses)-1) # this works because the keys of userresponses are consecutive integers
                self.sendMessage(chat_id, self.pick(self.userresponses[r]))
            return
        
        self.active = False
        return
コード例 #10
0
ファイル: bot.py プロジェクト: pelusodan/ReactAnalytics
 def message_removed(self, slack_event):
     db.remove_message(
         Message('', slack_event['channel'], slack_event['ts'], '', ''))