Skip to content
Snippets Groups Projects
Commit 0e9bf000 authored by dnns01's avatar dnns01
Browse files

Update libs and fix appointments and polls

parent 45ae838b
No related branches found
No related tags found
No related merge requests found
.idea/misc.xml 100755 → 100644
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (xanathar)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (xanathar)" project-jdk-type="Python SDK" />
</project> </project>
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" /> <excludeFolder url="file://$MODULE_DIR$/venv" />
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.10 (xanathar)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.11 (xanathar)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>
\ No newline at end of file
import asyncio import asyncio
import uuid
from datetime import datetime, timedelta from datetime import datetime, timedelta
import os import os
...@@ -89,7 +90,7 @@ class Appointments(commands.GroupCog, name="appointments", description="Handle A ...@@ -89,7 +90,7 @@ class Appointments(commands.GroupCog, name="appointments", description="Handle A
reminder_sent=reminder == 0, uuid=uuid.uuid4()) reminder_sent=reminder == 0, uuid=uuid.uuid4())
await interaction.response.send_message(embed=appointment.get_embed(), view=AppointmentView()) await interaction.response.send_message(embed=appointment.get_embed(), view=AppointmentView())
message = await interaction.original_message() message = await interaction.original_response()
Appointment.update(message=message.id).where(Appointment.id == appointment.id).execute() Appointment.update(message=message.id).where(Appointment.id == appointment.id).execute()
@app_commands.command(name="list", description="Listet alle Termine dieses Kanals auf.") @app_commands.command(name="list", description="Listet alle Termine dieses Kanals auf.")
...@@ -110,9 +111,9 @@ class Appointments(commands.GroupCog, name="appointments", description="Handle A ...@@ -110,9 +111,9 @@ class Appointments(commands.GroupCog, name="appointments", description="Handle A
except errors.NotFound: except errors.NotFound:
appointment.delete_instance(recursive=True) appointment.delete_instance(recursive=True)
await interaction.edit_original_message(content=answer) await interaction.edit_original_response(content=answer)
else: else:
await interaction.edit_original_message(content="Für diesen Channel existieren derzeit keine Termine") await interaction.edit_original_response(content="Für diesen Channel existieren derzeit keine Termine")
async def setup(bot: commands.Bot) -> None: async def setup(bot: commands.Bot) -> None:
......
...@@ -42,13 +42,13 @@ class Polls(commands.GroupCog, name="poll", description="Handle Polls in Channel ...@@ -42,13 +42,13 @@ class Polls(commands.GroupCog, name="poll", description="Handle Polls in Channel
choice] choice]
await interaction.response.send_message("Bereite Umfrage vor, bitte warten...", view=PollView()) await interaction.response.send_message("Bereite Umfrage vor, bitte warten...", view=PollView())
message = await interaction.original_message() message = await interaction.original_response()
poll = Poll.create(question=question, author=interaction.user.id, channel=interaction.channel_id, poll = Poll.create(question=question, author=interaction.user.id, channel=interaction.channel_id,
message=message.id) message=message.id)
for choice in choices: for choice in choices:
PollChoice.create(poll_id=poll.id, emoji=choice[0], text=choice[1]) PollChoice.create(poll_id=poll.id, emoji=choice[0], text=choice[1])
await interaction.edit_original_message(content="", embed=poll.get_embed(), view=PollView()) await interaction.edit_original_response(content="", embed=poll.get_embed(), view=PollView())
def parse_choice(self, idx: int, choice: str): def parse_choice(self, idx: int, choice: str):
choice = choice.strip() choice = choice.strip()
......
aiohttp==3.8.5 aiohttp==3.8.5
aiosignal==1.2.0 aiosignal==1.3.1
async-timeout==4.0.2 async-timeout==4.0.3
attrs==21.4.0 attrs==23.1.0
charset-normalizer==2.1.0 charset-normalizer==3.2.0
discord.py==2.3.2 discord.py==2.3.2
emoji==2.8.0 emoji==2.8.0
frozenlist==1.3.0 frozenlist==1.4.0
idna==3.3 idna==3.4
multidict==6.0.2 multidict==6.0.4
peewee==3.15.2 peewee==3.16.3
python-dotenv==0.20.0 python-dotenv==1.0.0
yarl==1.7.2 yarl==1.9.2
...@@ -10,9 +10,7 @@ class AppointmentView(discord.ui.View): ...@@ -10,9 +10,7 @@ class AppointmentView(discord.ui.View):
@discord.ui.button(label='Zusagen', style=discord.ButtonStyle.green, custom_id='appointment_view:accept', emoji="👍") @discord.ui.button(label='Zusagen', style=discord.ButtonStyle.green, custom_id='appointment_view:accept', emoji="👍")
async def accept(self, interaction: discord.Interaction, button: discord.ui.Button): async def accept(self, interaction: discord.Interaction, button: discord.ui.Button):
appointment = Appointment.select().where(Appointment.message == interaction.message.id) if appointment := Appointment.get_or_none(Appointment.message == interaction.message.id):
if appointment:
appointment = appointment[0]
attendee = appointment.attendees.filter(member_id=interaction.user.id) attendee = appointment.attendees.filter(member_id=interaction.user.id)
if attendee: if attendee:
await interaction.response.send_message("Du bist bereits Teilnehmerin dieses Termins.", await interaction.response.send_message("Du bist bereits Teilnehmerin dieses Termins.",
...@@ -26,9 +24,7 @@ class AppointmentView(discord.ui.View): ...@@ -26,9 +24,7 @@ class AppointmentView(discord.ui.View):
@discord.ui.button(label='Absagen', style=discord.ButtonStyle.red, custom_id='appointment_view:decline', emoji="👎") @discord.ui.button(label='Absagen', style=discord.ButtonStyle.red, custom_id='appointment_view:decline', emoji="👎")
async def decline(self, interaction: discord.Interaction, button: discord.ui.Button): async def decline(self, interaction: discord.Interaction, button: discord.ui.Button):
appointment = Appointment.select().where(Appointment.message == interaction.message.id) if appointment := Appointment.get_or_none(Appointment.message == interaction.message.id):
if appointment:
appointment = appointment[0]
attendee = appointment.attendees.filter(member_id=interaction.user.id) attendee = appointment.attendees.filter(member_id=interaction.user.id)
if attendee: if attendee:
attendee = attendee[0] attendee = attendee[0]
...@@ -44,18 +40,14 @@ class AppointmentView(discord.ui.View): ...@@ -44,18 +40,14 @@ class AppointmentView(discord.ui.View):
@discord.ui.button(label='Download .ics', style=discord.ButtonStyle.blurple, custom_id='appointment_view:ics', @discord.ui.button(label='Download .ics', style=discord.ButtonStyle.blurple, custom_id='appointment_view:ics',
emoji="📅") emoji="📅")
async def ics(self, interaction: discord.Interaction, button: discord.ui.Button): async def ics(self, interaction: discord.Interaction, button: discord.ui.Button):
appointment = Appointment.select().where(Appointment.message == interaction.message.id) if appointment := Appointment.get_or_none(Appointment.message == interaction.message.id):
if appointment:
appointment = appointment[0]
await interaction.response.send_message("", file=File(appointment.get_ics_file(), await interaction.response.send_message("", file=File(appointment.get_ics_file(),
filename=f"{appointment.title}_{appointment.uuid}.ics"), ephemeral=True) filename=f"{appointment.title}_{appointment.uuid}.ics"), ephemeral=True)
@discord.ui.button(label='Löschen', style=discord.ButtonStyle.gray, custom_id='appointment_view:delete', emoji="🗑") @discord.ui.button(label='Löschen', style=discord.ButtonStyle.gray, custom_id='appointment_view:delete', emoji="🗑")
async def delete(self, interaction: discord.Interaction, button: discord.ui.Button): async def delete(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer(thinking=False) await interaction.response.defer(thinking=False)
appointment = Appointment.select().where(Appointment.message == interaction.message.id) if appointment := Appointment.get_or_none(Appointment.message == interaction.message.id):
if appointment:
appointment = appointment[0]
if interaction.user.id == appointment.author: if interaction.user.id == appointment.author:
appointment.delete_instance(recursive=True) appointment.delete_instance(recursive=True)
await interaction.message.delete() await interaction.message.delete()
...@@ -9,9 +9,7 @@ class PollView(discord.ui.View): ...@@ -9,9 +9,7 @@ class PollView(discord.ui.View):
@discord.ui.button(label='Abstimmen', style=discord.ButtonStyle.green, custom_id='poll_view:vote', emoji="") @discord.ui.button(label='Abstimmen', style=discord.ButtonStyle.green, custom_id='poll_view:vote', emoji="")
async def vote(self, interaction: discord.Interaction, button: discord.ui.Button): async def vote(self, interaction: discord.Interaction, button: discord.ui.Button):
poll = Poll.select().where(Poll.message == interaction.message.id) if poll := Poll.get_or_none(Poll.message == interaction.message.id):
if poll:
poll = poll[0]
await interaction.response.send_message(f"{poll.question}\n\n*(Nach der Abstimmung kannst du diese Nachricht " await interaction.response.send_message(f"{poll.question}\n\n*(Nach der Abstimmung kannst du diese Nachricht "
f"verwerfen. Wenn die Abstimmung nicht funktioniert, bitte verwirf " f"verwerfen. Wenn die Abstimmung nicht funktioniert, bitte verwirf "
f"die Nachricht und Klicke erneut auf den Abstimmen Button der " f"die Nachricht und Klicke erneut auf den Abstimmen Button der "
...@@ -21,19 +19,15 @@ class PollView(discord.ui.View): ...@@ -21,19 +19,15 @@ class PollView(discord.ui.View):
@discord.ui.button(label='Beenden', style=discord.ButtonStyle.gray, custom_id='poll_view:close', emoji="🛑") @discord.ui.button(label='Beenden', style=discord.ButtonStyle.gray, custom_id='poll_view:close', emoji="🛑")
async def close(self, interaction: discord.Interaction, button: discord.ui.Button): async def close(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer(thinking=False) await interaction.response.defer(thinking=False)
poll = Poll.select().where(Poll.message == interaction.message.id) if poll := Poll.get_or_none(Poll.message == interaction.message.id):
if poll:
poll = poll[0]
if interaction.user.id == poll.author: if interaction.user.id == poll.author:
poll.delete_instance(recursive=True) poll.delete_instance(recursive=True)
await interaction.edit_original_message(view=None) await interaction.edit_original_response(view=None)
@discord.ui.button(label='Löschen', style=discord.ButtonStyle.gray, custom_id='poll_view:delete', emoji="🗑") @discord.ui.button(label='Löschen', style=discord.ButtonStyle.gray, custom_id='poll_view:delete', emoji="🗑")
async def delete(self, interaction: discord.Interaction, button: discord.ui.Button): async def delete(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer(thinking=False) await interaction.response.defer(thinking=False)
poll = Poll.select().where(Poll.message == interaction.message.id) if poll := Poll.get_or_none(Poll.message == interaction.message.id):
if poll:
poll = poll[0]
if interaction.user.id == poll.author: if interaction.user.id == poll.author:
poll.delete_instance(recursive=True) poll.delete_instance(recursive=True)
await interaction.message.delete() await interaction.message.delete()
......
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