123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #Библиотеки
- import xmpp
- from config import jid, jidpassword
- from BotClass import JabberBot
- from RequestClass import RequestDataBase
- requesDB = RequestDataBase()
- #Основной метод для обработки сообщинй от пользователя
- def message_handler(conn, mess):
- text = mess.getBody()
- user = mess.getFrom()
- if str(text).startswith("!"):
- commands_request(conn, mess)
- else:
- conn.send(xmpp.Message(user, "Я тебя не понимаю..."))
- def commands_request(conn, mess):
- try:
- text = mess.getBody()
- user = mess.getFrom()
- arguments = str(text).split()
- if text == "!addcl":
- conn.send(xmpp.Message(user, requesDB.add_car_log(arguments[0])))
- elif text == "!delcl":
- conn.send(xmpp.Message(user, requesDB.del_car_log(int(arguments[0]))))
- elif text == '!ссt':
- conn.send(xmpp.Message(user, requesDB.change_current_token(arguments[0], arguments[1])))
- elif text == '!addol':
- conn.send(xmpp.Message(user, requesDB.add_order_log()))
- elif text == '!delol':
- conn.send(xmpp.Message(user, requesDB.del_order_log(arguments[0])))
- elif text == '!addc':
- conn.send(xmpp.Message(user, requesDB.add_car(arguments[0])))
- elif text == '!cc':
- conn.send(xmpp.Message(user, requesDB.change_car(arguments[0])))
- elif text == '!gup':
- conn.send(xmpp.Message(user, requesDB.get_upcoming_orders(arguments[0])))
- elif text == '!ac':
- conn.send(xmpp.Message(user, requesDB.actuality_check(arguments[0])))
- elif text == '!ico':
- conn.send(xmpp.Message(user, requesDB.insert_current_order(arguments[0])))
- elif text == '!dco':
- conn.send(xmpp.Message(user, requesDB.del_current_order(arguments[0])))
- elif text == '!uco':
- conn.send(xmpp.Message(user, requesDB.update_current_order(arguments[0])))
- elif text == '!cs':
- conn.send(xmpp.Message(user, requesDB.change_status(arguments[0])))
- else:
- conn.send(xmpp.Message(user, "Такой команды нет"))
- except Exception as ex:
- conn.send(xmpp.Message(user, str(ex)))
-
- #Авторизация и запуск бота
- bot = JabberBot(jid, jidpassword)
- bot.register_handler('message', message_handler)
- bot.start()
|