Archived
1
0
Fork 0

Merge branch 'v4-dev' of https://github.com/Teahouse-Studios/bot into v4-dev

This commit is contained in:
yzhh 2021-07-31 02:06:35 +08:00
commit 6d658cd844
7 changed files with 80 additions and 94 deletions

View file

@ -1,11 +1,14 @@
import asyncio
import os
import psutil
import time
from core.loader import ModulesManager
from core.elements import MessageSession
from database import BotDBUtil
from core.loader.decorator import command
from core.parser.command import CommandParser
from core.bots.graia.broadcast import app
@command('module',
@ -108,6 +111,40 @@ async def bot_version(msg: MessageSession):
await msg.sendMessage(msgs, msgs)
openfile.close()
@command('version',
is_base_function=True,
help_doc='~ping {获取机器人信息}'
)
async def ping(msg: MessageSession):
checkpermisson = msg.checkSuperUser()
result = "Pong!"
if checkpermisson:
Boot_Start = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(psutil.boot_time()))
time.sleep(0.5)
Cpu_usage = psutil.cpu_percent()
RAM = int(psutil.virtual_memory().total / (1024 * 1024))
RAM_percent = psutil.virtual_memory().percent
Swap = int(psutil.swap_memory().total / (1024 * 1024))
Swap_percent = psutil.swap_memory().percent
Disk = int(psutil.disk_usage('').used / (1024 * 1024 * 1024))
DiskTotal = int(psutil.disk_usage('').total / (1024 * 1024 * 1024))
try:
GroupList = len(await app.groupList())
except Exception:
GroupList = '无法获取'
try:
FriendList = len(await app.friendList())
except Exception:
FriendList = '无法获取'
BFH = r'%'
result += (f"\n系统运行时间:{Boot_Start}"
+ f"\n当前CPU使用率{Cpu_usage}{BFH}"
+ f"\n物理内存:{RAM}M 使用率:{RAM_percent}{BFH}"
+ f"\nSwap内存{Swap}M 使用率:{Swap_percent}{BFH}"
+ f"\n磁盘容量:{Disk}G/{DiskTotal}G"
+ f"\n已加入QQ群聊{GroupList}"
+ f" | 已添加QQ好友{FriendList}")
await msg.sendMessage(result)
@command('admin',
is_base_function=True,

26
modules/utils/__init__.py Normal file
View file

@ -0,0 +1,26 @@
from modules.utils import ab, rc, newbie
from modules.wiki.dbutils import WikiTargetInfo
from core.loader.decorator import command
from core.elements import MessageSession
def get_start_wiki(msg: MessageSession):
start_wiki = WikiTargetInfo(msg).get_start_wiki()
return start_wiki
@command('rc', help_doc='~rc {获取默认wiki的最近更改}')
async def rc_loader(msg: MessageSession):
res = await rc(get_start_wiki(msg))
await msg.sendMessage(res)
@command('ab', help_doc='~ab {获取默认wiki的最近滥用日志}')
async def ab_loader(msg: MessageSession):
res = await ab(get_start_wiki(msg))
await msg.sendMessage(res)
@command('newbie', help_doc='~newbie {获取默认wiki的新用户}')
async def newbie_loader(msg: MessageSession):
res = await newbie(get_start_wiki(msg))
await msg.sendMessage(res)

View file

@ -3,16 +3,14 @@ import json
import aiohttp
from core.dirty_check import check
from modules_o.utils.UTC8 import UTC8
from modules_o.wiki.database import WikiDB
from modules_o.wiki.wikilib import wikilib
from modules.utils.UTC8 import UTC8
from modules.wiki.wikilib import wikilib
async def ab(table, id):
get_wiki_url = WikiDB.get_start_wiki(table, id)
pageurl = await wikilib().get_article_path(get_wiki_url) + 'Special:AbuseLog'
if get_wiki_url:
url = get_wiki_url + '?action=query&list=abuselog&aflprop=user|title|action|result|filter|timestamp&format=json'
async def ab(wiki_url):
pageurl = await wikilib().get_article_path(wiki_url) + 'Special:AbuseLog'
if wiki_url:
url = wiki_url + '?action=query&list=abuselog&aflprop=user|title|action|result|filter|timestamp&format=json'
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=aiohttp.ClientTimeout(total=20)) as req:
if req.status != 200:

View file

