-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
287 lines (225 loc) · 11.6 KB
/
bot.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# -*- coding: utf-8 -*-
import firebaseconfig, image, video, games
import urllib
import urllib.parse
import requests
import time
from datetime import datetime
import os
limitecitadas = 0
users = []
replyed = []
start_time = 0
trigger = os.environ.get('trigger_1')
trigger2 = os.environ.get('trigger_2')
access_token = os.environ.get('Token')
try:
messagetext = os.environ.get('message')
except:
messagetext = 'did you call me?'
def replyimg(cmm, topic, user, comment, message):
global users, limitecitadas
users.append(user)
if limitecitadas > 5:
print('limite atingido')
return
# Put the words you want the bot to ignore here
blacklist = ['piroca', 'penis', 'anal', 'prolapso anal', 'sexo', 'shemale', 'traveco', 'travesti', 'pênis',
'melhor do mundo', 'rola', 'tripofobia', 'calcanhar de maracujá', 'calcanhar de maracuja',
'bilola', 'calcanhar maracuja', 'calcanhar', 'calcanar', 'maracuja', 'maracuja', 'bilola', 'pauzao',
'cintaralho', 'pau', 'genital', 'fuck', 'selfsuck', 'suck', 'cruzando', 'naked', 'cuceta', 'gangbang',
'two girls one cup', '2 girls 1 cup', 'nipple', 'gay', 'xere']
query = message.split('!img')[1].strip()
# query = unidecode.unidecode(query).lower()
for word in blacklist:
if word in query:
return
request = requests.get('https://api.vk.com/method/users.get?user_ids={}&access_token={}&v=5.52'.format(user, access_token))
name = request.json()['response'][0]['first_name']
print('cheguei aqui')
print(query)
try:
attachment = 'photo{}_{}'.format(os.environ.get('user_id'), image.uploadImage(image.getPicture(query)))
except Exception as e:
print('attachment error')
print(e)
return
message = '[post{}|{}], here is your image'.format(comment, name)
url = 'https://api.vk.com/method/board.createComment?group_id={}&topic_id={}&message={}&attachments={}&access_token={}&v=5.52'.format(str(cmm).split('-')[1], topic, str(message), attachment, access_token)
requests.get(url)
limitecitadas += 1
def replyComandos(cmm, topic, user, comment):
global users
users.append(user)
request = requests.get(
'https://api.vk.com/method/users.get?user_ids={}&access_token={}&v=5.52'.format(user, access_token))
name = request.json()['response'][0]['first_name']
comandos = 'take a look at my profile'
comandos = urllib.parse.quote(comandos)
message = '[post{}|{}], {}'.format(comment, name, comandos)
url = 'https://api.vk.com/method/board.createComment?group_id={}&topic_id={}&message={}&access_token={}&v=5.52'.format(
str(cmm).split('-')[1], topic, str(message), access_token)
requests.get(url)
def replyJogos(cmm, topic, user, comment, serie):
global users
serie = serie.upper()
users.append(user)
request = requests.get(
'https://api.vk.com/method/users.get?user_ids={}&access_token={}&v=5.52'.format(user, access_token))
name = request.json()['response'][0]['first_name']
jogos = games.getLiveScore(serie)
if len(jogos) == 0:
message = '[post{}|{}], there is no Brazilian Serie {} games today :('.format(comment, name, serie)
url = 'https://api.vk.com/method/board.createComment?group_id={}&topic_id={}&message={}&access_token={}&v=5.52'.format(
str(cmm).split('-')[1], topic, str(message), access_token)
requests.get(url)
return
textofinal = ''
for jogo in jogos:
textofinal += jogo['condition'] + ' - ' + jogo['horario'] + ' - ' + jogo['estado'] + '\n'
jogosdehoje = urllib.parse.quote(textofinal)
message = '[post{}|{}], these are the today games: \n {}'.format(comment, name, jogosdehoje)
url = 'https://api.vk.com/method/board.createComment?group_id={}&topic_id={}&message={}&access_token={}&v=5.52'.format(str(cmm).split('-')[1], topic, message, access_token)
requests.get(url)
def replyVideo(cmm, topic, user, comment, linkmessage):
request = requests.get('https://api.vk.com/method/users.get?user_ids={}&access_token={}&v=5.52'.format(user, access_token))
name = request.json()['response'][0]['first_name'].encode('utf-8')
if 'youtube' in linkmessage:
id = linkmessage.split('https://www.youtube.com/watch?v=')[1]
videolink = 'https://www.youtube.com/watch?v=' + id
link = video.getYoutubeUrl(videolink)
message = '[post{}|{}], try this: \n{}'.format(comment, name, link)
url = 'https://api.vk.com/method/board.createComment?group_id={}&topic_id={}&message={}&access_token={}&v=5.52'.format(str(cmm).split('-')[1], topic, str(message), access_token)
requests.get(url)
return
id = linkmessage.split('https://vk.com/video')[1]
linkslist = video.downloadVideo(video.getVideo(id))
message = '[post{}|{}], try this: \n{}'.format(comment, name, linkslist)
url = 'https://api.vk.com/method/board.createComment?group_id={}&topic_id={}&message={}&access_token={}&v=5.52'.format(str(cmm).split('-')[1], topic, str(message), access_token)
requests.get(url)
def remindMe():
schedule = firebaseconfig.getSchedule()
if schedule == None:
return
for reminder in schedule.each():
event = reminder.val()
print(event)
currentTime = int(time.mktime(datetime.now().timetuple()))
if int(event['Time']) < currentTime:
reply(event['Community'], event['Topic'], event['User'], event['Comment'])
firebaseconfig.removeFromSchedule(reminder.key())
def getNotifications():
global replyed
global users
bannedlist = firebaseconfig.getBanned()
# Put an user id here to mannualy ban him. Any user with his id on this array will be ignored by the bot
banned = []
if bannedlist != None:
for userbanned in bannedlist:
banned.append(userbanned)
request = requests.get('https://api.vk.com/method/notifications.get?filters=mentions&count=5&start_time={}&access_token={}&v=5.52'.format(start_time, access_token))
notifications = request.json()['response']['items']
for notification in notifications:
if str(notification['type']) == 'reply_topic':
cmm = notification['parent']['owner_id']
topic = notification['parent']['id']
user = notification['feedback']['from_id']
comment = notification['feedback']['id']
title = notification['parent']['title']
message = notification['feedback']['text']
date = int(time.mktime(datetime.now().timetuple()))
if str(user) in banned:
continue
if comment not in replyed and (trigger in str(message) or trigger2 in str(message)):
replyed.append(comment)
try:
if '!remind' in str(message):
if trigger in message:
remindertime = message.split(trigger + ' !remind')[1].split(' ')[1]
remindermagnitude = message.split(trigger + ' !remind')[1].split(' ')[2]
elif trigger2 in message:
remindertime = message.split(trigger2 + ' !remind')[1].split(' ')[1]
remindermagnitude = message.split(trigger2 + ' !remind')[1].split(' ')[2]
if (str(remindermagnitude) == 'hours') or (str(remindermagnitude) == 'hour'):
if int(remindertime) <= 365 * 24:
firebaseconfig.writeToFirebase(cmm, topic, user, comment, (date + int(remindertime) * 3600))
elif (str(remindermagnitude) == 'minutes') or (str(remindermagnitude) == 'minute'):
if int(remindertime) <= 365 * 24 * 60:
firebaseconfig.writeToFirebase(cmm, topic, user, comment, (date + int(remindertime) * 60))
elif (str(remindermagnitude) == 'days') or (str(remindermagnitude) == 'day'):
if int(remindertime) <= 365:
firebaseconfig.writeToFirebase(cmm, topic, user, comment,(int(date) + int(remindertime) * 3600 * 24))
elif '!img' in str(message):
replyimg(cmm, topic, user, comment, message)
elif '!tag' in str(message):
reply(cmm, topic, user, comment, message, True)
elif '!download' in str(message):
# This can take too much time and make the bot lose some notifications, consider running it on a separate environment
replyVideo(cmm, topic, user, comment, message)
elif '!gamessd' in str(message):
replyJogos(cmm, topic, user, comment, 'D')
elif '!gamesc' in str(message):
replyJogos(cmm, topic, user, comment, 'C')
elif '!gamesb' in str(message):
replyJogos(cmm, topic, user, comment, 'B')
elif '!games' in str(message):
replyJogos(cmm, topic, user, comment, 'A')
elif '!comandos' in str(message):
replyComandos(cmm, topic, user, comment)
elif '!' in str(message):
return
else:
reply(cmm, topic, user, comment)
except Exception as e:
print(e)
pass
def reply(cmm, topic, user, comment, commenttext='', tag=False):
global users, messagetext
users.append(user)
request = requests.get(
'https://api.vk.com/method/users.get?user_ids={}&access_token={}&v=5.52'.format(user, access_token))
name = request.json()['response'][0]['first_name']
if tag == False:
message = '[post{}|{}], {}'.format(comment, name, messagetext)
else:
tag = commenttext.split('!tag')[1].strip()
message = '[post{}|{}], {}'.format(comment, name, tag)
url = 'https://api.vk.com/method/board.createComment?group_id={}&topic_id={}&message={}&access_token={}&v=5.52'.format(
str(cmm).split('-')[1], topic, str(message), access_token)
requests.get(url)
def acceptInvites():
request = requests.get('https://api.vk.com/method/groups.getInvites?count=100&offset=0&access_token={}&v=5.52'.format(access_token))
invites = request.json()['response']['items']
for invite in invites:
if invite['type'] == 'group':
id = invite['id']
requests.get(
'https://api.vk.com/method/groups.join?group_id={}&access_token={}&v=5.52'.format(id, access_token))
def run():
try:
global replyed
global start_time
global limitecitadas
global users
start_time = int(time.mktime(datetime.now().timetuple()) - 2)
while True:
time.sleep(1)
getNotifications()
minutes = int(datetime.now().minute)
seconds = float(datetime.now().second)
if minutes in [0, 10, 20, 30, 40, 50] and float(seconds) < 2:
for user in list(set(users)):
if users.count(user) > 6:
firebaseconfig.writeToFirebaseBanned(user)
limitecitadas = 0
users = []
if float(seconds) < 2:
remindMe()
if minutes == 0 and float(seconds) < 2 or minutes == 30 and float(seconds) < 2:
acceptInvites()
if len(replyed) > 10:
replyed = replyed[-10:]
except Exception as e:
print(e)
time.sleep(2)
run()