Skip to content
Snippets Groups Projects
Unverified Commit b1cd8f42 authored by dnns01's avatar dnns01 Committed by GitHub
Browse files

Merge pull request #17 from FU-Hagen-Discord/disnake-migration

Migrate to disnake
parents a3497ad9 764b2be8
Branches master
No related tags found
1 merge request!15Aktualisierung von News-Branch
......@@ -5,8 +5,8 @@ import json
import os
import uuid
import discord
from discord.ext import tasks, commands
import disnake
from disnake.ext import tasks, commands
import utils
from cogs.help import help, handle_error, help_category
......@@ -109,7 +109,7 @@ class Appointments(commands.Cog):
if str(message.id) in delete:
await message.delete()
except discord.errors.NotFound:
except disnake.errors.NotFound:
delete.append(message_id)
if len(delete) > 0:
......@@ -169,7 +169,7 @@ class Appointments(commands.Cog):
else:
reminder = utils.to_minutes(reminder)
embed = discord.Embed(title="Neuer Termin hinzugefügt!",
embed = disnake.Embed(title="Neuer Termin hinzugefügt!",
description=f"Wenn du eine Benachrichtigung zum Beginn des Termins"
f"{f', sowie {reminder} Minuten vorher, ' if reminder > 0 else f''} "
f"erhalten möchtest, reagiere mit :thumbsup: auf diese Nachricht.",
......@@ -182,7 +182,7 @@ class Appointments(commands.Cog):
if recurring:
embed.add_field(name="Wiederholung", value=f"Alle {recurring} Tage", inline=False)
message = await channel.send(embed=embed, file=discord.File(get_ics_file(title, date_time, reminder, recurring),
message = await channel.send(embed=embed, file=disnake.File(get_ics_file(title, date_time, reminder, recurring),
filename=f"{title}.ics"))
await message.add_reaction("👍")
await message.add_reaction("🗑️")
......@@ -214,7 +214,7 @@ class Appointments(commands.Cog):
message = await ctx.channel.fetch_message(int(message_id))
answer += f'{appointment["date_time"]}: {appointment["title"]} => ' \
f'{message.jump_url}\n'
except discord.errors.NotFound:
except disnake.errors.NotFound:
delete.append(message_id)
if len(delete) > 0:
......
......@@ -3,8 +3,8 @@ import json
import os
import re
import discord
from discord.ext import commands, tasks
import disnake
from disnake.ext import commands, tasks
import utils
from cogs.help import help
......@@ -46,7 +46,7 @@ class Calmdown(commands.Cog):
if inform_user:
await utils.send_dm(user, f"Die Mute-Rolle wurde nun wieder entfernt.")
await user.remove_roles(role)
except discord.errors.NotFound:
except disnake.errors.NotFound:
pass
if self.silenced_users.get(str(user_id)):
......@@ -77,7 +77,7 @@ class Calmdown(commands.Cog):
)
@commands.command(name="calmdown", aliases=["auszeit", "mute"])
@commands.check(utils.is_mod)
async def cmd_calmdown(self, ctx, user: discord.Member, duration):
async def cmd_calmdown(self, ctx, user: disnake.Member, duration):
if re.match(r"^[0-9]+$", duration):
duration = f"{duration}m"
if not utils.is_valid_time(duration):
......
import discord
import disnake
import emoji
DEFAULT_OPTIONS = ["🇦", "🇧", "🇨", "🇩", "🇪", "🇫", "🇬", "🇭", "🇮", "🇯", "🇰", "🇱", "🇲", "🇳", "🇴", "🇵", "🇶",
......@@ -83,7 +83,7 @@ class Poll:
f"Fehler beim Erstellen der Umfrage! Es werden nicht mehr als {len(DEFAULT_OPTIONS)} Optionen unterstützt!")
return
embed = discord.Embed(title=title, description=self.question)
embed = disnake.Embed(title=title, description=self.question)
embed.add_field(name="Erstellt von", value=f'<@!{self.author}>', inline=False)
embed.add_field(name="\u200b", value="\u200b", inline=False)
......
import inspect
import re
import discord
from discord.ext import commands
import disnake
from disnake.ext import commands
import utils
......@@ -166,7 +166,7 @@ class Help(commands.Cog):
text += f"**{command['syntax']}**\n"
text += f"{command['brief']}\n\n" if command['brief'] else "\n"
if (len(helptext) + len(text) > 2048):
embed = discord.Embed(title=title,
embed = disnake.Embed(title=title,
description=helptext,
color=19607)
await utils.send_dm(ctx.author, "", embed=embed)
......@@ -176,7 +176,7 @@ class Help(commands.Cog):
helptext += text
text = ""
embed = discord.Embed(title=title,
embed = disnake.Embed(title=title,
description=helptext,
color=19607)
await utils.send_dm(ctx.author, "", embed=embed)
......@@ -199,7 +199,7 @@ class Help(commands.Cog):
text += f"`{param}` - {desc}\n"
text += f"**Beispiel:**\n `{command['example']}`\n" if command['example'] else ""
text += f"\n{command['description']}\n" if command['description'] else ""
embed = discord.Embed(title=title,
embed = disnake.Embed(title=title,
description=text,
color=19607)
await utils.send_dm(ctx.author, text) # , embed=embed)
......@@ -231,7 +231,7 @@ class Help(commands.Cog):
text += f"\n{command['description']}\n" if command['description'] else ""
text += "=====================================================\n"
if (len(helptext) + len(text) > 2048):
embed = discord.Embed(title=title,
embed = disnake.Embed(title=title,
description=helptext,
color=19607)
await utils.send_dm(ctx.author, "", embed=embed)
......@@ -241,7 +241,7 @@ class Help(commands.Cog):
helptext += text
text = ""
embed = discord.Embed(title=title,
embed = disnake.Embed(title=title,
description=helptext,
color=19607)
await utils.send_dm(ctx.author, "", embed=embed)
import json
import os
import discord
from discord.ext import commands
import disnake
from disnake.ext import commands
from cogs.help import help, handle_error, help_category
......@@ -33,7 +33,7 @@ class Links(commands.Cog):
@commands.command(name="links")
async def cmd_links(self, ctx, group=None):
if channel_links := self.links.get(str(ctx.channel.id)):
embed = discord.Embed(title=f"Folgende Links sind in diesem Channel hinterlegt:\n")
embed = disnake.Embed(title=f"Folgende Links sind in diesem Channel hinterlegt:\n")
if group:
group = group.lower()
if group_links := channel_links.get(group):
......
import os
from discord.ext import commands
from disnake.ext import commands
import utils
from cogs.components.poll.poll import Poll
......
import json
import os
import discord
import disnake
import emoji
from discord.ext import commands
from disnake.ext import commands
import utils
from cogs.help import help, handle_error, help_category
......@@ -45,7 +45,7 @@ class Roles(commands.Cog):
guild = ctx.guild
members = await guild.fetch_members().flatten()
answer = f''
embed = discord.Embed(title="Statistiken",
embed = disnake.Embed(title="Statistiken",
description=f'Wir haben aktuell {len(members)} Mitglieder auf diesem Server, verteilt auf folgende Rollen:')
for role in guild.roles:
......@@ -77,7 +77,7 @@ class Roles(commands.Cog):
channel = await self.bot.fetch_channel(self.channel_id)
message = None if self.role_message_id == 0 else await channel.fetch_message(self.role_message_id)
embed = discord.Embed(title="Vergabe von Fakultäts-Rollen",
embed = disnake.Embed(title="Vergabe von Fakultäts-Rollen",
description="Durch klicken auf die entsprechende Reaktion kannst du dir die damit assoziierte Rolle zuweisen, oder entfernen. Dies funktioniert so, dass ein Klick auf die Reaktion die aktuelle Zuordnung dieser Rolle ändert. Das bedeutet, wenn du die Rolle, die mit :scales: assoziiert ist, schon hast, aber die Reaktion noch nicht ausgewählt hast, dann wird dir bei einem Klick auf die Reaktion diese Rolle wieder weggenommen. ")
value = f""
......
import io
import os
import discord
from discord.ext import commands
import disnake
from disnake.ext import commands
class Support(commands.Cog):
......@@ -15,14 +15,14 @@ class Support(commands.Cog):
if message.author == self.bot.user:
return
if type(message.channel) is discord.DMChannel:
if type(message.channel) is disnake.DMChannel:
channel = await self.bot.fetch_channel(self.channel_id)
files = []
for attachment in message.attachments:
fp = io.BytesIO()
await attachment.save(fp)
files.append(discord.File(fp, filename=attachment.filename))
files.append(disnake.File(fp, filename=attachment.filename))
await channel.send(f"Support Nachricht von <@!{message.author.id}>:")
await channel.send(message.content, files=files)
\ No newline at end of file
await channel.send(message.content, files=files)
......@@ -3,8 +3,8 @@ import os
import random
import re
import discord
from discord.ext import commands
import disnake
from disnake.ext import commands
import utils
from cogs.help import text_command_help, help, handle_error, remove_help_for, help_category
......@@ -229,7 +229,7 @@ class TextCommands(commands.Cog):
command = self.text_commands.get(cmd)
title = "Vorschlag für neuen Command Text" if command else "Vorschlag für neues Command"
embed = discord.Embed(title=title,
embed = disnake.Embed(title=title,
description=f"<@!{ctx.author.id}> hat folgenden Vorschlag eingereicht.\n"
f"👍 um den Vorschlag anzunehmen\n"
f"👎 um den Vorschlag abzulehnen")
......
This diff is collapsed.
import os
import discord
from discord.ext import commands
import disnake
from disnake.ext import commands
import utils
from cogs.help import help, handle_error
......@@ -24,7 +24,7 @@ class Welcome(commands.Cog):
channel = await self.bot.fetch_channel(self.channel_id)
message = None if self.message_id == 0 else await channel.fetch_message(self.message_id)
embed = discord.Embed(title=":rocket: __FernUni Föderation__ :rocket:",
embed = disnake.Embed(title=":rocket: __FernUni Föderation__ :rocket:",
description="Willkommen auf dem interdisziplinären Server von und für FernUni-Studierende! Hier können FernUni-Studierende aus allen Fachrichtungen in Austausch treten, Ideen austauschen und gemeinsam an Projekten arbeiten: viel Potenzial für gegenseitige Bereicherung!")
embed.add_field(name=":sparkles: Entstehung",
......
......@@ -3,17 +3,19 @@ async-timeout==3.0.1
attrs==20.3.0
beautifulsoup4==4.9.3
certifi==2020.12.5
cffi==1.14.5
chardet==3.0.4
discord.py==1.7.3
disnake==2.2.2
emoji==1.2.0
idna==2.10
multidict==5.1.0
pycparser==2.20
PyNaCl==1.4.0
python-dotenv==0.17.0
requests==2.25.1
six==1.16.0
soupsieve==2.2.1
tinydb==4.4.0
typing-extensions==3.7.4.3
urllib3==1.26.5
yarl==1.6.3
dislash.py==1.0.17
discord.py[voice]==1.7.3
pynacl==1.4.0
import os
import discord
from discord.ext import commands
from dislash import *
import disnake
from disnake.ext import commands
from dotenv import load_dotenv
from cogs import appointments, calmdown, help, links, polls, roles, support, text_commands, timer, welcome
......@@ -14,21 +13,34 @@ GUILD = int(os.getenv('DISCORD_GUILD'))
ACTIVITY = os.getenv('DISCORD_ACTIVITY')
PIN_EMOJI = "📌"
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='!', help_command=None, activity=discord.Game(ACTIVITY), intents=intents)
bot.add_cog(appointments.Appointments(bot))
bot.add_cog(calmdown.Calmdown(bot))
bot.add_cog(help.Help(bot))
bot.add_cog(links.Links(bot))
bot.add_cog(polls.Polls(bot))
bot.add_cog(roles.Roles(bot))
bot.add_cog(support.Support(bot))
bot.add_cog(text_commands.TextCommands(bot))
bot.add_cog(timer.Timer(bot))
bot.add_cog(welcome.Welcome(bot))
SlashClient(bot, show_warnings=True) # Stellt den Zugriff auf die Buttons bereit
class Root(commands.Bot):
def __init__(self):
super().__init__(command_prefix='!', help_command=None, activity=disnake.Game(ACTIVITY),
intents=disnake.Intents.all())
self.add_cogs()
self.persistent_views_added = False
async def on_ready(self):
if not self.persistent_views_added:
if timer_cog := self.get_cog("Timer"):
self.add_view(timer_cog.get_view())
print("Client started!")
def add_cogs(self):
self.add_cog(appointments.Appointments(self))
self.add_cog(calmdown.Calmdown(self))
self.add_cog(help.Help(self))
self.add_cog(links.Links(self))
self.add_cog(polls.Polls(self))
self.add_cog(roles.Roles(self))
self.add_cog(support.Support(self))
self.add_cog(text_commands.TextCommands(self))
self.add_cog(timer.Timer(self))
self.add_cog(welcome.Welcome(self))
bot = Root()
def get_reaction(reactions):
......@@ -57,11 +69,6 @@ async def unpin_message(message):
await message.unpin()
@bot.event
async def on_ready():
print("Client started!")
@bot.event
async def on_raw_reaction_add(payload):
if payload.user_id == bot.user.id:
......
import os
import re
import discord
import disnake
async def send_dm(user, message, embed=None):
""" Send DM to a user/member """
if type(user) is discord.User or type(user) is discord.Member:
if type(user) is disnake.User or type(user) is disnake.Member:
if user.dm_channel is None:
await user.create_dm()
......
import disnake
from disnake import MessageInteraction, ButtonStyle
from disnake.ui import Button, View
SUBSCRIBE = "timerview:subscribe"
UNSUBSCRIBE = "timerview:unsubscribe"
SKIP = "timverview:skip"
RESTART = "timverview:restart"
STOP = "timverview:stop"
class TimerView(View):
def __init__(self, callback):
super().__init__(timeout=None)
self.callback = callback
@disnake.ui.button(emoji="👍", style=ButtonStyle.grey, custom_id=SUBSCRIBE)
async def btn_subscribe(self, button: Button, interaction: MessageInteraction):
await self.callback(button, interaction)
@disnake.ui.button(emoji="👎", style=ButtonStyle.grey, custom_id=UNSUBSCRIBE)
async def btn_unsubscribe(self, button: Button, interaction: MessageInteraction):
await self.callback(button, interaction)
@disnake.ui.button(emoji="", style=ButtonStyle.grey, custom_id=SKIP)
async def btn_skip(self, button: Button, interaction: MessageInteraction):
await self.callback(button, interaction)
@disnake.ui.button(emoji="🔄", style=ButtonStyle.grey, custom_id=RESTART)
async def btn_restart(self, button: Button, interaction: MessageInteraction):
await self.callback(button, interaction)
@disnake.ui.button(emoji="🛑", style=ButtonStyle.grey, custom_id=STOP)
async def btn_stop(self, button: Button, interaction: MessageInteraction):
await self.callback(button, interaction)
def disable(self):
for button in self.children:
button.disabled = True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment