Beispiel #1
0
def receive_message(msg):
    if msg["date"] < time.time() - 2:
        return  # old
    logger.msg(msg)
    if msg["text"] == "/help" or msg["text"] == "/help@" + bot.getBotUsername(
    ):
        keyboard = {"keyboard": [["/help"], ["/quit"], ["/test keyboard"]]}
        bot.sendMessage(msg["chat"]["id"],
                        "Commands: (in custom keyboard)",
                        reply_markup=json.dumps(keyboard))
    if msg["text"] == "/quit" or msg["text"] == "/quit@" + bot.getBotUsername(
    ):
        if msg["from"]["id"] == 43804645:
            bot.sendMessage(msg["chat"]["id"], "Bye!")
            bot.quit = True
        else:
            bot.sendMessage(msg["chat"]["id"], "You don't have permission!")
    if msg["text"] == "/test keyboard":
        keyboard = {
            "keyboard": [[
                "1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣", "0⃣",
                "XD"
            ], ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],
                         ["/help", "/quit", "/test keyboard"]]
        }
        bot.sendMessage(msg["chat"]["id"],
                        "Sending custom keyboard!",
                        reply_markup=json.dumps(keyboard))
Beispiel #2
0
 def onOutgoingCall( self, id, caller, callee ):
     now = datetime.datetime.now() 
     logger.msg( "Invoked onOutgoingCall handler" )
     
     query = "begin; \
             insert into calls ( dt_start, id_caller ) values( '%s', %s ); \
             select currval('calls_id_seq');" % ( now, caller ) 
     self.db.runQuery( query ).addCallback( self.addDictionaryEntry, id ).addCallback( self.insertCallHistory, self.callStatuses[ 'OUTGOING' ], now ).addErrback( self._queryFail )
Beispiel #3
0
 def onAnswer( self, id, caller, callee ):
     now = datetime.datetime.now()
      
     logger.msg( "Invoked onAnswer handler" )
     
     if not self.ids.has_key( id ):
         logger.warn( "Something strange happened: answered a non-received call." )
     else:
         self.insertCallHistory( self.ids[ id ], self.callStatuses[ 'ANSWER' ], now )
Beispiel #4
0
    def onAnswer(self, id, caller, callee):
        now = datetime.datetime.now()

        logger.msg("Invoked onAnswer handler")

        if not self.ids.has_key(id):
            logger.warn(
                "Something strange happened: answered a non-received call.")
        else:
            self.insertCallHistory(self.ids[id], self.callStatuses['ANSWER'],
                                   now)
Beispiel #5
0
    def onOutgoingCall(self, id, caller, callee):
        now = datetime.datetime.now()
        logger.msg("Invoked onOutgoingCall handler")

        query = "begin; \
                insert into calls ( dt_start, id_caller ) values( '%s', %s ); \
                select currval('calls_id_seq');" % (now, caller)
        self.db.runQuery(query).addCallback(
            self.addDictionaryEntry,
            id).addCallback(self.insertCallHistory,
                            self.callStatuses['OUTGOING'],
                            now).addErrback(self._queryFail)
Beispiel #6
0
    def onHangup( self, id, caller, callee ):
        now = datetime.datetime.now() 
        
        logger.msg( "Invoked onHangup handler" )
        
        if not self.ids.has_key( id ):
            logger.warn( "Something strange happened: hanged-up a non-received call." )
        else:
            # TODO: maybe it's better to do it with chain of deffereds?
            query = "select dt_start from calls where id = %i;" % ( self.ids[ id ] )
            self.db.runQuery( query ).addCallback( self.updateCallEntry, now, self.ids[ id ], callee ).addErrback( self._queryFail )
            self.insertCallHistory( self.ids[ id ], self.callStatuses[ 'HANG_UP' ], now )
            del self.ids[ id ]
	logger.msg( self.ids )
Beispiel #7
0
def on_msg_receive(msg):
    #if not syncFinished:
    #    print ("RET - 1")
    #    return;
    #pp.pprint(utils.msg2dict(msg))
    logger.msg(msg)
    if msg.dest.id == our_id: # direct message
        peer = msg.src
    else: # chatroom
        peer = msg.dest
    if msg.text is not None and msg.text.startswith("!ping"):
        peer.send_msg("PONG!")
    elif msg.text is not None and msg.text.startswith("!emoji"):
        peer.send_msg("Emojis: \n" + emoji.emojize(':white_check_mark: :smile: :laughing: :blush: :smiley: :x: :heavy_check_mark:', use_aliases=True).encode('UTF-8'))
    return
Beispiel #8
0
    def onHangup(self, id, caller, callee):
        now = datetime.datetime.now()

        logger.msg("Invoked onHangup handler")

        if not self.ids.has_key(id):
            logger.warn(
                "Something strange happened: hanged-up a non-received call.")
        else:
            # TODO: maybe it's better to do it with chain of deffereds?
            query = "select dt_start from calls where id = %i;" % (
                self.ids[id])
            self.db.runQuery(query).addCallback(
                self.updateCallEntry, now, self.ids[id],
                callee).addErrback(self._queryFail)
            self.insertCallHistory(self.ids[id], self.callStatuses['HANG_UP'],
                                   now)
            del self.ids[id]
        logger.msg(self.ids)
