Skip to content

Commit

Permalink
adjusting so funcationality is restored.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrogman committed Nov 21, 2024
1 parent d0bfd5b commit ad00701
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 34 deletions.
7 changes: 4 additions & 3 deletions managarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from discord import app_commands
from discord.ext import commands
from discord.ui import Select, View, Button
from modules import dbFunctions, discordFunctions, configFunctions, mathFunctions, emailFunctions, selectFunctions
from modules import globalBot, dbFunctions, discordFunctions, configFunctions, selectFunctions, viewFunctions

bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
globalBot.bot = bot

# Set up logging to both console and file
log_file = "/config/managarr.log"
Expand Down Expand Up @@ -45,7 +46,7 @@ async def payment_received(ctx, *, user: str, amount: float):
await ctx.response.send_message(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=UpdateSelectorView(search_results, information), ephemeral=True)
await ctx.response.send_message("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")
Expand All @@ -64,7 +65,7 @@ async def move_user(ctx, *, user: str, amount: float = None):
await ctx.response.send_message(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=UpdateSelectorView(search_results, information), ephemeral=True)
await ctx.response.send_message("Select the correct user", view=viewFunctions.UpdateSelectorView(search_results, information), ephemeral=True)


# Bot command to add a new Plex server
Expand Down
Empty file added modules/__init__.py
Empty file.
3 changes: 1 addition & 2 deletions modules/discordFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from discord import Embed
from discord.ext import commands
from modules import configFunctions
from modules.globalBot import bot


config_location = "/config/config.yml"
config = configFunctions.get_config(config_location)

bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())


async def add_role(user_id, role_name):
guild_id = int(config['discord']['guildId'])
Expand Down
1 change: 1 addition & 0 deletions modules/globalBot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bot = None
27 changes: 0 additions & 27 deletions modules/selectFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,6 @@
config_location = "/config/config.yml"
config = configFunctions.get_config(config_location)

class UpdateSelector(Select):
def __init__(self, search_results, information):
self.search_results = search_results
self.information = information
max_options = 10
options = [
discord.SelectOption(
label=f"{user['paymentPerson']} | {user['server']} ({user['status']})",
value=str(idx),
description=f"Discord: {user['primaryDiscord'] if user['primaryDiscord'] else 'N/A'} | Email: {user['primaryEmail']}",
emoji="👤"
)
for idx, user in enumerate(search_results[:max_options])
]
max_values = min(len(search_results), max_options)
super().__init__(placeholder="Please select the user", options=options, min_values=1, max_values=max_values)

async def callback(self, interaction: discord.Interaction):
selected_user_indices = [int(value) for value in self.values]
selected_users = [self.search_results[idx] for idx in selected_user_indices]
self.information.setdefault('users', []).extend(selected_users)

if self.information['what'] == 'payment':
await self.view.handle_payment(interaction, selected_users)
elif self.information['what'] == 'move':
await self.view.handle_move(interaction, selected_users)


class ServerSelect(Select):
def __init__(self, interaction, servers):
Expand Down
30 changes: 30 additions & 0 deletions modules/sharedFunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import discord
from discord.ui import Select


class UpdateSelector(Select):
def __init__(self, search_results, information):
self.search_results = search_results
self.information = information
max_options = 10
options = [
discord.SelectOption(
label=f"{user['paymentPerson']} | {user['server']} ({user['status']})",
value=str(idx),
description=f"Discord: {user['primaryDiscord'] if user['primaryDiscord'] else 'N/A'} | Email: {user['primaryEmail']}",
emoji="👤"
)
for idx, user in enumerate(search_results[:max_options])
]
max_values = min(len(search_results), max_options)
super().__init__(placeholder="Please select the user", options=options, min_values=1, max_values=max_values)

async def callback(self, interaction: discord.Interaction):
selected_user_indices = [int(value) for value in self.values]
selected_users = [self.search_results[idx] for idx in selected_user_indices]
self.information.setdefault('users', []).extend(selected_users)

if self.information['what'] == 'payment':
await self.view.handle_payment(interaction, selected_users)
elif self.information['what'] == 'move':
await self.view.handle_move(interaction, selected_users)
4 changes: 2 additions & 2 deletions modules/viewFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from discord.ui import View, Button
from datetime import datetime
from dateutil.relativedelta import relativedelta
from modules import configFunctions, discordFunctions, dbFunctions, emailFunctions, selectFunctions
from modules import configFunctions, discordFunctions, dbFunctions, emailFunctions, selectFunctions, sharedFunctions


config_location = "/config/config.yml"
Expand Down Expand Up @@ -323,7 +323,7 @@ def __init__(self, search_results, information):
super().__init__()
self.search_results = search_results
self.information = information
self.add_item(selectFunctions.UpdateSelector(search_results, information))
self.add_item(sharedFunctions.UpdateSelector(search_results, information))

async def handle_payment(self, interaction, selected_users):
user_count = len(self.information.get('users', []))
Expand Down

0 comments on commit ad00701

Please sign in to comment.