Example #1
0
File: core.py Project: tdf/tmb
def botloop(bot):
    while True:
        try:
            updates = bot.getUpdates(offset=int(config["global"]["update_id"]) + 1, timeout=10)
        except TelegramError as e:
            if "Timed out" in str(e):
                continue
        if len(updates):
            config["global"]["update_id"] = str(updates[-1].update_id)
            writeconfig()
        for update in updates:
            parseUpdate(update, bot)
        yield from asyncio.sleep(5)
        if tmb.called_from_test:
            break
Example #2
0
File: core.py Project: tdf/tmb
 def parseMessage(self, message):
     if message.startswith("/"):
         return self.parseCommand(message[1:])
     elif self.state == "register":
         if message == self.password:
             config["registered"][str(self.chatid)] = "True"
             writeconfig()
             self.msg("You are now registered.")
             self.state = "start"
         else:
             self.msg("This is unfortunately wrong. Please try again.")
     elif self.state == "unregister":
         if message == "confirm":
             if str(self.chatid) in config["registered"]:
                 config.remove_option("registered", str(self.chatid))
                 writeconfig()
                 self.msg("You are now unsubscribed.")
                 self.state = "start"
             else:
                 self.msg("You are not registered.")
                 self.state = "start"
Example #3
0
def test_writeconfig():
	from tmb.config import writeconfig
	writeconfig()