Skip to content

Commit

Permalink
Revert "Adding youtube notifications validations"
Browse files Browse the repository at this point in the history
This reverts commit c6b6a1a.
  • Loading branch information
rukasudev committed Jan 8, 2025
1 parent 14dcc67 commit 2a6ac4d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 44 deletions.
10 changes: 0 additions & 10 deletions app/components/modals.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,3 @@ def validate_streamer_name(self, response: str) -> bool:

ok = bot.twitch.get_user_id_from_login(response) is not None
return {"ok": ok, "error_key": "streamer-not-found"}

def validate_youtube_channel(self, response: str) -> bool:
from app import bot

for item in self.cogs:
if response.lower() == item.get("youtuber").get("value").lower():
return {"ok": False, "error_key": "youtuber-already-registered"}

ok = bot.youtube.get_channel_id_from_username(response) is not None
return {"ok": ok, "error_key": "youtuber-not-found"}
8 changes: 0 additions & 8 deletions app/languages/errors/errors.en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,3 @@ en-us:
streamer-already-registered:
title: Streamer Already Registered
message: "The notification of this streamer's lives is already set up on this server. Please, select another streamer and try again."

youtuber-already-registered:
title: Youtuber Already Registered
message: "The notification of this youtuber's videos is already set up on this server. Please, select another youtuber and try again."

youtube-channel-not-found:
title: Youtuber Not Found
message: "I'm sorry, but I couldn't find the youtuber you're looking for. Please, check the name and try again."
8 changes: 0 additions & 8 deletions app/languages/errors/errors.pt-br.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,3 @@ pt-br:
streamer-already-registered:
title: Streamer Já Registrado
message: "A notificação das lives desse streamer já está configurada nesse servidor. Por favor, selecione outro streamer e tente novamente."

youtuber-already-registered:
title: Youtuber Já Registrado
message: "A notificação dos vídeos desse youtuber já está configurada nesse servidor. Por favor, selecione outro youtuber e tente novamente."

youtuber-not-found:
title: Youtuber Não Encontrado
message: "Desculpe, mas não consegui encontrar o youtuber que você está procurando. Por favor, verifique o nome e tente novamente."
1 change: 0 additions & 1 deletion app/languages/form/notifications_youtube_video.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ steps:
- action: modal
key: youtuber
max_length: 30
validation: validate_youtube_channel
lowercase: true
title:
en-us: Youtuber
Expand Down
20 changes: 3 additions & 17 deletions app/views/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from app.services.cogs import insert_cog_by_guild, insert_cog_event
from app.services.moderations import update_moderations_by_guild
from app.services.notifications_twitch import unsubscribe_streamer
from app.services.notifications_youtube_video import unsubscribe_youtube_new_video
from app.services.utils import (
get_available_roles_by_guild,
get_form_settings_with_database_values,
Expand Down Expand Up @@ -69,7 +68,7 @@ async def update_counter(self, args):
try:
self._step = next(self.steps)
except StopIteration:
await self.pre_finish_step(args)
self.pre_finish_step(args)
return await self._after_callback(args)

self.step_embed = parse_form_dict_to_embed(self._step, self.locale)
Expand Down Expand Up @@ -297,7 +296,7 @@ async def _finish(self, interaction: discord.Interaction):

interaction.locale = parse_valid_locale(interaction.locale)
cog_param = self._parse_responses_to_cog()
await self.pre_finish_step(interaction)
self.pre_finish_step(interaction)

update_moderations_by_guild(
guild_id=interaction.guild_id, key=self.command_key, value=True
Expand Down Expand Up @@ -336,10 +335,7 @@ async def _finish(self, interaction: discord.Interaction):

await interaction.followup.send(embed=embed, view=self)

async def pre_finish_step(self, interaction: discord.Interaction):
if not interaction.response._response_type:
await interaction.response.defer(thinking=True, ephemeral=True)

def pre_finish_step(self, interaction: discord.Interaction):
if self.command_key == commandconstants.NOTIFICATIONS_TWITCH_KEY:
from app.services.notifications_twitch import subscribe_streamer
self.handle_streamer_change(interaction)
Expand All @@ -348,18 +344,8 @@ async def pre_finish_step(self, interaction: discord.Interaction):
from app.services.notifications_youtube_video import (
subscribe_youtube_new_video,
)
self.handle_youtuber_change(interaction)
subscribe_youtube_new_video(interaction, self.responses)

def handle_youtuber_change(self, interaction: discord.Interaction):
if not hasattr(self, "composition_index"):
return

old_youtuber = self.view.form_view.cogs
new_youtuber = self.responses[0]["value"][self.composition_index]
if old_youtuber["youtuber"]["value"] != new_youtuber:
unsubscribe_youtube_new_video(interaction, old_youtuber)

def handle_streamer_change(self, interaction: discord.Interaction):
if not hasattr(self, "composition_index"):
return
Expand Down
4 changes: 4 additions & 0 deletions app/views/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def __init__(


async def update_command(self, interaction: discord.Interaction):
await interaction.response.defer(thinking=True, ephemeral=True)

data = self.edited_form_view._parse_responses_to_cog()

update_cog_by_guild(interaction.guild_id, self.command_key, data)
Expand Down Expand Up @@ -243,6 +245,8 @@ def handle_add_item_button(self) -> None:
return self.add_item(AddItemButton(self.add_item_callback, locale=self.locale))

async def add_item_callback(self, interaction: discord.Interaction):
await interaction.response.defer(thinking=True, ephemeral=True)

response = self.form_view._parse_responses_to_cog()[constants.COMMAND_KEY_TO_COMPOSITION_KEY[self.command_key]].get("values")[0]
self.cogs[constants.COMMAND_KEY_TO_COMPOSITION_KEY[self.command_key]]["values"].append(response)

Expand Down

0 comments on commit 2a6ac4d

Please sign in to comment.