forked from JosXa/BotListBot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmisc.py
More file actions
64 lines (52 loc) · 2.08 KB
/
Copy pathmisc.py
File metadata and controls
64 lines (52 loc) · 2.08 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
import binascii
import datetime
import os
from telegram import ParseMode
from telegram.ext import ConversationHandler
import util
from models import Statistic, APIAccess
from models import User, Bot, Notifications
from util import restricted
@restricted(strict=True)
def access_token(bot, update):
user = User.from_telegram_object(update.effective_user)
rd_token = binascii.hexlify(os.urandom(32)).decode('utf-8')
try:
db_token = APIAccess.get(user=user).token
except:
db_token = "You have no token."
text = "Random token: {}\n" \
"Database token (use this for api calls):\n{}".format(rd_token, db_token)
update.message.reply_text(text)
return ConversationHandler.END
def credits(bot, update):
users_contrib = User.select().join(Bot)
pass
Bot.select(Bot.submitted_by)
return ConversationHandler.END
def t3chnostats(bot, update):
days = 30
txt = 'Bots approved by other people *in the last {} days*:\n\n'.format(days)
bots = Bot.select().where(
(Bot.approved_by != User.get(User.chat_id == 918962)) &
(Bot.date_added.between(
datetime.date.today() - datetime.timedelta(days=days),
datetime.date.today()
))
)
txt += '\n'.join(['{} by @{}'.format(str(b), b.approved_by.username) for b in bots])
update.message.reply_text(txt, parse_mode=ParseMode.MARKDOWN)
def set_notifications(bot, update, value: bool):
cid = update.effective_chat.id
try:
notifications = Notifications.get(Notifications.chat_id == cid)
except Notifications.DoesNotExist:
notifications = Notifications(chat_id=cid)
notifications.enabled = value
notifications.save()
Statistic.of(update, ('enabled' if value else 'disabled') + ' notifications for their group {}'.format(
cid))
msg = util.success("Nice! Notifications enabled.") if value else "Ok, notifications disabled."
msg += '\nYou can always adjust this setting with the /subscribe command.'
bot.send_or_edit(cid, msg, to_edit=update.effective_message.message_id)
return ConversationHandler.END