-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (45 loc) · 1.72 KB
/
main.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
from google.cloud import storage
from telegram.ext import Dispatcher, CommandHandler, Filters, MessageHandler
from telegram import Update, Bot
import random
from time import sleep
import os
BUCKET_NAME = 'rojaodasicont'
FILE_NAME = 'cont.txt'
storage_client = storage.Client()
bucket = storage_client.bucket(BUCKET_NAME)
def get_count():
blob = bucket.get_blob(FILE_NAME)
if blob:
return int(blob.download_as_text())
else:
return 0
def save_count(count):
blob = bucket.blob(FILE_NAME)
blob.upload_from_string(str(count))
count = get_count()
def start(bot, update):
update.message.reply_text("Opa, sou o bot q vai causar absoluto terror no grupo do Dasi com um belo rojão roxo", quote=False)
def acende(bot, update):
global count
count += 1
save_count(count)
update.message.reply_text("pra", quote=False)
update.message.reply_text("pra pra", quote=False)
update.message.reply_text("pra pra pra", quote=False)
update.message.reply_text("pow", quote=False)
update.message.reply_text("pow pow", quote=False)
update.message.reply_text("POW POW POW", quote=False)
def contagem(bot, update):
global count
update.message.reply_text(f"O DASI Já usou o Rojão DASIANO {count} vezes")
def webhook(request):
bot = Bot(token=os.environ["TELEGRAM_TOKEN"])
dispatcher = Dispatcher(bot, None, 0)
dispatcher.add_handler(CommandHandler('start', start))
dispatcher.add_handler(CommandHandler('acende', acende))
dispatcher.add_handler(CommandHandler('contagem', contagem))
if request.method == 'POST':
update = Update.de_json(request.get_json(force=True), bot)
dispatcher.process_update(update)
return 'ok'