-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from srobo/kjk/passwords
Store passwords in a JSON file rather than in a channel
- Loading branch information
Showing
6 changed files
with
80 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
log.log | ||
.env | ||
seen_posts.txt | ||
passwords.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
import discord | ||
from discord import app_commands | ||
|
||
if TYPE_CHECKING: | ||
from src.bot import BotClient | ||
|
||
@app_commands.command( # type:ignore[arg-type] | ||
name='passwd', | ||
description='Outputs or changes team passwords', | ||
) | ||
@app_commands.describe( | ||
tla='Three Letter Acronym (e.g. SRZ)', | ||
new_password='New password', | ||
) | ||
async def passwd( | ||
interaction: discord.interactions.Interaction["BotClient"], | ||
tla: str | None = None, | ||
new_password: str | None = None, | ||
) -> None: | ||
if tla is None: | ||
await interaction.response.send_message( | ||
'\n'.join([f"**{team}:** {password}" for team, password in interaction.client.passwords.items()]), | ||
ephemeral=True, | ||
) | ||
else: | ||
if new_password is not None: | ||
if isinstance(interaction.user, discord.Member) and not interaction.user.guild_permissions.administrator: | ||
await interaction.response.send_message( | ||
"You do not have permission to change team passwords.", | ||
ephemeral=True | ||
) | ||
return | ||
interaction.client.set_password(tla, new_password) | ||
await interaction.response.send_message(f"The password for {tla.upper()} has been changed.", ephemeral=True) | ||
else: | ||
password = interaction.client.passwords[tla] | ||
await interaction.response.send_message(f"The password for {tla.upper()} is `{password}`", ephemeral=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters