Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor role ids into config (fixed conflicts) #39

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
674 changes: 674 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

132 changes: 132 additions & 0 deletions gitignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
.vscode/
.idea/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
8 changes: 7 additions & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@

load_dotenv()

TOKEN = os.environ.get("TOKEN") # required
TOKEN = os.environ.get("TOKEN") # required
DEBUG = os.environ.get("DEBUG", False)

ROLE_IDS = (
("Webgroup", "1166751688598761583"),
("Gamez", "1089204642241581139"),
("Croomer", "1172696659097047050"),
)

CHANNEL_IDS = {
"lobby": "627542044390457350"
}
50 changes: 25 additions & 25 deletions src/extensions/uptime.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from datetime import datetime
import arc
start_time = datetime.now()
plugin = arc.GatewayPlugin("Blockbot Uptime")
@plugin.include
@arc.slash_command("uptime", "Show formatted uptime of Blockbot")
async def uptime(ctx):
up_time = datetime.now() - start_time
d = up_time.days
h, ms = divmod(up_time.seconds, 3600)
m, s = divmod(ms, 60)
format = lambda val, str: f"{val} {str}{'s' if val != 1 else ''}"
message_parts = [(d, "day"), (h, "hour"), (m, "minute"), (s, "second")]
formatted_parts = [format(val, str) for val, str in message_parts if val]
await ctx.respond(f"Uptime: **{', '.join(formatted_parts)}**")
@arc.loader
def loader(client):
client.add_plugin(plugin)
from datetime import datetime

import arc

start_time = datetime.now()

plugin = arc.GatewayPlugin("Blockbot Uptime")

@plugin.include
@arc.slash_command("uptime", "Show formatted uptime of Blockbot")
async def uptime(ctx):
up_time = datetime.now() - start_time
d = up_time.days
h, ms = divmod(up_time.seconds, 3600)
m, s = divmod(ms, 60)

format = lambda val, str: f"{val} {str}{'s' if val != 1 else ''}"
message_parts = [(d, "day"), (h, "hour"), (m, "minute"), (s, "second")]
formatted_parts = [format(val, str) for val, str in message_parts if val]

await ctx.respond(f"Uptime: **{', '.join(formatted_parts)}**")

@arc.loader
def loader(client):
client.add_plugin(plugin)
17 changes: 7 additions & 10 deletions src/extensions/user_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
import hikari

from src.utils import role_mention
from src.config import ROLE_IDS

plugin = arc.GatewayPlugin(name="User Roles")
plugin = arc.GatewayPlugin("User Roles")

role = plugin.include_slash_group("role", "Get/remove assignable roles.")

role_choices = [
hikari.CommandChoice(name="Webgroup", value="1166751688598761583"),
hikari.CommandChoice(name="Gamez", value="1089204642241581139"),
hikari.CommandChoice(name="Croomer", value="1172696659097047050"),
]
ROLE_CHOICES = [hikari.CommandChoice(name=name, value=value) for name,value in ROLE_IDS] # ROLE_IDS <- ROLE_CHOICES into CommandChoice-es; thus ROLE_CHOICES can just store easy-to-update tuples

@role.include
@arc.slash_subcommand("add", "Add an assignable role.")
async def add_role(
ctx: arc.GatewayContext,
role: arc.Option[str, arc.StrParams("The role to add.", choices=role_choices)]
role: arc.Option[str, arc.StrParams("The role to add.", choices=ROLE_CHOICES)]
) -> None:
assert ctx.guild_id
assert ctx.member
Expand All @@ -40,7 +37,7 @@ async def add_role(
@arc.slash_subcommand("remove", "Remove an assignable role.")
async def remove_role(
ctx: arc.GatewayContext,
role: arc.Option[str, arc.StrParams("The role to remove.", choices=role_choices)]
role: arc.Option[str, arc.StrParams("The role to remove.", choices=ROLE_CHOICES)]
) -> None:
assert ctx.guild_id
assert ctx.member
Expand Down Expand Up @@ -69,7 +66,7 @@ async def role_error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
f"❌ Blockbot is not permitted to self-service the {role_mention(role)} role.",
flags=hikari.MessageFlag.EPHEMERAL
)

if isinstance(exc, hikari.NotFoundError):
return await ctx.respond(
f"❌ Blockbot can't find that role.",
Expand All @@ -80,4 +77,4 @@ async def role_error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:

@arc.loader
def loader(client: arc.GatewayClient) -> None:
client.add_plugin(plugin)
client.add_plugin(plugin)
16 changes: 8 additions & 8 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import hikari
from arc import GatewayClient

async def get_guild(client: GatewayClient, event: hikari.GuildMessageCreateEvent):
return event.get_guild() or await client.rest.fetch_guild(event.guild_id)

def role_mention(role_id: hikari.Snowflake | int | str):
return f"<@&{role_id}>"
import hikari
from arc import GatewayClient
async def get_guild(client: GatewayClient, event: hikari.GuildMessageCreateEvent):
return event.get_guild() or await client.rest.fetch_guild(event.guild_id)
def role_mention(role_id: hikari.Snowflake | int | str):
return f"<@&{role_id}>"
Loading