2022-10-12 02:40:33 +00:00
|
|
|
import discord
|
|
|
|
from discord import Client, Intents
|
|
|
|
from wiki_postbot.creds import Discord_Creds
|
|
|
|
from wiki_postbot.patterns.wikilink import Wikilink
|
|
|
|
|
|
|
|
from discord.ext import commands
|
|
|
|
from discord import Emoji
|
2022-10-16 03:15:33 +00:00
|
|
|
#
|
|
|
|
# intents = Intents.default()
|
|
|
|
# intents.message_content = True
|
|
|
|
#
|
|
|
|
# bot = commands.Bot(command_prefix='/', intents=intents)
|
|
|
|
#
|
|
|
|
# DEBUG = False
|
|
|
|
#
|
|
|
|
# @bot.event
|
|
|
|
# async def on_message(message:discord.Message):
|
|
|
|
# print(message)
|
|
|
|
#
|
|
|
|
# if message.content == 'ping':
|
|
|
|
# await message.channel.send('pong')
|
|
|
|
#
|
|
|
|
# if 'good bot' in message.content:
|
|
|
|
# await message.add_reaction("❤️🔥")
|
|
|
|
#
|
|
|
|
# wl = Wikilink.parse(message.content)
|
|
|
|
# if len(wl) > 0:
|
|
|
|
# if DEBUG:
|
|
|
|
# await message.channel.send(f"Wikilinks detected: \n" + '\n'.join([str(l) for l in wl]))
|
|
|
|
# else:
|
|
|
|
# await message.add_reaction("⏳")
|
|
|
|
#
|
|
|
|
# await bot.process_commands(message)
|
|
|
|
#
|
|
|
|
# @bot.command()
|
2022-10-12 02:40:33 +00:00
|
|
|
|
2022-10-16 03:15:33 +00:00
|
|
|
# @bot.command
|
2022-10-12 02:40:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-16 03:15:33 +00:00
|
|
|
class MyClient(Client):
|
2022-10-12 02:40:33 +00:00
|
|
|
|
2022-10-16 03:15:33 +00:00
|
|
|
def __init__(self, intents=None, debug:bool=False, **kwargs):
|
|
|
|
if intents is None:
|
|
|
|
intents = Intents.default()
|
|
|
|
intents.message_content = True
|
2022-10-12 02:40:33 +00:00
|
|
|
|
2022-10-16 03:15:33 +00:00
|
|
|
self.debug = debug
|
2022-10-12 02:40:33 +00:00
|
|
|
|
2022-10-16 03:15:33 +00:00
|
|
|
super(MyClient, self).__init__(intents=intents, **kwargs)
|
2022-10-12 02:40:33 +00:00
|
|
|
|
|
|
|
|
2022-10-16 03:15:33 +00:00
|
|
|
async def on_ready(self):
|
|
|
|
print('Logged on as', self.user)
|
|
|
|
|
|
|
|
async def on_message(self, message):
|
|
|
|
print(message)
|
|
|
|
# don't respond to ourselves
|
|
|
|
if message.author == self.user:
|
|
|
|
return
|
2022-10-12 02:40:33 +00:00
|
|
|
|
2022-10-16 03:15:33 +00:00
|
|
|
wl = Wikilink.parse(message.content)
|
|
|
|
if len(wl)>0:
|
|
|
|
await message.channel.send(f"Wikilinks detected: \n" + '\n'.join([str(l) for l in wl]))
|
|
|
|
|
|
|
|
async def debug(ctx: discord.ext.commands.Context, arg):
|
|
|
|
print('debug command')
|
|
|
|
global DEBUG
|
|
|
|
if arg == "on":
|
|
|
|
DEBUG = True
|
|
|
|
await ctx.message.add_reaction("🧪")
|
|
|
|
elif arg == "off":
|
|
|
|
DEBUG = False
|
|
|
|
await ctx.message.add_reaction("🤐")
|
|
|
|
else:
|
|
|
|
await ctx.message.reply("usage: /debug off or /debug on")
|
2022-10-12 02:40:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
creds = Discord_Creds.from_json('discord_creds.json')
|
|
|
|
# client = MyClient()
|
|
|
|
# client.run(creds.token)
|
|
|
|
|
|
|
|
|
|
|
|
bot.run(creds.token)
|