Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/secret/__init__.py

89 lines
3.8 KiB
Python
Raw Normal View History

2023-03-01 13:41:42 +00:00
from datetime import datetime, timedelta
2023-02-05 14:33:33 +00:00
from core.builtins import Bot
2023-03-04 08:51:56 +00:00
from core.component import module
2021-09-10 18:05:27 +00:00
from core.dirty_check import check
2021-08-23 14:17:04 +00:00
from core.logger import Logger
2023-03-01 13:41:42 +00:00
from core.scheduler import Scheduler, DateTrigger
2021-11-12 14:25:53 +00:00
from modules.wiki.utils.UTC8 import UTC8
from modules.wiki.utils.wikilib import WikiLib
2022-01-05 11:14:45 +00:00
wiki = WikiLib('https://minecraft.fandom.com/zh/api.php')
2023-03-01 13:41:42 +00:00
bot = Bot.FetchTarget
2021-08-23 14:17:04 +00:00
2023-03-04 08:51:56 +00:00
cn = module('__check_newbie__', required_superuser=True, developers=['OasisAkari'])
2021-08-23 14:17:04 +00:00
2023-03-04 08:51:56 +00:00
@cn.handle(DateTrigger(datetime.now() + timedelta(seconds=10)))
2023-03-04 09:04:35 +00:00
2023-03-01 13:41:42 +00:00
async def newbie():
2022-01-05 11:14:45 +00:00
if bot.name not in ['QQ', 'TEST']:
return
Logger.info('Start newbie monitoring...')
file = await wiki.get_json(action='query', list='logevents', letype='newusers')
2021-08-23 16:08:21 +00:00
qq = []
2023-01-16 07:54:07 +00:00
for x in file['query']['logevents']:
if 'title' in x:
qq.append(x['title'])
2021-11-12 14:25:53 +00:00
2021-08-23 16:08:21 +00:00
@Scheduler.scheduled_job('interval', seconds=60)
async def check_newbie():
2022-01-05 11:14:45 +00:00
qqqq = await wiki.get_json(action='query', list='logevents', letype='newusers')
2023-01-16 07:54:07 +00:00
for xz in qqqq['query']['logevents']:
if 'title' in xz:
if xz['title'] not in qq:
prompt = UTC8(xz['timestamp'], 'onlytime') + \
'新增新人:\n' + xz['title']
s = await check(prompt)
Logger.debug(s)
for z in s:
sz = z['content']
if not z['status']:
sz = sz + '\n检测到外来信息介入,请前往日志查看所有消息。' \
'https://minecraft.fandom.com/zh/wiki/Special:%E6%97%A5%E5%BF%97?type=newusers'
await bot.post_message('__check_newbie__', sz)
qq.append(xz['title'])
2022-01-05 11:14:45 +00:00
2023-03-04 08:51:56 +00:00
ca = module('__check_abuse__', required_superuser=True, developers=['OasisAkari'])
@ca.handle(DateTrigger(datetime.now() + timedelta(seconds=10)))
2023-03-01 13:41:42 +00:00
async def _():
2022-01-05 11:14:45 +00:00
if bot.name not in ['QQ', 'TEST']:
return
Logger.info('Start abuse monitoring...')
query = await wiki.get_json(action='query', list='abuselog', aflprop='user|title|action|result|filter|timestamp',
afllimit=30)
abuses = []
for x in query["query"]["abuselog"]:
2022-04-08 07:17:39 +00:00
abuses.append(
f'{x["user"]}{x["title"]}{x["timestamp"]}{x["filter"]}{x["action"]}{x["result"]}')
2022-01-05 11:14:45 +00:00
@Scheduler.scheduled_job('interval', seconds=60)
async def check_abuse():
query2 = await wiki.get_json(action='query', list='abuselog',
aflprop='user|title|action|result|filter|timestamp',
afllimit=30)
for y in query2["query"]["abuselog"]:
identify = f'{y["user"]}{y["title"]}{y["timestamp"]}{y["filter"]}{y["action"]}{y["result"]}'
if identify not in abuses:
s = f'用户:{y["user"]}\n' \
f'页面标题:{y["title"]}\n' \
f'过滤器名:{y["filter"]}\n' \
f'操作:{y["action"]}\n'
result = y['result']
if result == '':
result = 'pass'
s += '处理结果:' + result + '\n'
s += UTC8(y['timestamp'], 'full')
chk = await check(s)
2022-08-04 07:52:42 +00:00
Logger.debug(chk)
2022-01-05 11:14:45 +00:00
for z in chk:
sz = z['content']
if not z['status']:
sz = sz + '\n检测到外来信息介入,请前往日志查看所有消息。' \
2022-01-20 12:13:03 +00:00
'https://minecraft.fandom.com/zh/wiki/Special:%E6%BB%A5%E7%94%A8%E6%97%A5%E5%BF%97'
2022-01-05 11:15:28 +00:00
await bot.post_message('__check_abuse__', sz)
2022-01-05 11:14:45 +00:00
abuses.append(identify)