mirror of
https://github.com/house-of-vanity/fesmoo_perdoliq.git
synced 2025-08-21 16:17:15 +00:00
Multithreading message handling.
This commit is contained in:
26
baraban.py
26
baraban.py
@@ -7,10 +7,15 @@ This program is dedicated to the public domain under the CC0 license.
|
||||
"""
|
||||
import os
|
||||
import logging
|
||||
import threading
|
||||
import telegram
|
||||
from telegram.error import NetworkError, Unauthorized
|
||||
from time import sleep
|
||||
import tg_settings
|
||||
try:
|
||||
import tg_settings
|
||||
except:
|
||||
print("You have to create tg_settings.py. See tg_settings.py.example.")
|
||||
os.exit(1)
|
||||
try:
|
||||
if os.environ["DRYRUN"]:
|
||||
from dryrun import Perdoliq
|
||||
@@ -38,7 +43,7 @@ def main():
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
while True:
|
||||
try:
|
||||
echo(bot)
|
||||
handle_update(bot)
|
||||
except NetworkError:
|
||||
sleep(1)
|
||||
except Unauthorized:
|
||||
@@ -64,7 +69,7 @@ def list_test(username, password):
|
||||
return "Exception: " + str(e)
|
||||
|
||||
|
||||
def echo(bot):
|
||||
def handle_update(bot):
|
||||
"""Echo the message the user sent."""
|
||||
global update_id
|
||||
# Request updates after the last update_id
|
||||
@@ -72,17 +77,16 @@ def echo(bot):
|
||||
update_id = update.update_id + 1
|
||||
|
||||
if update.message:
|
||||
# if there is and update, process it in threads
|
||||
t = threading.Thread(target=do_action, args=(update,))
|
||||
t.start()
|
||||
|
||||
def do_action(update):
|
||||
try:
|
||||
s = update.message.text.split()
|
||||
except:
|
||||
s = "empty"
|
||||
return 1
|
||||
if s[0] == '/resolve':
|
||||
#msg = "usr: " + \
|
||||
# s[1] + " pass: " + \
|
||||
# s[2] + " subj: " + \
|
||||
# s[3] + " test: " + \
|
||||
# s[4] + " accuracy: " + \
|
||||
# s[5] + " commit: " + s[6]
|
||||
if len(s) != 7:
|
||||
update.message.reply_markdown("Missing operand... Try again")
|
||||
update.message.reply_markdown("Usage: */resolve <user[text]> "\
|
||||
@@ -106,6 +110,7 @@ def echo(bot):
|
||||
try:
|
||||
if len(s) == 3:
|
||||
update.message.reply_text("Fetching tests...")
|
||||
sleep(5)
|
||||
tests = list_test(s[1], s[2])
|
||||
else:
|
||||
update.message.reply_markdown("Usage: */list <user[text]>"\
|
||||
@@ -137,3 +142,4 @@ def echo(bot):
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
Reference in New Issue
Block a user