Skip to content

Commit

Permalink
add help command
Browse files Browse the repository at this point in the history
  • Loading branch information
squi-ddy committed Jan 27, 2024
1 parent aa1edce commit 39cc536
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 38 deletions.
66 changes: 33 additions & 33 deletions bot/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bot/src/cogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
from .nick import Nick
from .projects import Projects
from .ui_helper import UIHelper
from .help import Help

__all__ = ["Nick", "MemberManagement", "Cache", "UIHelper", "MSAuth", "GithubAuth", "Projects", "JSONCache"]
__all__ = ["Nick", "MemberManagement", "Cache", "UIHelper", "MSAuth", "GithubAuth", "Projects", "JSONCache", "Help"]
56 changes: 56 additions & 0 deletions bot/src/cogs/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from nextcord import Interaction
from nextcord.ext.commands import Cog, Bot
from .cache import Cache
from config import config

from utils.access_control_decorators import is_in_server

class Help(Cog):
__slots__ = "bot", "cache"

def __init__(self, bot: Bot, cache: Cache):
self.bot = bot
self.cache = cache

def get_commands_members(self):
return [
("/nick", "Send a request to change your server name"),
("/ms verify", "Start the email verification process"),
("/gh verify", "Link with your GitHub account"),
]

def get_commands_exco(self):
return self.get_commands_members() + [
("/members import", "Import new members from a csv (make sure to do this before new members join!)"),
("/members export", "Export members to a csv"),
("/members refresh", "Give alumni role to members who have graduated"),
("/members modify_year", "Modify the year of a member (retained people)"),
("/members leave", "Give someone guest role, removing member role"),
("/ms manual_verify", "Manually verify someone's email"),
("/projects create", "Create a new project"),
("/projects delete", "Delete a project"),
("/projects import", "Add an existing project to the database"),
("/projects link", "Link a project to GitHub"),
("/projects share", "Share project GitHub repo to members"),
("/projects export", "Export all projects and member assignments"),
("/projects archive", "Archive a project")
]

@is_in_server(description="Get help on the commands")
async def help(self, interaction: Interaction):
if not interaction.user or not (member := self.cache.guild.get_member(interaction.user.id)):
raise RuntimeError("Interaction had invalid user!")

if member.get_role(config.exco_role):
commands = self.get_commands_exco()
else:
commands = self.get_commands_members()

commands = "\n".join([f"> `{command}`\n{description}\n" for command, description in commands])

await interaction.response.send_message(
f"Here are the commands you can use:\n\n{commands}",
ephemeral=True
)

__all__ = ["Help"]
2 changes: 1 addition & 1 deletion bot/src/cogs/member_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def refresh(self, interaction: Interaction) -> None:

await interaction.send(content=f"Done! {updated} people graduated.")

@subcommand(members, description="Modify a member's year (for retained people)", name="modify-year")
@subcommand(members, description="Modify a member's year (for retained people)")
async def modify_year(
self,
interaction: Interaction,
Expand Down
10 changes: 7 additions & 3 deletions bot/src/cogs/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ async def link(

await interaction.send("Project linked successfully!")

@subcommand(project, description="Share a GitHub repo with a user")
@subcommand(project, description="Share GitHub repo with project members")
async def share(
self,
interaction: Interaction,
Expand Down Expand Up @@ -323,10 +323,14 @@ async def share(

members = role.members
github_names = []
no_github = []

for member in members:
github_name = database.get_github(member.id) # type: ignore
github_names.append(github_name)
if (not github_name):
no_github.append(member.display_name)
continue
github_names.append(github_name.github)

for contributor in repo.get_contributors():
if contributor.login in github_names:
Expand All @@ -336,7 +340,7 @@ async def share(
for github_name in github_names:
repo.add_to_collaborators(github_name, permission="maintain")

await interaction.send(f"Project shared to ```{', '.join(github_names)}```")
await interaction.send(f"Project shared to ```{', '.join(github_names)}``` (no GitHub linked: ```{', '.join(no_github)}```)")

@subcommand(project, description="Export all projects and member assignments")
async def export(self, interaction: Interaction) -> None:
Expand Down
2 changes: 2 additions & 0 deletions bot/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Nick,
Projects,
UIHelper,
Help
)
from config import config
from nextcord import Intents
Expand Down Expand Up @@ -42,6 +43,7 @@ def main() -> None:
bot.add_cog(MemberManagement(bot, cache))
bot.add_cog(Nick(bot, cache, ui_helper))
bot.add_cog(Projects(bot, cache, ui_helper, github_auth))
bot.add_cog(Help(bot, cache))

ipc_server.start()

Expand Down

0 comments on commit 39cc536

Please sign in to comment.