@ -4,15 +4,13 @@ import re
import aiohttp
from core.dirty_check import check
from modules_o.wiki.database import WikiDB
from modules_o.wiki.wikilib import wikilib
from modules.wiki.wikilib import wikilib
async def newbie(table, id):
get_wiki_url = WikiDB.get_start_wiki(table, id)
pageurl = await wikilib().get_article_path(get_wiki_url) + 'Special:Log?type=newusers'
if get_wiki_url:
url = get_wiki_url + '?action=query&list=logevents&letype=newusers&format=json'
async def newbie(wiki_url):
pageurl = await wikilib().get_article_path(wiki_url) + 'Special:Log?type=newusers'
if wiki_url:
url = wiki_url + '?action=query&list=logevents&letype=newusers&format=json'
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=aiohttp.ClientTimeout(total=20)) as req:
if req.status != 200:

View file

@ -3,16 +3,14 @@ import json
import aiohttp
from core.dirty_check import check
from modules_o.utils.UTC8 import UTC8
from modules_o.wiki.database import WikiDB
from modules_o.wiki.wikilib import wikilib
from modules.utils.UTC8 import UTC8
from modules.wiki.wikilib import wikilib
async def rc(table, id):
get_wiki_url = WikiDB.get_start_wiki(table, id)
pageurl = await wikilib().get_article_path(get_wiki_url) + 'Special:RecentChanges'
if get_wiki_url:
url = get_wiki_url + '?action=query&list=recentchanges&rcprop=title|user|timestamp&rctype=edit|new&format=json'
async def ab(wiki_url):
pageurl = await wikilib().get_article_path(wiki_url) + 'Special:RecentChanges'
if wiki_url:
url = wiki_url + '?action=query&list=recentchanges&rcprop=title|user|timestamp&rctype=edit|new&format=json'
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=aiohttp.ClientTimeout(total=20)) as req:
if req.status != 200:

View file

@ -1,71 +0,0 @@
import time
import psutil
from modules_o.utils import ab
from modules_o.utils.newbie import newbie
from modules_o.utils import rc
async def rc_loader(kwargs: dict):
if Group in kwargs:
table = 'start_wiki_link_group'
id = kwargs[Group].id
if Friend in kwargs:
table = 'start_wiki_link_self'
id = kwargs[Friend].id
msg = await rc(table, id)
await sendMessage(kwargs, msg)
async def ab_loader(kwargs: dict):
if Group in kwargs:
table = 'start_wiki_link_group'
id = kwargs[Group].id
if Friend in kwargs:
table = 'start_wiki_link_self'
id = kwargs[Friend].id
msg = await ab(table, id)
send = await sendMessage(kwargs, msg)
async def newbie_loader(kwargs: dict):
if Group in kwargs:
table = 'start_wiki_link_group'
id = kwargs[Group].id
if Friend in kwargs:
table = 'start_wiki_link_self'
id = kwargs[Friend].id
msg = await newbie(table, id)
await sendMessage(kwargs, msg)
async def ping(kwargs: dict):
checkpermisson = database.check_superuser(kwargs)
result = "Pong!"
if checkpermisson:
Boot_Start = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(psutil.boot_time()))
time.sleep(0.5)
Cpu_usage = psutil.cpu_percent()
RAM = int(psutil.virtual_memory().total / (1024 * 1024))
RAM_percent = psutil.virtual_memory().percent
Swap = int(psutil.swap_memory().total / (1024 * 1024))
Swap_percent = psutil.swap_memory().percent
Disk = int(psutil.disk_usage('').used / (1024 * 1024 * 1024))
DiskTotal = int(psutil.disk_usage('').total / (1024 * 1024 * 1024))
try:
GroupList = len(await app.groupList())
except Exception:
GroupList = '无法获取'
try:
FriendList = len(await app.friendList())
except Exception:
FriendList = '无法获取'
BFH = r'%'
result += (f"\n系统运行时间:{Boot_Start}"
+ f"\n当前CPU使用率{Cpu_usage}{BFH}"
+ f"\n物理内存:{RAM}M 使用率:{RAM_percent}{BFH}"
+ f"\nSwap内存{Swap}M 使用率:{Swap_percent}{BFH}"
+ f"\n磁盘容量:{Disk}G/{DiskTotal}G"
+ f"\n已加入群聊:{GroupList}"
+ f" | 已添加好友:{FriendList}")
await sendMessage(kwargs, result)