Skip to content

Commit

Permalink
Fixing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrogman committed Nov 21, 2024
1 parent 0312abf commit 821b713
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
20 changes: 12 additions & 8 deletions managarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,54 +43,58 @@ async def on_ready():
@bot.tree.command(name="payment_received", description="Update user's paid amount and extend end date")
@app_commands.describe(user="User identifier (Discord user, email address, or paymentPerson)", amount="Payment amount (float)")
async def payment_received(ctx, *, user: str, amount: float):
await ctx.response.defer(ephemeral=True)
search_results = dbFunctions.find_user(user)
if not search_results:
await ctx.response.send_message(f"{ctx.user.name} No user found matching the given identifier: {user}")
await ctx.followup.send(f"{ctx.user.name} No user found matching the given identifier: {user}")
return
information = {'what': 'payment', 'paymentAmount': amount}
await ctx.response.send_message("Select the correct user", view=viewFunctions.UpdateSelectorView(search_results, information), ephemeral=True)
await ctx.followup.send("Select the correct user", view=viewFunctions.UpdateSelectorView(search_results, information), ephemeral=True)


@bot.tree.command(name="add_new_user", description="Add new user to DB")
@app_commands.describe(discorduser="Discord Username; Put none or na if user not on Discord", email="User email address", payment_person="The name on the payment", amount="Payment amount (float)")
async def add_new_user(ctx, *, discorduser: str = "none", email: str, payment_person: str, amount: float):
await ctx.response.defer(ephemeral=True)
information = {'what': 'newuser', 'primaryEmail': email, 'paidAmount': amount, 'paymentPerson': payment_person}
await ctx.response.send_message("Confirm Discord User", view=discordFunctions.DiscordUserView(information, ctx, discorduser), ephemeral=True)
await ctx.followup.send("Confirm Discord User", view=viewFunctions.DiscordUserView(information, ctx, discorduser), ephemeral=True)


# Bot command to "Change a user's subscription (change server or add/remove 4k library)"
@bot.tree.command(name="move_user", description="Update user's plex libraries")
@app_commands.describe(user="User identifier (Discord user, email address, or paymentPerson)", amount="Payment amount (float)")
async def move_user(ctx, *, user: str, amount: float = None):
await ctx.response.defer(ephemeral=True)
search_results = dbFunctions.find_user(user)
if not search_results:
await ctx.response.send_message(f"No user found matching the given identifier: {user}", ephemeral=True)
await ctx.followup.send(f"No user found matching the given identifier: {user}", ephemeral=True)
return
information = {'what': 'move', 'paymentAmount': amount}
await ctx.response.send_message("Select the correct user", view=viewFunctions.UpdateSelectorView(search_results, information), ephemeral=True)
await ctx.followup.send("Select the correct user", view=viewFunctions.UpdateSelectorView(search_results, information), ephemeral=True)


# Bot command to add a new Plex server
@bot.tree.command(name="add_plex_server", description="Add a new Plex server to the configuration")
@app_commands.describe(email="Plex account email", password="Plex account password")
async def add_plex_server(ctx, *, email: str, password: str):
await ctx.response.defer(ephemeral=True)
try:
account = MyPlexAccount(email, password)
servers = account.resources()
except Exception as e:
await ctx.response.send_message(f"Error: {str(e)}", ephemeral=True)
await ctx.followup.send(f"Error: {str(e)}", ephemeral=True)
return

# Filter the resources to get only servers
servers = [server for server in servers if 'server' in server.provides]

if not servers:
await ctx.response.send_message("No servers found. Please check your credentials.", ephemeral=True)
await ctx.followup.send("No servers found. Please check your credentials.", ephemeral=True)
return

view = View()
view.add_item(selectFunctions.ServerSelect(ctx, servers))
await ctx.response.send_message("Choose a Plex server:", view=view, ephemeral=True)
await ctx.followup.send("Choose a Plex server:", view=view, ephemeral=True)


bot.run(bot_token)
8 changes: 4 additions & 4 deletions modules/selectFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async def handle_payment(self, interaction):
f"Term Length: {self.information.get('termLength')}\n"
)

confirmation_view = managarr.ConfirmButtonsNewUser(interaction, self.information)
confirmation_view = viewFunctions.ConfirmButtonsNewUser(interaction, self.information)
await interaction.response.edit_message(content=confirmation_message, view=confirmation_view)

async def handle_move(self, interaction):
Expand All @@ -165,7 +165,7 @@ async def handle_move(self, interaction):
f"End Date: {self.information.get('endDate')}\n"
)

confirmation_view = managarr.ConfirmButtonsMoveUser(interaction, self.information)
confirmation_view = viewFunctions.ConfirmButtonsMoveUser(interaction, self.information)
await interaction.response.edit_message(content=confirmation_message, view=confirmation_view)

async def handle_new_user(self, interaction):
Expand All @@ -187,7 +187,7 @@ async def handle_new_user(self, interaction):
f"Term Length: {self.information.get('termLength')}\n"
)

confirmation_view = managarr.ConfirmButtonsNewUser(interaction, self.information)
confirmation_view = viewFunctions.ConfirmButtonsNewUser(interaction, self.information)
await interaction.response.edit_message(content=confirmation_message, view=confirmation_view)


Expand Down Expand Up @@ -243,4 +243,4 @@ async def callback(self, interaction: discord.Interaction):
else:
await interaction.response.send_message("Failed to find selected user, please try again.", ephemeral=True)
return
await interaction.response.edit_message(content="Select the payment method", view=mathFunctions.PaymentMethodView(self.information))
await interaction.response.edit_message(content="Select the payment method", view=viewFunctions.PaymentMethodView(self.information))

0 comments on commit 821b713

Please sign in to comment.