支持添加 log 频道
This commit is contained in:
parent
844bbb7331
commit
2fa5cae93b
@ -20,3 +20,6 @@ REDIS_CONFIG = {'host': '127.0.0.1', 'port': 6379, 'db': 1}
|
||||
|
||||
# 拥有者 id 配置
|
||||
OWNER = 0
|
||||
|
||||
# 日志频道 id 0 为不启用
|
||||
CHANNEL = 0
|
||||
|
30
func.py
30
func.py
@ -3,7 +3,7 @@ import time
|
||||
import connector
|
||||
import telegram
|
||||
from telegram.ext import CommandHandler, MessageHandler, Filters
|
||||
from config import TOKEN, LIMIT_COUNT, EXCLUSIVE_MODE, RANK_COMMAND_MODE, OWNER, EXCLUSIVE_LIST
|
||||
from config import TOKEN, LIMIT_COUNT, EXCLUSIVE_MODE, RANK_COMMAND_MODE, OWNER, EXCLUSIVE_LIST, CHANNEL
|
||||
import schedule
|
||||
from task import add_task
|
||||
|
||||
@ -42,6 +42,10 @@ def rank(update, context):
|
||||
if chat_type != "supergroup":
|
||||
update.message.reply_text("此命令只有在群组中有效!")
|
||||
return
|
||||
try:
|
||||
msg = update.message.reply_text("正在添加任务,请稍等~")
|
||||
except:
|
||||
pass
|
||||
if RANK_COMMAND_MODE:
|
||||
try:
|
||||
chat_member = bot.get_chat_member(chat_id, user_id)
|
||||
@ -50,8 +54,16 @@ def rank(update, context):
|
||||
if status == "creator" or status == "administrator":
|
||||
print("用户权限正确")
|
||||
else:
|
||||
try:
|
||||
bot.delete_message(chat_id=chat_id, message_id=msg.message_id)
|
||||
except:
|
||||
pass
|
||||
return
|
||||
except Exception as e:
|
||||
try:
|
||||
bot.delete_message(chat_id=chat_id, message_id=msg.message_id)
|
||||
except:
|
||||
pass
|
||||
print(e)
|
||||
print("获取用户身份失败")
|
||||
if r.exists("{}_frequency_limit".format(chat_id)):
|
||||
@ -70,11 +82,23 @@ def rank(update, context):
|
||||
r.expireat("{}_frequency_limit".format(chat_id), ex_time)
|
||||
count = int(r.get("{}_frequency_limit".format(chat_id)))
|
||||
if count > LIMIT_COUNT:
|
||||
update.message.reply_text("该群组在这个小时内的生成配额已经用完,请稍后再试~")
|
||||
try:
|
||||
bot.edit_message_text(chat_id=chat_id, message_id=msg.message_id, text="该群组在这个小时内的生成配额已经用完,请稍后再试~")
|
||||
except:
|
||||
pass
|
||||
return
|
||||
add_task(chat_id)
|
||||
print("群组: {},用户: {}|{} 发起了主动触发请求".format(chat_id, username, user_id, ))
|
||||
update.message.reply_text("统计数据将在分析完毕后发送到当前群组,请稍等~")
|
||||
if not CHANNEL == 0:
|
||||
ctext = f'#WORDCLOUD #APPLY \n' \
|
||||
f'群组 ID:`{chat_id}`\n' \
|
||||
f'用户 ID:`{user_id}' \
|
||||
f'执行操作:`主动生成词云`\n'
|
||||
bot.send_message(chat_id=chat_id, text=ctext, parse_mode="Markdown")
|
||||
try:
|
||||
bot.edit_message_text(chat_id=chat_id, message_id=msg.message_id, text="统计数据将在分析完毕后发送到当前群组,请稍等~")
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
print("主动触发任务失败,请检查")
|
||||
print(e)
|
||||
|
17
task.py
17
task.py
@ -8,7 +8,7 @@ import telegram
|
||||
import time
|
||||
import os
|
||||
import connector
|
||||
from config import TOKEN, FRONT
|
||||
from config import TOKEN, FRONT, CHANNEL
|
||||
|
||||
bot = telegram.Bot(token=TOKEN)
|
||||
|
||||
@ -24,7 +24,7 @@ def schedule_task():
|
||||
if "chat_content" in i:
|
||||
group_list.append(i[:i.find("_")])
|
||||
# print(group_list)
|
||||
print("运行定时任务,让任务队列中添加任务,任务数量:{}".format(len(group_list)))
|
||||
print("运行定时任务,向任务队列中添加任务,任务数量:{}".format(len(group_list)))
|
||||
for group in group_list:
|
||||
try:
|
||||
# 向任务队列中添加任务
|
||||
@ -49,9 +49,20 @@ def do_task():
|
||||
stop_time = float(time.time())
|
||||
print("当前群组处理耗时:" + str(stop_time - start_time))
|
||||
print("---------------------------")
|
||||
ctext = f'#WORDCLOUD \n' \
|
||||
f'群组 ID:`{group}`\n' \
|
||||
f'执行操作:`生成词云`\n' \
|
||||
f'结果:`成功`\n' \
|
||||
f'处理耗时:`{(stop_time - start_time)[:5]}`'
|
||||
except Exception as e:
|
||||
print("群组: {} | 处理失败,可能是机器人已经被移出群组,请检查报错!".format(group))
|
||||
print(e)
|
||||
ctext = f'#WORDCLOUD #SCHEDULE \n' \
|
||||
f'群组 ID:`{group}`\n' \
|
||||
f'执行操作:`生成词云`\n' \
|
||||
f'结果:`失败`\n'
|
||||
if not CHANNEL == 0:
|
||||
bot.send_message(chat_id=CHANNEL, text=ctext, parse_mode="Markdown")
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
@ -166,7 +177,7 @@ def generate(group):
|
||||
chat_id=group,
|
||||
photo=open(img_path, "rb"),
|
||||
caption=text,
|
||||
parse_mode='markdown',
|
||||
parse_mode='Markdown',
|
||||
disable_notification=True
|
||||
)
|
||||
except Exception as e:
|
||||
|
Loading…
Reference in New Issue
Block a user