fix(bot): 🐛 Attempt to fix p.hangup.

This commit is contained in:
Nyeki.py
2024-10-18 00:35:32 -03:00
parent 7fd0801d78
commit 8cd1613e3c
2 changed files with 25 additions and 10 deletions
+13 -4
View File
@@ -5,19 +5,28 @@ import discord
from payphone.db import models
async def get_channel(channel: discord.TextChannel) -> models.Channel:
async def get_channel(
channel: discord.TextChannel, for_update: bool = False
) -> models.Channel:
"""Returns a channel from the database, creating or updating it if it already exists.
Args:
channel (discord.TextChannel): The channel to fetch.
for_update (bool, optional): Whether the select should be FOR UPDATE or not.
Returns:
models.Channel: The channel row.
"""
row, _ = await models.Channel.update_or_create(
id=channel.id, server=channel.guild.id
)
model = models.Channel
if for_update:
model = model.select_for_update()
row = await model.get_or_none(id=channel.id)
if row is None:
row = await models.Channel.create(id=channel.id, server_id=channel.guild.id)
channel_name = channel.name.replace("discord", "d").replace("wumpus", "w")
webhook_name = f"Payphone #{channel_name}"