-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·102 lines (82 loc) · 2.81 KB
/
main.py
File metadata and controls
executable file
·102 lines (82 loc) · 2.81 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
#!/usr/bin/python3
from telegram.ext import MessageHandler, Filters
from telegram.ext import CommandHandler
from telegram.ext import CallbackContext
from telegram import Update
import logging
from telegram.ext import Updater
from datetime import datetime, timezone
from apscheduler.schedulers.background import BackgroundScheduler
from pytz import utc
import requests
'''
变量填写区
'''
misskey_url = "https://m.isle.moe" # 实例地址,末尾不要加 /
misskey_token = ""
tg_token = ""
misskey_version_above_v13 = True # 如果你的实例版本大于等于 13.0.0,请将此项设置为 True
'''
变量填写结束
'''
updater = Updater(
token=tg_token, use_context=True)
dispatcher = updater.dispatcher
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
Status = True
Sum = 0
def refresh():
global Status
Status = True
# 北京时间每天 0 点刷新
scheduler = BackgroundScheduler(timezone=utc)
scheduler.add_job(refresh, 'cron', hour=18, minute='0')
scheduler.start()
def get_invite_code():
if misskey_version_above_v13:
r = requests.post(misskey_url+'/api/invite',
json={"i": misskey_token})
else:
r = requests.post(misskey_url+'/api/admin/invite',
json={"i": misskey_token})
value = r.json()
return value['code']
def gen_random_int():
x = randint(1,50)
y = randint(1,50)
return x,y
def start(update: Update, context: CallbackContext):
user = update.message.from_user
global Status
if Status:
x,y = gen_random_int()
global Sum
Sum = x+y
context.bot.send_message(
chat_id=user['id'], text="问题:{}+{}=?".format(x,y))
else:
context.bot.send_message(
chat_id=user['id'], text="今日邀请码发放已达到上限")
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
def verify(update: Update, context: CallbackContext):
user = update.message.from_user
global Status
if Status:
if update.message.text == str(Sum):
context.bot.send_message(chat_id=user['id'], text="验证通过")
context.bot.send_message(
chat_id=user['id'], text="邀请码:"+get_invite_code())
context.bot.send_message(
chat_id=user['id'], text="注册时,请阅读本站服务条款!")
Status = False
else:
context.bot.send_message(chat_id=user['id'], text="回答错误")
else:
context.bot.send_message(
chat_id=user['id'], text="今日邀请码发放已达到上限")
verify_handler = MessageHandler(Filters.text & (~Filters.command), verify)
dispatcher.add_handler(verify_handler)
updater.start_polling()
updater.idle()