Skip to content

Commit

Permalink
Make the commands interaction compatible and disable the broken ones
Browse files Browse the repository at this point in the history
  • Loading branch information
janvernieuwe committed Nov 21, 2022
1 parent 6a43795 commit 206360b
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 30 deletions.
14 changes: 8 additions & 6 deletions cogs/bikkelpunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,30 @@ async def get(self, ctx):
# first check if the time is right before doing anything else
check_time = self.utils.is_time_correct()
if check_time is False:
return await ctx.channel.send(
f":last_quarter_moon_with_face: Echte bikkels leven tussen 03:00 en 05:00!"
return await ctx.interaction.response.send_message(
f":last_quarter_moon_with_face: Echte bikkels leven tussen 03:00 en 05:00!",
ephemeral=True
)
record = self.utils.get_existing_record(ctx.message.author.id)
if record is None:
self.utils.create_bikkelpunt_record(ctx.message)
record = self.utils.get_existing_record(ctx.message.author.id)
else:
if self.utils.has_cooldown(record):
return await ctx.channel.send(
f":last_quarter_moon_with_face: Je hebt al gebikkelt vandaag, probeer het morgen nog eens"
return await ctx.interaction.response.send_message(
f":last_quarter_moon_with_face: Je hebt al gebikkelt vandaag, probeer het morgen nog eens",
ephemeral=True
)
self.utils.update_bikkelpunt_record(ctx.message, record.get('points'))
await ctx.channel.send(
await ctx.interaction.response.send_message(
f":last_quarter_moon_with_face: Je bent een echte bikkel! "
f"**+1** (**{record.get('points') + 1}** punten totaal)"
)

@bikkel.command(help='Toon de top 10 bikkelpunten')
async def ranking(self, ctx):
database.reconnect()
await ctx.channel.send(self.utils.get_top_10_message())
await ctx.interaction.response.send_message(self.utils.get_top_10_message())


async def setup(bot):
Expand Down
14 changes: 8 additions & 6 deletions cogs/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from cachecontrol import CacheControl
from cachecontrol.heuristics import ExpiresAfter
from cachecontrol.caches.file_cache import FileCache
from util.confirm import Confirm
from discord.ext.commands import Context

import config

Expand Down Expand Up @@ -143,8 +143,8 @@ async def _joinmessage(channel, embed) -> discord.message:
await msg.add_reaction('⏹')
return msg

@commands.hybrid_command(pass_context=True, help='Create a joinable anime channel')
@commands.has_any_role(config.role['global_mod'], config.role['anime_mod'])
#@commands.hybrid_command(pass_context=True, help='Create a joinable anime channel')
#@commands.has_any_role(config.role['global_mod'], config.role['anime_mod'])
async def animechannel(self, ctx, channel_name, mal_anime_url):
print(f'{ctx.author} creates anime channel {channel_name}')
guild = ctx.message.guild
Expand All @@ -171,24 +171,25 @@ async def animechannel(self, ctx, channel_name, mal_anime_url):

@commands.hybrid_command(pass_context=True, help='Create a simple joinable channel (use quotes for description)')
@commands.has_role(config.role['global_mod'])
async def simplechannel(self, ctx, categoryid, name, description):
async def simplechannel(self, ctx: Context, categoryid, name, description):
print(f'{ctx.author} creates simple channel {name} in category {categoryid}')
guild = ctx.message.guild
try:
category = next(cat for cat in guild.categories if cat.id == int(categoryid))
except StopIteration:
await ctx.channel.send(f':x: Cant find category <#{categoryid}> :thinking:')
return
newchan = await guild.create_text_channel(
new_channel = await guild.create_text_channel(
name=name,
category=category,
topic=description,
position=len(category.channels),
reason=f"Aangevraagd door {ctx.author}",
overwrites=self.get_overwites(guild, category)
)
embed = JoinableMessage.create_simple_embed(newchan, 0)
embed = JoinableMessage.create_simple_embed(new_channel, 0)
await self._joinmessage(ctx.channel, embed)
await ctx.interaction.response.send_message(f'Created channel <#{new_channel.id}> in <#{new_channel.category.id}>')

@commands.Cog.listener(name='on_raw_reaction_add')
async def join(self, payload):
Expand Down Expand Up @@ -267,6 +268,7 @@ async def rechannel(self, ctx, channelid):
message = JoinableMessage(message, self.bot)
await message.update_members()
print(f'user {ctx.author} restored {channel}')
await ctx.interaction.response.send_message('Done', ephemeral=True)


async def setup(bot):
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions cogs/sotw.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,13 @@ async def next(self, ctx):

# Check if we have enough nominations and if we have a solid win
if len(nominations) < 2:
return await ctx.channel.send(':x: Niet genoeg nominations')
return await ctx.interaction.response.send_message(':x: Niet genoeg nominations', ephemeral=True)
if nominations[0].votes == nominations[1].votes:
return await ctx.channel.send(':x: Het is een gelijke stand')
return await ctx.interaction.response.send_message(':x: Het is een gelijke stand', ephemeral=True)

# Build a dict of the winner for the win message and database insertion
winner = nominations[0]
await ctx.channel.send(await self.forum(nominations))

# Send the win message
await channel.send(
f":trophy: De winnaar van week {self.get_previous_week_number()} is: "
Expand Down Expand Up @@ -229,6 +228,7 @@ async def next(self, ctx):

# Commit change
database.commit()
await ctx.interaction.response.send_message('Done', ephemeral=True)


async def setup(bot):
Expand Down
1 change: 1 addition & 0 deletions extensions/anilist.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async def anilist(ctx, username):
embed.add_field(name=':busts_in_silhouette: Last Activity', value=time_string)

await ctx.channel.send(embed=embed)
await ctx.interaction.response.send_message('Done', ephemeral=True)


async def request_activity_data(userid):
Expand Down
3 changes: 1 addition & 2 deletions extensions/anime.py → extensions/anime.py.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ async def anime(ctx: discord.ext.commands.context.Context, search):
embed.add_field(name=f'Premiered', value=anime['starting_time'])
embed.add_field(name=f'Links', value=f"[AniList](https://anilist.co/anime/{anime_id})")
await ctx.channel.send(embed=embed)
print(ctx.interaction)
#await ctx.message.delete()
await ctx.interaction.response.send_message('Done', ephemeral=True)


async def setup(bot):
Expand Down
23 changes: 13 additions & 10 deletions extensions/animeforum.py → extensions/animepost.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import re

from discord import ChannelType, TextStyle, ForumChannel, ForumTag
from discord import ForumTag
from discord.ext.commands import Context
from AnilistPython import Anilist

import config
import discord
from discord.ext import commands
from discord.ui import Modal, TextInput, ChannelSelect
from discord.ui import Modal, TextInput
from util.html2md import html2md


class AnimeForm(Modal):
Expand All @@ -28,12 +29,7 @@ def filter_tags(self, tag: ForumTag):

async def on_submit(self, interaction: discord.Interaction):
forum = interaction.guild.get_channel(config.channel["anime_forum"])
description = self.anime['desc'].replace('<br>', "\n")\
.replace('<b>', '**')\
.replace('</b>', '**')\
.replace('<i>', '*')\
.replace('</i>', '*')

description = html2md(self.anime['desc'])
content = f'**description:** {description}\n**Start date:** {self.anime["starting_time"]}\n{self.anime["cover_image"]}\n<{self.anilist_link}>\n{self.youtube.value}'
thread = await forum.create_thread(
name=self.name.value,
Expand All @@ -43,19 +39,26 @@ async def on_submit(self, interaction: discord.Interaction):
tags = []
filtered = filter(self.filter_tags, forum.available_tags)
for tag in filtered:
if len(tags) >= 5:
break
tags.append(tag)
await thread[0].add_tags(*tags)
await interaction.response.send_message(f'Created <#{thread[0].id}> in <#{forum.id}>')


@commands.hybrid_command(help='Create an anime post')
@commands.has_role(config.role['global_mod'])
@commands.has_role(config.role['user'])
async def animepost(ctx: Context, anilist_link):
anilist_id = re.search(r'anime/(\d+)', anilist_link)[1]
try:
anilist_id = re.search(r'anime/(\d+)', anilist_link)[1]
except TypeError:
await ctx.interaction.response.send_message(':x: Invalid anilist url', ephemeral=True)
return
anilist = Anilist()
anime = anilist.get_anime_with_id(anilist_id)
modal = AnimeForm(anime, anilist_link)
await ctx.interaction.response.send_modal(modal)
print(f'Created anime post for {modal.name} by {ctx.interaction.user.name}')


async def setup(bot):
Expand Down
2 changes: 1 addition & 1 deletion extensions/credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def credits(ctx):
mins = int(runtime // 60 % 60)
seconds = int(runtime % 60)
runtime = "{} days, {} hours, {} mins, {} seconds".format(days, hours, mins, seconds)
await ctx.send(f"**Info**\n- Author: {author}\n- Library: {lib}\n- Runtime: Python {appsoft}\n- Uptime: {runtime}")
await ctx.interaction.response.send_message(f"**Info**\n- Author: {author}\n- Library: {lib}\n- Runtime: Python {appsoft}\n- Uptime: {runtime}", ephemeral=True)
print(f"{ctx.author} showed the bot credits <3")


Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions extensions/leave.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async def leave(ctx):
)
await channel.send(f":outbox_tray: {user.mention} left")
print(f'{user} left channel {channel} using the leave command')
await ctx.interaction.response.send_message('Done', ephemeral=True)


async def setup(bot):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def userexport(ctx, channel_id: int = 0):
binary = io.BytesIO(output.getvalue().encode('utf-8'))
await ctx.send(f'Here is your export {ctx.author.mention}', file=File(binary, f"{channel.name}.csv"))
print(f"{ctx.author} exported users for channel {channel}")

await ctx.interaction.response.send_message('Done', ephemeral=True)

async def setup(bot):
bot.add_command(userexport)
2 changes: 1 addition & 1 deletion startdiscord.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
## Simple shell script that reboots the bot if it crashes
until python3 discordpy.py; do
until python3 discordpy.py -v; do
echo $(date +%H:%M:%S_%Y-%m-%d) "CRASH"
sleep 1
done
Expand Down
10 changes: 10 additions & 0 deletions util/html2md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import string


def html2md(content: string):
return content.replace('\n', '')\
.replace('<br>', "\n")\
.replace('<b>', '**')\
.replace('</b>', '**')\
.replace('<i>', '*')\
.replace('</i>', '*')

0 comments on commit 206360b

Please sign in to comment.