-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_bot.py
More file actions
156 lines (127 loc) · 6.14 KB
/
main_bot.py
File metadata and controls
156 lines (127 loc) · 6.14 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import requests
import telepot
from sys import argv
from time import sleep
from telepot.loop import MessageLoop
from bot_decorators import check
from greetings import greetings
from handle import command, main
from punishment import punish
token = argv[1]
@check
def control(msg):
#try:
main_inst = main(bot, msg)
command_inst = command(bot, msg)
greetings_inst = greetings(bot,msg)
punish_inst = punish(bot, msg)
if msg.get('data') and not(msg.get('permission') == False):
text = ''
ctext = ''
if msg['data'].isdigit():
punish_inst.unwarn(data=main_inst.query_data)
elif isinstance(msg['data'], str) and not(msg['data'] in ('agree', 'disagree')):
punish_inst.banvote(msg=msg)
if msg.get('text'):
text = msg['text'].split(' ')
ctext = text[0].lower()
else:
ctext = ''
if not (main_inst.chat_type == 'private'):
admin_commands = {
'/ban': punish_inst.ban,
'/unban': punish_inst.unban,
'/warn': punish_inst.warn,
'/unwarn': punish_inst.unwarn,
'/blacklist': command_inst.blacklist,
'/afklist': command_inst.afklist,
'/clear': command_inst.clearlists,
'/promote': command_inst.promote_demote,
'/demote': command_inst.promote_demote,
'/pin': command_inst.pin,
'/unpin': command_inst.unpin,
'/uptime': command_inst.uptime,
'/voteban': punish_inst.banvote,
'/test': command_inst.kitploit_articles
}
user_command = {
'/afk': command_inst.afk,
'/back': command_inst.back,
'/rules': command_inst.rules,
'/admins': command_inst.admins,
'/help': command_inst.help
}
if msg.get('new_chat_participant'):
greetings_inst.welcome()
main_inst.dbexec.insert_if_not_exists(
first_name=msg['new_chat_member']['first_name'],
user_id=msg['new_chat_member']['id'],
username = msg['new_chat_member']['username']
)
main_inst.dbexec.sql_update(
'ban','DEFAULT',
msg['new_chat_member']['id'],
msg['new_chat_member']['first_name']
)
elif user_command.get(ctext):
user_command[ctext]()
elif admin_commands.get(ctext):
if ctext.startswith('/warn'):
admin_commands[ctext](text)
elif ctext.startswith('/afklist', 0, 8):
admin_commands[ctext]()
elif ctext.startswith('/voteban'):
if len(text) == 4:
if text[1].startswith('@') and text[2].isdigit() and text[3].isdigit():
punish_inst.banvote(username=text[1], temp=text[2], tvotation=text[3])
else:
bot.sendMessage(chat_id=main_inst.chat_id,parse_mode='Markdown', text='*Invalid Command.*\n*Command:* `/voteban [@username] [TimeBan] [TimeVotation]`')
elif ctext.startswith('/demote'):
admin_commands[ctext](admin=False)
else:
admin_commands[ctext]()
elif ctext.startswith('rt',0,2):
if msg.get('reply_to_message', False):
if (text[0].lower() == 'rt' and len(text) == 1) or (text[0].lower() == 'rtzao' and len(text) == 1):
command_inst.rt()
else:
text = msg['text'].lower()
if ('rt' == text[0:2]) and (len(text[2:]) == 0) or ('rtzao' == text[0:2]) and (len(text[5:]) == 0):
text = text.strip('rt')
command_inst.rt(text)
elif 'rtzao' == text[0:5]:
text = text.strip('rtzao')
command_inst.rt(text)
elif 'rt' == text[0:2]:
text = text.strip('rtzao')
command_inst.rt(text)
elif msg.get('back'):
bot.sendMessage(main_inst.chat_id, msg['back'])
elif msg.get('ban'):
bot.kickChatMember(main_inst.chat_id, msg['ban']['userid'])
bot.sendMessage(
main_inst.chat_id,
parse_mode='HTML',
text='<a href="https://telegram.me/{0}/">{1}</a> <b>has been banned for flood</b>'.format(
msg['ban']['username'],
msg['ban']['first_name']),
disable_web_page_preview=True,
reply_to_message_id=msg['ban']['msgid'][0])
for id in msg['ban']['msgid']:
requests.post(
'https://api.telegram.org/bot428427082:AAHdv4elQ5XBKMmJMRqlqtKh4rgisIhhCgk/deleteMessage?chat_id={0}&message_id={1}'.format(main_inst.chat_id, id))
main_inst.dbexec.sql_update('ban',1)
elif msg.get('vote_msg') or msg.get('vote_query') or msg.get('vote_closed'):
punish_inst.banvote(msg=msg)
elif msg.get('permission'):
main_inst.get_admin_list(query=True)
elif msg.get('article'):
command_inst.kitploit_articles()
#except:
# pass
bot = telepot.Bot(token)
if __name__ == '__main__':
print('Listening...')
MessageLoop(bot, control).run_as_thread()
while 1:
sleep(100)