Skip to content
111 changes: 62 additions & 49 deletions main.py

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging

import discord
Expand All @@ -10,63 +11,75 @@
import voice
import pin

logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
file_handler = logging.FileHandler(filename='discord.log', encoding='utf-8',
mode='w')
file_handler.setFormatter(logging.Formatter(
'%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(file_handler)
intents = discord.Intents(messages=True, guilds=True, reactions=True,
members=True, message_content=True)
bot = commands.Bot(command_prefix='!', intents=intents, case_insensitive=True,
help_command=None,
allowed_mentions=discord.AllowedMentions(everyone=False))

def get_token() -> str:
with open("token.json") as f:
file = f.read()
token = json.loads(file)["token"]
return token

@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
print('Time: {0}'.format(datetime.datetime.now(datetime.timezone.utc)))
await bot.add_cog(matching.Matching(bot))
await bot.add_cog(roles.Roles(bot))
await bot.add_cog(audit.Audit(bot))
await bot.add_cog(voice.Voice(bot))
await bot.add_cog(pin.Pin(bot))

def main():
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
file_handler = logging.FileHandler(filename='discord.log', encoding='utf-8',
mode='w')
file_handler.setFormatter(logging.Formatter(
'%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(file_handler)
intents = discord.Intents(messages=True, guilds=True, reactions=True,
members=True, message_content=True)
bot = commands.Bot(command_prefix='!', intents=intents, case_insensitive=True,
help_command=None,
allowed_mentions=discord.AllowedMentions(everyone=False))

@bot.command()
async def ping(ctx):
await ctx.send('pong')

@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
print('Time: {0}'.format(datetime.datetime.now(datetime.timezone.utc)))
await bot.add_cog(matching.Matching(bot))
await bot.add_cog(roles.Roles(bot))
await bot.add_cog(audit.Audit(bot))
await bot.add_cog(voice.Voice(bot))
await bot.add_cog(pin.Pin(bot))
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} commands.")
except Exception as e:
print(e)

@bot.command()
@is_owner()
async def msg(ctx, channel: int, *, text: str):
await bot.get_channel(channel).send(text)
@bot.command()
async def ping(ctx):
await ctx.send('pong')

@bot.command()
@is_owner()
async def msg(ctx, channel: int, *, text: str):
await bot.get_channel(channel).send(text)

@bot.command()
@is_owner()
async def delete_category(ctx):
if ctx.channel.category:
await voice.delete_category_fully(ctx.channel.category)
@bot.command()
@is_owner()
async def delete_category(ctx):
if ctx.channel.category:
await voice.delete_category_fully(ctx.channel.category)

@bot.command()
@is_owner()
async def mass_ban(ctx, *, text: str):
lines = text.splitlines()
for line in lines:
try:
user_id = int(line.split()[0][3:-1])
member = ctx.guild.get_member(user_id)
if member:
await ctx.guild.ban(member, reason='spam bot')
print('banned: ', member)
except ValueError:
print('ValueError: ', line.split()[0])

@bot.command()
@is_owner()
async def mass_ban(ctx, *, text: str):
lines = text.splitlines()
for line in lines:
try:
user_id = int(line.split()[0][3:-1])
member = ctx.guild.get_member(user_id)
if member:
await ctx.guild.ban(member, reason='spam bot')
print('banned: ', member)
except ValueError:
print('ValueError: ', line.split()[0])
bot.allowed_mentions = discord.AllowedMentions(everyone=False)
bot.run(get_token())


bot.allowed_mentions = discord.AllowedMentions(everyone=False)
bot.run('<BOT KEY HERE>')
if __name__ == "__main__":
main()
83 changes: 53 additions & 30 deletions matching.py

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error when doing /lfg asap:

[2024-09-13 16:01:54] [ERROR   ] discord.ext.commands.bot: Ignoring exception in command lfg
Traceback (most recent call last):
  File "C:\Projects\IxianDevice\ixian-device-foss\venv\Lib\site-packages\discord\app_commands\commands.py", line 857, in _do_call
    return await self._callback(self.binding, interaction, **params)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\IxianDevice\ixian-device-foss\matching.py", line 338, in lfg
    await ctx.reply("Match created!")
  File "C:\Projects\IxianDevice\ixian-device-foss\venv\Lib\site-packages\discord\ext\commands\context.py", line 748, in reply
    return await self.send(content, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\IxianDevice\ixian-device-foss\venv\Lib\site-packages\discord\ext\commands\context.py", line 1077, in send
    await self.interaction.response.send_message(**kwargs)
  File "C:\Projects\IxianDevice\ixian-device-foss\venv\Lib\site-packages\discord\interactions.py", line 855, in send_message
    await adapter.create_interaction_response(
  File "C:\Projects\IxianDevice\ixian-device-foss\venv\Lib\site-packages\discord\webhook\async_.py", line 221, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Projects\IxianDevice\ixian-device-foss\venv\Lib\site-packages\discord\ext\commands\hybrid.py", line 444, in _invoke_with_namespace
    value = await self._do_call(ctx, ctx.kwargs)  # type: ignore
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\IxianDevice\ixian-device-foss\venv\Lib\site-packages\discord\app_commands\commands.py", line 876, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'lfg' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Projects\IxianDevice\ixian-device-foss\venv\Lib\site-packages\discord\ext\commands\hybrid.py", line 444, in _invoke_with_namespace
    value = await self._do_call(ctx, ctx.kwargs)  # type: ignore
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\IxianDevice\ixian-device-foss\venv\Lib\site-packages\discord\app_commands\commands.py", line 876, in _do_call
    raise CommandInvokeError(self, e) from e
discord.ext.commands.errors.HybridCommandError: Hybrid command raised an error: Command 'lfg' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@

channels = {
# lfg: matches
625131638887546890: 995753350408716308, # classic dune
900857355242184734: 995761430152368240, # dune: conquest
801911401156968478: 995752955464650782, # dune: imperium
625131638887546890: 995753350408716308, # classic dune
900857355242184734: 995761430152368240, # dune: conquest
801911401156968478: 995752955464650782, # dune: imperium
1022775514278142002: 1022775384992911410, # dune: war for arrakis
744191730097586236: 995751425390936124, # dune off-topic
746433956894867506: 694601128402485258, # test 1
746433606259572899: 746433914595311688, # test 2
782783616232194068: 783402464493174816, # eclipse
778682723665051698: 778682593499414579, # chaos in the old world
833984225824866336: 833984400257056769, # inis
822605513623339008: 855472640847773696, # dune play-testing
744191730097586236: 995751425390936124, # dune off-topic
746433956894867506: 694601128402485258, # test 1
746433606259572899: 746433914595311688, # test 2
782783616232194068: 783402464493174816, # eclipse
778682723665051698: 778682593499414579, # chaos in the old world
833984225824866336: 833984400257056769, # inis
822605513623339008: 855472640847773696, # dune play-testing
1032408375507566612: 1032672765070811218, # dune: imperium ranked
1257052124597194913: 1257052081802448937, # public test
}
Expand Down Expand Up @@ -306,13 +306,13 @@ def __init__(self, bot):
'creation_msg_id'], invites_sent=v['invites_sent'])
asyncio.ensure_future(update_timer())

@commands.command()
@commands.hybrid_command()
async def help(self, ctx, arg=''):
if ctx.channel.id in channels:
await ctx.channel.send(files.get_help(arg),
allowed_mentions=mentions)
await ctx.reply(files.get_help(arg),
allowed_mentions=mentions, )


@commands.command(aliases=['new'])
@commands.hybrid_command(aliases=['new'])
async def lfg(self, ctx, *, text):
print(f'!lfg {text}')
print(f'creation_msg: {ctx.message.jump_url}')
Expand All @@ -329,44 +329,67 @@ async def lfg(self, ctx, *, text):
embed=embed, allowed_mentions=mentions))
matches[match.message.id] = match
match.save()
for emoji_id in custom_emojis_to_add:
emoji = await self.guild.fetch_emoji(emoji_id)
await match.message.add_reaction(emoji)
#for emoji_id in custom_emojis_to_add:
# emoji = await self.guild.fetch_emoji(emoji_id)
# await match.message.add_reaction(emoji)
for emoji_str in common_emojis_to_add:
await match.message.add_reaction(emoji_str)
await match.update()
await ctx.reply("Match created!")

@commands.command(aliases=['remove'])
@commands.hybrid_command(aliases=['remove'])
async def delete(self, ctx):
match_to_delete = None
for match in matches.values():
if match.host == ctx.author.id:
match_to_delete = match
match_to_delete.mark_delete()

@commands.command()
if match_to_delete:
match_to_delete.mark_delete()
await ctx.reply("Match deleted successfully!")
return
await ctx.reply("Something went wrong deleting the match.")

@commands.hybrid_command()
async def edit(self, ctx, *, text):
match_to_edit = None
for match in matches.values():
if match.host == ctx.author.id:
match_to_edit = match
match_to_edit.edit_time(text)
match_to_edit.edit_note(text)
await match.update()
if match_to_edit:
match_to_edit.edit_time(text)
match_to_edit.edit_note(text)
await match_to_edit.update()
await ctx.reply("Match edited successfully!")
return
await ctx.reply("Something went wrong editing the match.")

@commands.command(aliases=edit_date_aliases)
@commands.hybrid_command(aliases=edit_date_aliases)
async def edit_date(self, ctx, *, text):
match_to_edit = None
for match in matches.values():
if match.host == ctx.author.id:
match_to_edit = match
match_to_edit.edit_time(text)
await match.update()
if match_to_edit:
match_to_edit.edit_time(text)
await match_to_edit.update()
await ctx.reply("Match edited successfully!")
return
await ctx.reply("Something went wrong editing the match.")

@commands.command(aliases=edit_text_aliases)
@commands.hybrid_command(aliases=edit_text_aliases)
async def edit_text(self, ctx, *, text):
match_to_edit = None
for match in matches.values():
if match.host == ctx.author.id:
match_to_edit = match
match_to_edit.edit_note(text)
await match.update()
if match_to_edit:
match_to_edit.edit_note(text)
await match_to_edit.update()
await ctx.reply("Match edited successfully!")
return

await ctx.reply("Something went wrong editing the match.")

@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
Expand Down