Beispiel #9
0
def receive_message(msg):
    if msg["date"] < time.time() - 2:
        return  # old
    logger.msg(msg)
    if msg["text"] == "/help" or msg["text"] == "/help@" + bot.getBotUsername():
        keyboard = {"keyboard": [["/help"], ["/quit"], ["/test keyboard"]]}
        bot.sendMessage(msg["chat"]["id"], "Commands: (in custom keyboard)", reply_markup=json.dumps(keyboard))
    if msg["text"] == "/quit" or msg["text"] == "/quit@" + bot.getBotUsername():
        if msg["from"]["id"] == 43804645:
            bot.sendMessage(msg["chat"]["id"], "Bye!")
            bot.quit = True
        else:
            bot.sendMessage(msg["chat"]["id"], "You don't have permission!")
    if msg["text"] == "/test keyboard":
        keyboard = {
            "keyboard": [
                ["1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣", "0⃣", "XD"],
                ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],
                ["/help", "/quit", "/test keyboard"],
            ]
        }
        bot.sendMessage(msg["chat"]["id"], "Sending custom keyboard!", reply_markup=json.dumps(keyboard))
Beispiel #10
0
def receive_location(msg):
    logger.msg(msg)
Beispiel #11
0
def new_chat_title(msg):
    logger.msg(msg)
Beispiel #12
0
def receive_video(msg):
    logger.msg(msg)
Beispiel #13
0
def receive_contact(msg):
    logger.msg(msg)
Beispiel #14
0
 def connectionLost( self, reason ):
     logger.msg( "Connection terminated" )
Beispiel #15
0
def receive_sticker(msg):
    logger.msg(msg)
Beispiel #16
0
def receive_audio(msg):
    logger.msg(msg)
Beispiel #17
0
def group_chat_created(msg):
    logger.msg(msg)
Beispiel #18
0
 def connectionMade( self ):
     logger.msg( "Received new connection" ) 
Beispiel #19
0
def left_chat_participant(msg):
    logger.msg(msg)
Beispiel #20
0
 def _querySuccess(self, result):
     # TODO: need something more useful here
     logger.msg("Query committed.")
Beispiel #21
0
 def connectionLost(self, reason):
     logger.msg("Connection terminated")
Beispiel #22
0
 def connectionMade(self):
     logger.msg("Received new connection")
Beispiel #23
0
def new_chat_photo(msg):
    logger.msg(msg)
Beispiel #24
0
def receive_document(msg):
    logger.msg(msg)
Beispiel #25
0
def delete_chat_photo(msg):
    logger.msg(msg)
Beispiel #26
0
def receive_photo(msg):
    logger.msg(msg)
Beispiel #27
0
def receive_message(msg):
    if msg["date"] < time.time() - 2:
        return # old
    logger.msg(msg)
    if msg["text"] == "/help" or msg["text"] == "/help@" + bot.getBotUsername():
        options = {"keyboard":[["/help"], ["/quit"], ["/test keyboard"], ["/mqm"]]}
        bot.sendMessage(msg["chat"]["id"], "Commands: (in custom keyboard)", reply_markup=json.dumps(options))

    elif msg["text"] == "/quit" or msg["text"] == "/quit@" + bot.getBotUsername():
        if msg["from"]["id"] == 43804645 or msg["from"]["id"] == 61615919:
            bot.sendMessage(msg["chat"]["id"], "Bye!")
            bot.quit = True
        else:
            bot.sendMessage(msg["chat"]["id"], "You don't have permission!")

    elif msg["text"] == "/test keyboard":
        keyboard = {"keyboard":[["1⃣","2⃣","3⃣","4⃣","5⃣","6⃣","7⃣","8⃣","9⃣","0⃣", "XD"],["q","w","e","r","t","y","u","i","o","p"],["/help", "/quit", "/test keyboard"]]}
        bot.sendMessage(msg["chat"]["id"], "Sending custom keyboard!", reply_markup=json.dumps(keyboard))

    elif msg["text"] == "/mqm":
        imgClasses = None
        for i in range(1,4500):
            request = requests.get('http://www.mequeme.com/page/'+str(i))
            tree = html.fromstring(request.content)
            imgClasses =tree.xpath("//div[@class='media']//img")
            if len(imgClasses) != 0:
                break
        imgClass = imgClasses[0]
        # Debug print (html.etree.tostring(imgClass, pretty_print=True))
        imgURL = imgClass.attrib['src']
        # Not the best way to do this but...
        caption = imgClass.attrib['alt']

        print(caption)
        response = requests.get(imgURL)
        f = open("sample.gif", 'wb')
        f.write(response.content)
        f.close()
        img = open('sample.gif', 'rb')
        bot.sendChatAction(msg["chat"]["id"], 'upload_photo')
        bot.sendImage(msg["chat"]["id"], img, caption=caption)
        img.close()
        os.remove('sample.gif')

    elif msg["text"] == "/mqm random":
        imgClasses=None
        while True:
            rand = random.randint(0,4500)
            request = requests.get('http://www.mequeme.com/page/'+str(rand))
            tree = html.fromstring(request.content)
            imgClasses =tree.xpath("//div[@class='media']//img")
            if len(imgClasses) != 0:
                break
        imgClass=imgClasses[random.randint(0,len(imgClasses)-1)]
        # Debug print (html.etree.tostring(imgClass, pretty_print=True))
        imgURL = imgClass.attrib['src']
        # Not the best way to do this but...
        caption = imgClass.attrib['alt']

        print(caption)
        response = requests.get(imgURL)
        f = open("sample.gif", 'wb')
        f.write(response.content)
        f.close()
        img = open('sample.gif', 'rb')
        bot.sendChatAction(msg["chat"]["id"], 'upload_photo')
        bot.sendImage(msg["chat"]["id"], img, caption=caption)
        img.close()
        os.remove('sample.gif')
Beispiel #28
0
 def _querySuccess( self, result ):
     # TODO: need something more useful here
     logger.msg( "Query committed." )