-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUnipdBot.py
79 lines (66 loc) · 2.14 KB
/
UnipdBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/python
# -*- coding: utf-8 -*-
import telegram
from pyUniPd import pyUniPd
import ConfigParser
from time import sleep
config = ConfigParser.ConfigParser()
config.read('settings.ini')
token = config.get('main', 'token')
admin = str(config.get('main', 'admin'))
LAST_UPDATE_ID = None
uni = pyUniPd()
def main():
global LAST_UPDATE_ID
bot = telegram.Bot(token)
try:
LAST_UPDATE_ID = bot.getUpdates()[-1].update_id
except IndexError:
LAST_UPDATE_ID = None
while True:
unipd(bot)
def unipd(bot):
global LAST_UPDATE_ID
for update in bot.getUpdates(offset=LAST_UPDATE_ID, timeout=10):
chat_id = update.message.chat_id
message = update.message.text.encode("utf-8")
pos = update.message.location
usrChat = str(update.message.chat_id)
if usrChat == admin:
isAdmin = True
else:
isAdmin = False
if '/stats' in message.lower():
is_Stats = True
else:
is_Stats = False
if isAdmin and is_Stats:
uni.adminStats(bot, update, message, '/stats', chat_id)
LAST_UPDATE_ID = update.update_id + 1
elif is_Stats and not isAdmin:
reply = "Non sei il mio creatore! Tradimento! " \
"Aiuto! Hahhahaha ciao :)"
bot.sendMessage(chat_id=chat_id, text=reply)
LAST_UPDATE_ID = update.update_id + 1
else:
pass
commands = pyUniPd.commandlist('db/commandsDB.db')
if pos is not None:
uni.sendNearPOI(bot, chat_id, pos)
LAST_UPDATE_ID = update.update_id + 1
else:
pass
for c in range(len(commands)):
if commands[c].lower() in message.lower():
uni.reply(bot, update, message,
commands[c], chat_id)
LAST_UPDATE_ID = update.update_id + 1
while True:
if __name__ == "__main__":
try:
main()
except:
txt = 'Some error happened. Check me!'
bot = telegram.Bot(token)
bot.sendMessage(chat_id=admin, text=txt)
sleep(5)