Skip to content

Commit

Permalink
added basic users cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
ghrlt committed Oct 17, 2023
1 parent f0f37a5 commit 9590781
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
30 changes: 26 additions & 4 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,32 @@ def saveInfos(userId: int, role: str|None, firstname: str|None, lastname: str|No
)
else:
env.logger.debug("Overwriting info for user %i", userId)
DATABASE_CURSOR.execute(
"UPDATE infos SET role = ?, firstname = ?, lastname = ?, email = ?, phone = ? WHERE user_id = ?",
(role, firstname, lastname, email, phone, userId)
)

if role != None:
DATABASE_CURSOR.execute(
"UPDATE infos SET role = ? WHERE user_id = ?",
(role, userId)
)
if firstname != None:
DATABASE_CURSOR.execute(
"UPDATE infos SET firstname = ? WHERE user_id = ?",
(firstname, userId)
)
if lastname != None:
DATABASE_CURSOR.execute(
"UPDATE infos SET lastname = ? WHERE user_id = ?",
(lastname, userId)
)
if email != None:
DATABASE_CURSOR.execute(
"UPDATE infos SET email = ? WHERE user_id = ?",
(email, userId)
)
if phone != None:
DATABASE_CURSOR.execute(
"UPDATE infos SET phone = ? WHERE user_id = ?",
(phone, userId)
)

DATABASE_CONNECTION.commit()

Expand Down
3 changes: 2 additions & 1 deletion slash_commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import configuration
from . import install
from . import admin
from . import admin
from . import users
44 changes: 44 additions & 0 deletions slash_commands/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from __main__ import bot, slash
import views
import database

import discord
from discord import app_commands




@app_commands.guild_only()
class Users(app_commands.Group):

@app_commands.command(name="set_username", description="Set user usernames")
async def _setUsername(
self, interaction: discord.Interaction,
user: discord.Member, username: str, app: str = 'global'
) -> None:
await interaction.response.defer(ephemeral=True)

database.saveCredentials(user.id, app, username)

await interaction.followup.send(
content="Successfully updated %s username for %s!" % (user.mention, app),
ephemeral=True
)

@app_commands.command(name="set_infos", description="Set user infos")
async def _setInfos(
self, interaction: discord.Interaction,
user: discord.Member, firstName: str|None, lastName: str|None,
email: str|None, phoneNumber: str|None,
) -> None:
await interaction.response.defer(ephemeral=True)

database.saveInfos(user.id, firstName, lastName, email, phoneNumber)

await interaction.followup.send(
content="Successfully updated %s infos!" % (user.mention),
ephemeral=True
)


slash.add_command(Users(name="users", description="Manage users"))

0 comments on commit 9590781

Please sign in to comment.