-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbot.py
More file actions
executable file
·252 lines (218 loc) · 9.34 KB
/
bot.py
File metadata and controls
executable file
·252 lines (218 loc) · 9.34 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
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
import os, time
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from telegram import Chat
from requests import post, get, delete
import logging
import random as r
import time
from math import sqrt, gcd, log
from itertools import count, islice
api_location = 'https://api-bigodera.herokuapp.com/'
# function to handle the /start command
def start(update, context):
chat_id = update.message.chat_id
text = "Bigodera acordado! Agora você já pode utilizar alguns de meus comando. Veja uma lista dos comandos digitando /help"
update.message.reply_text(text)
# function to handle the /help command
def help(update, context):
text = (
"Tenho as seguintes funcionalidades\n"
+ "/start - Me acorda caso esteja dormindo\n"
+ "/on - Verifica se eu estou acordado\n"
+ "/meme - Frases icônicas de pessoas mais ainda\n"
+ "/add_meme meme - Adicionar um meme\n"
+ "/linkar_cf handle - Liga o handle à sua conta do Telegram\n"
+ "/deslinkar_cf - Desvincula seu handle do codeforces da sua conta do Telegram\n"
+ "/probleminha rating [tags] - Escolhe um problema aleatório do codeforces para seu handle cadastrado\n"
+ "/roll n t - Rola n dados de t faces\n"
+ "/even_odd - O famoso par ou impar\n"
+ "/primo n - Verifica se n é primo\n"
+ "/calculadora a op b - Faz o calculo, +,-,*,**,%,^ ex: 1 + 1\n"
+ "/contador_caga_pau - É tanta cagada de pau que nem dá pra contar\n"
+ "/incrementa_contador_caga_pau - Alguém cagou no pau '-'\n"
+ "/fatorar n1 [n2 n3 ... n10] - Realiza a fatoração (máximo de 10 números por comando)"
# + "/mute - Apenas admins, muta o Machado\n"
# + "/unmute - Deixa o garoto falar merda vai..."
)
update.message.reply_text(text)
def on(update, context):
update.message.reply_text("To de pé rs")
def greet(update, context):
global api_location
for new_user_obj in update.message.new_chat_members:
text = get(api_location+'greet/'+new_user_obj.split()[0]).json()['1']
update.message.reply_text(text)
def noncommand(update, context):
text = (update.message.text).lower()
ret = ""
if "caga pau" in text:
ret = "FELIPE WEISS"
elif "felipe weiss" in text:
ret = "caga pau"
elif "sei la" in text:
ret = "treze"
elif "porra" in text and "caralho" in text:
ret = "Ambiente Familiar"
elif "bigod" in text and text[-1] == "?":
ret = "sim"
elif "gasp" in text and text[-1] == ".":
ret = "cara é bom!"
elif "cara" == text.split()[0]:
carinhas = ["'-'", "'.'", "XD", "u.u", "@.@", ".-.", ":c"]
ret = r.choice(carinhas)
elif "bom dia" in text and text[-1] == "!":
ret = "O sol nasceu na puta que pariu do horizonte, para iluminar a porra dos seus sonhos, bom dia filha da putaaa"
elif "boa noite" in text:
ret = "Já vai tarde..."
elif "melhor da vida" in text:
quotes = [
"pao de alho",
"acordar cedo e lembrar que é sábado",
"mijar apertado",
"borda recheada de brinde",
"quando chega o que vc comprou pela internet",
"frete grátis",
"achar dinheiro no bolso",
"wifi grátis",
"final da nacional",
]
ret = r.choice(quotes)
if ret:
update.message.reply_text(ret)
def meme(update, context):
global api_location
api_data = get(api_location+'meme')
text = api_data.json()['1']
update.message.reply_text(text)
def add_meme(update, context):
global api_location
new_meme = ' '.join(update.message.text.split(' ')[1:])
text = post(api_location+'add_meme', json={'new_meme': new_meme}).json()['1']
update.message.reply_text(text)
def birthday(update, context):
global api_location
name = update.message.text.split()[1]
text = get(api_location+'birthday/'+name).json()['1']
update.message.reply_text(text)
# function to handle errors occured in the dispatcher
def user(update, context):
global api_location
user_id = update.message.from_user.id
handle = ' '.join(update.message.text.split(' ')[1:])
text = post(api_location+'user', json = {'handle': handle, 'id_telegram': int(user_id)}).json()['1']
update.message.reply_text(text)
def del_user(update, context):
global api_location
user_id = update.message.from_user.id
text = delete(api_location+'del_user', json = {'id_telegram': int(user_id)}).json()['1']
update.message.reply_text(text)
def cf_problem(update, context):
global api_location
user_id = update.message.from_user.id
split_message = update.message.text.split(' ')
if (len(split_message) == 1):
text = post(api_location+'cfproblem', json={'id_telegram': int(user_id)}).json()['1']
update.message.reply_text(text)
else:
rating = split_message[1]
tags = ''
if (len(split_message) > 2):
tags = ' '.join(split_message[2:])
text = post(api_location+'cfproblem', json={'id_telegram': int(user_id), 'rating': int(rating), 'tags': tags}).json()['1']
update.message.reply_text(text)
def contador_caga_pau(update, context):
global api_location
text = get(api_location+'contador_caga_pau').json()['1']
update.message.reply_text(text)
def inc_contador_caga_pau(update, context):
global api_location
text = get(api_location+'contador_caga_pau++').json()['1']
update.message.reply_text(text)
def roll(update, context):
global api_location
args = update.message.text.split(' ')[1:]
dados = args[0]
lados = args[1]
results = post(api_location+'roll', json={'dados': dados, 'lados': lados}).json()
text = ''
if (results == {'1' : 'Vsf! Porrada de Dado.'}):
update.message.reply_text('Vsf! Porrada de Dado.')
return
for dado in results:
text += str(dado) + ': ' + str(results[dado]) + '\n'
update.message.reply_text(text[:len(text)-1])
def even_odd(update, context):
global api_location
text = get(api_location+'even_odd').json()['1']
update.message.reply_text(text)
def primo(update, context):
global api_location
numbers = ' '.join(update.message.text.split(' ')[1:])
results = post(api_location+'primo', json={'numbers': numbers}).json()
text = ''
for line in results:
text += results[line]+'\n'
update.message.reply_text(text[:len(text)-1])
def fatorar(update, context):
global api_location
numbers = ' '.join(update.message.text.split(' ')[1:])
# print(numbers)
results = post(api_location+'fatorar', json={'numbers': numbers}).json()
text = ''
for number in results:
text += str(number) + ': ' + results[number] + '\n'
update.message.reply_text(text[:len(text)-1])
def calculadora(update, context):
global api_location
split_message = update.message.text.split(' ')
# print(split_message)
try:
number1 = split_message[1]
operation = split_message[2]
number2 = split_message[3]
text = post(api_location+'calculadora', json={'number1': float(number1), 'number2': float(number2), 'operation': operation}).json()['1']
update.message.reply_text(text)
except:
update.message.reply_text('Um erro ocorreu')
def error(update, context):
update.message.reply_text('Update "%s" caused error "%s"', update, error)
# function to handle normal text
# def text(update, context):
# text_received = update.message.text
# update.message.reply_text(f'did you said "{text_received}" ?')
def main():
# tfile = open('bot_token', 'r')
TOKEN = os.environ["TELEGRAM_TOKEN"]
# create the updater, that will automatically create also a dispatcher and a queue to
# make them dialoge
updater = Updater(TOKEN, use_context=True)
dispatcher = updater.dispatcher
# add handlers for start and help commands
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CommandHandler("help", help))
dispatcher.add_handler(CommandHandler("meme", meme))
dispatcher.add_handler(CommandHandler("add_meme", add_meme))
dispatcher.add_handler(CommandHandler("on", on))
dispatcher.add_handler(CommandHandler("greet", greet))
dispatcher.add_handler(CommandHandler("feliz_aniversario",birthday))
dispatcher.add_handler(CommandHandler("linkar_cf",user))
dispatcher.add_handler(CommandHandler("deslinkar_cf",del_user))
dispatcher.add_handler(CommandHandler("probleminha",cf_problem))
dispatcher.add_handler(CommandHandler("contador_caga_pau",contador_caga_pau))
dispatcher.add_handler(CommandHandler("incrementa_contador_caga_pau",inc_contador_caga_pau))
dispatcher.add_handler(CommandHandler("roll",roll))
dispatcher.add_handler(CommandHandler("even_odd",even_odd))
dispatcher.add_handler(CommandHandler("primo",primo))
dispatcher.add_handler(CommandHandler("fatorar",fatorar))
dispatcher.add_handler(CommandHandler("calculadora",calculadora))
# dispatcher.add_handler(MessageHandler(Filters.text, text))
# add an handler for normal text (not commands)
dispatcher.add_handler(MessageHandler(Filters.text, noncommand))
# add an handler for errors
dispatcher.add_error_handler(error)
# start your shiny new bot
updater.start_polling()
# run the bot until Ctrl-C
updater.idle()
if __name__ == '__main__':
main()