Archived
1
0
Fork 0
This commit is contained in:
yzhh 2021-08-22 22:55:25 +08:00
parent 493aaab4fa
commit 6949c923d6
9 changed files with 30 additions and 64 deletions

View file

@ -26,8 +26,8 @@ async def msg_handler(message: types.Message):
all_tsk[user_id].set()
MessageTaskManager.del_task(user_id)
msg = MessageSession(MsgInfo(targetId=f'Telegram|{message.chat.type}|{message.chat.id}',
senderId=f'Telegram|User|{message.from_user.id}', targetFrom='Telegram',
senderFrom='Telegram', senderName=message.from_user.username),
senderId=f'Telegram|User|{message.from_user.id}', targetFrom=f'Telegram|{message.chat.type}',
senderFrom='Telegram|User', senderName=message.from_user.username),
Session(message=message, target=message.chat.id, sender=message.from_user.id))
await parser(msg)

View file

@ -1,6 +1,7 @@
import asyncio
import logging
import os
import re
import discord
@ -17,7 +18,6 @@ from core.utils import PrivateAssets, init, load_prompt
PrivateAssets.set(os.path.abspath(os.path.dirname(__file__) + '/assets'))
init()
@client.event
async def on_ready():
Logger.info('Logged on as ' + str(client.user))
@ -28,7 +28,6 @@ async def on_ready():
await asyncio.gather(*gather_list)
Scheduler.start()
logging.getLogger('apscheduler.executors.default').setLevel(logging.WARNING)
await asyncio.sleep(5)
await load_prompt(FetchTarget)

View file

@ -84,9 +84,9 @@ class MessageSession(MS):
class FetchTarget(FT):
@staticmethod
async def fetch_target(targetId):
matchChannel = re.match(r'^(DC\|(?:DM\||)Channel)\|(.*)', targetId)
matchChannel = re.match(r'^(Discord\|(?:DM\||)Channel)\|(.*)', targetId)
if matchChannel:
getChannel = client.get_channel(int(matchChannel.group(2)))
getChannel = await client.fetch_channel(int(matchChannel.group(2)))
return MessageSession(MsgInfo(targetId=targetId, senderId=targetId, senderName='',
targetFrom=matchChannel.group(1), senderFrom=matchChannel.group(1)),
Session(message=False, target=getChannel, sender=getChannel))

View file

@ -70,7 +70,7 @@ async def slk_converter(filepath):
async def load_prompt(bot: FetchTarget):
print(111)
author_cache = os.path.abspath('.cache_restart_author')
author_cache = os.path.abspath(PrivateAssets.path + '/cache_restart_author')
loader_cache = os.path.abspath('.cache_loader')
if os.path.exists(author_cache):
open_author_cache = open(author_cache, 'r')

BIN
database/old.db Normal file

Binary file not shown.

View file

@ -0,0 +1,18 @@
import os
import sqlite3
from database import BotDBUtil
old_db_link = os.path.abspath('./database/old.db')
conn = sqlite3.connect(old_db_link)
c = conn.cursor()
friends = c.execute(f"SELECT * FROM friend_permission").fetchall()
for friend in friends:
BotDBUtil.Module(f'QQ|{friend[0]}').enable('|'.split(friend[1]))
groups = c.execute(f"SELECT * FROM group_permission").fetchall()
for group in groups:
BotDBUtil.Module(f'QQ|Group|{group[0]}').enable('|'.split(group[1]))
group_admins = c.execute(f"SELECT * FROM group_adminuser").fetchall()
for x in group_admins:
BotDBUtil.SenderInfo(f'QQ|{x[1]}').add_TargetAdmin(f'QQ|Group|{x[2]}')

View file

@ -176,12 +176,12 @@ async def ping(msg: MessageSession):
@command('admin',
is_base_function=True,
need_admin=True,
help_doc=('~admin add <user>', '~admin del <user>')
help_doc=('~admin add <UserID> {设置成员为机器人管理员}', '~admin del <UserID> {取消成员的机器人管理员}')
)
async def config_gu(msg: MessageSession):
if msg.parsed_msg['add']:
user = msg.parsed_msg['<user>']
if user:
if user and not BotDBUtil.SenderInfo(f"{msg.target.senderFrom}|{user}").check_TargetAdmin(msg.target.targetId):
if BotDBUtil.SenderInfo(f"{msg.target.senderFrom}|{user}").add_TargetAdmin(msg.target.targetId):
await msg.sendMessage("成功")
if msg.parsed_msg['del']:
@ -220,7 +220,7 @@ async def restart_bot(msg: MessageSession):
await msg.sendMessage('你确定吗?')
confirm = await msg.waitConfirm()
if confirm:
update = os.path.abspath('.cache_restart_author')
update = os.path.abspath(PrivateAssets.path + '/cache_restart_author')
write_version = open(update, 'w')
write_version.write(json.dumps({'From': msg.target.targetFrom, 'ID': msg.target.targetId}))
write_version.close()
@ -243,7 +243,7 @@ async def update_and_restart_bot(msg: MessageSession):
await msg.sendMessage('你确定吗?')
confirm = await msg.waitConfirm()
if confirm:
update = os.path.abspath('.cache_restart_author')
update = os.path.abspath(PrivateAssets.path + '/cache_restart_author')
write_version = open(update, 'w')
write_version.write(json.dumps({'From': msg.target.targetFrom, 'ID': msg.target.targetId}))
write_version.close()

View file

@ -1,21 +1,10 @@
import asyncio
import json
import traceback
import difflib
import aiohttp
from core.broadcast import bcc
from core.template import logger_info
from database_old import BotDB
from graia.application import MessageChain
from graia.application.message.elements.internal import Plain, Image
from graia.scheduler import GraiaScheduler
from graia.scheduler.timers import every_minute
from .database import MD as db
database = db()
check_enable_modules_all = BotDB.check_enable_modules_all
scheduler = GraiaScheduler(bcc.loop, bcc)
from
async def start_check_news(app):

View file

@ -1,40 +0,0 @@
import os
import sqlite3
dbpath = os.path.abspath('./modules/minecraft_news/save.db')
class MD:
def __init__(self):
if not os.path.exists(dbpath):
self.initialize()
self.conn = sqlite3.connect(dbpath)
self.c = self.conn.cursor()
def initialize(self):
a = open(dbpath, 'w')
a.close()
self.conn = sqlite3.connect(dbpath)
self.c = self.conn.cursor()
self.c.execute('''CREATE TABLE mc_news
(TITLE TEXT PRIMARY KEY NOT NULL,
LINK TEXT,
PDESC TEXT,
IMAGE TEXT,
PDATE TEXT);''')
self.c.close()
def add_news(self, title, link, desc, image, date):
self.c.execute(f"INSERT INTO mc_news (TITLE, LINK, PDESC, IMAGE, PDATE) VALUES (?, ?, ?, ?, ?)",
(title, link, desc, image, date))
self.conn.commit()
return
def check_exist(self, title):
a = self.c.execute(f"SELECT * FROM mc_news WHERE TITLE=?", (title,)).fetchone()
if a:
return True
else:
return False