2021-08-19 12:17:48 +00:00
|
|
|
import os
|
2021-07-21 17:58:33 +00:00
|
|
|
|
2021-07-26 12:43:51 +00:00
|
|
|
import discord
|
|
|
|
|
2022-06-12 07:07:53 +00:00
|
|
|
from bots.discord.client import client
|
|
|
|
from bots.discord.message import MessageSession, FetchTarget
|
2022-06-17 05:59:15 +00:00
|
|
|
from bots.discord.tasks import MessageTaskManager, FinishedTasks
|
|
|
|
|
2021-08-07 07:56:48 +00:00
|
|
|
from config import Config
|
2022-06-12 07:07:53 +00:00
|
|
|
from core.elements import MsgInfo, Session, PrivateAssets, Url
|
2021-07-21 17:58:33 +00:00
|
|
|
from core.logger import Logger
|
|
|
|
from core.parser.message import parser
|
2022-06-14 12:41:58 +00:00
|
|
|
from core.utils import init, init_async, load_prompt
|
2021-08-19 12:17:48 +00:00
|
|
|
|
|
|
|
PrivateAssets.set(os.path.abspath(os.path.dirname(__file__) + '/assets'))
|
2021-08-21 15:58:07 +00:00
|
|
|
init()
|
2022-06-12 07:07:53 +00:00
|
|
|
Url.disable_mm = True
|
2021-08-03 16:04:59 +00:00
|
|
|
|
2021-08-23 16:08:21 +00:00
|
|
|
count = 0
|
2021-08-23 12:44:31 +00:00
|
|
|
|
2021-11-12 14:25:53 +00:00
|
|
|
|
2021-07-21 17:58:33 +00:00
|
|
|
@client.event
|
|
|
|
async def on_ready():
|
|
|
|
Logger.info('Logged on as ' + str(client.user))
|
2021-08-23 16:08:21 +00:00
|
|
|
global count
|
|
|
|
if count == 0:
|
2022-06-14 12:41:58 +00:00
|
|
|
await init_async(FetchTarget)
|
2021-08-23 16:08:21 +00:00
|
|
|
await load_prompt(FetchTarget)
|
|
|
|
count = 1
|
2021-07-21 17:58:33 +00:00
|
|
|
|
2021-07-24 08:59:15 +00:00
|
|
|
|
2021-07-21 17:58:33 +00:00
|
|
|
@client.event
|
|
|
|
async def on_message(message):
|
|
|
|
# don't respond to ourselves
|
|
|
|
if message.author == client.user:
|
|
|
|
return
|
2021-08-21 15:58:07 +00:00
|
|
|
target = "Discord|Channel"
|
2021-07-26 12:43:51 +00:00
|
|
|
if isinstance(message.channel, discord.DMChannel):
|
2021-08-21 15:58:07 +00:00
|
|
|
target = "Discord|DM|Channel"
|
2022-06-17 05:59:15 +00:00
|
|
|
targetId = f"{target}|{message.channel.id}"
|
|
|
|
user_id = message.author
|
|
|
|
msg = MessageSession(target=MsgInfo(targetId=targetId,
|
2021-08-21 15:58:07 +00:00
|
|
|
senderId=f"Discord|Client|{message.author.id}",
|
2022-06-12 14:30:02 +00:00
|
|
|
senderName=message.author.name, targetFrom=target, senderFrom="Discord|Client",
|
|
|
|
clientName='Discord'),
|
2021-08-03 16:04:59 +00:00
|
|
|
session=Session(message=message, target=message.channel, sender=message.author))
|
2022-06-17 05:59:15 +00:00
|
|
|
all_tsk = MessageTaskManager.get()
|
|
|
|
if targetId in all_tsk:
|
|
|
|
add_ = None
|
|
|
|
if user_id in all_tsk[targetId]:
|
|
|
|
add_ = user_id
|
|
|
|
if 'all' in all_tsk[targetId]:
|
|
|
|
add_ = 'all'
|
|
|
|
if add_:
|
|
|
|
FinishedTasks.add_task(targetId, add_, msg)
|
|
|
|
all_tsk[targetId][add_].set()
|
|
|
|
MessageTaskManager.del_task(targetId, add_)
|
2021-07-21 17:58:33 +00:00
|
|
|
await parser(msg)
|
|
|
|
|
|
|
|
|
|
|
|
dc_token = Config('dc_token')
|
|
|
|
if dc_token:
|
2021-07-24 08:59:15 +00:00
|
|
|
client.run(dc_token)
|