Skip to content

Commit

Permalink
build discord commands with a .yaml file instead of a big inline blob
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoc committed Nov 7, 2024
1 parent 82beffa commit b4ebe0a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 113 deletions.
121 changes: 8 additions & 113 deletions apps/discord/management/commands/commands.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import requests
import yaml
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from pathlib import Path
from pprint import pformat

from apps.players.models.game_type import GameType


class Command(BaseCommand):
"""Get Discord bot commands."""
Expand Down Expand Up @@ -45,117 +45,12 @@ def handle(self, *args, **options):
)
)

all_commands = [
{
"type": 1,
"name": "challenges",
"description": "Link to the list of MUD challenges.",
},
{
"type": 1,
"name": "cycle",
"description": "Show when challenges will cycle next.",
},
{
"type": 1,
"name": "deadhead",
"description": "Show the player with the most deaths.",
},
{
"type": 1,
"name": "events",
"description": "Show any active events.",
},
{
"type": 1,
"name": "faq",
"description": "Link to frequently asked questions (FAQs).",
},
{
"type": 1,
"name": "feedback",
"description":
"Link to feedback page to send bug report,"
" idea, or suggestion.",
},
{
"name": "leader",
"type": 1,
"description": "List the leading player, by game type.",
"options": [{
"name": "type",
"description": "Game type to find the leader of.",
"type": 3,
"required": False,
"choices": [
{
"name": "Classic",
"value": str(GameType.CLASSIC.value)
},
{
"name": "Hardcore",
"value": str(GameType.HARDCORE.value)
},
{
"name": "Survival",
"value": str(GameType.SURVIVAL.value)
}
]
}]
},
{
"type": 1,
"name": "leaders",
"description": "Link to the list of leading MUD players.",
},
{
"type": 1,
"name": "mudhelp",
"description": "Search MUD help for a topic.",
"options": [
{
"name": "topic",
"description": "Name of the help topic to search for.",
"type": 3,
"required": True,
}
],
},
{
"type": 1,
"name": "mudtime",
"description": "Show current server time.",
},
{
"type": 1,
"name": "runtime",
"description": "Show current server runtime.",
},
{
"type": 1,
"name": "season",
"description": "Show the current season.",
},
{
"type": 1,
"name": "spell",
"description": "Search MUD help for a spell.",
"options": [
{
"name": "spell",
"description": "Name of the spell to search for.",
"type": 3,
"required": True,
}
],
},
{
"type": 1,
"name": "upgrades",
"description":
"Link to available remort upgrades and their renown costs."
},
]
with open(
file=Path(Path(__file__).parent, "commands.yaml"),
mode="r",
encoding="utf-8"
) as cmd_yml:
all_commands = yaml.safe_load(cmd_yml)

reg = requests.put(
url=discord_url,
Expand Down
80 changes: 80 additions & 0 deletions apps/discord/management/commands/commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---

- name: "challenges"
description: "Link to the list of MUD challenges."
type: 1

- name: "cycle"
description: "Show when challenges will cycle next."
type: 1

- name: "deadhead"
description: "Show the player with the most deaths."
type: 1

- description: "Show any active events."
name: "events"
type: 1

- description: "Link to frequently asked questions (FAQs)."
name: "faq"
type: 1

- description: "Link to feedback page to send bug report, idea, or suggestion."
name: "feedback"
type: 1

- name: "leader"
description: "List the leading player, by game type."
options:
- name: "type"
choices:
- name: "Classic"
value: "0"
- name: "Hardcore"
value: "1"
- name: "Survival"
value: "2"
description: "Game type to find the leader of."
required: false
type: 3
type: 1

- name: "leaders"
description: "Link to the list of leading MUD players."
type: 1

- name: "mudhelp"
description: "Search MUD help for a topic."
options:
- name: "topic"
description: "Name of the help topic to search for."
required: true
type: 3
type: 1

- name: "mudtime"
description: "Show current server time."
type: 1

- name: "runtime"
description: "Show current server runtime."
type: 1

- name: "season"
description: "Show the current season."
type: 1

- name: "spell"
description: Search MUD help for a spell."
options:
- description: "Name of the spell to search for."
name: "spell"
required: true
type: 3
type: 1

- name: "upgrades"
description: "Link to available remort upgrades and their renown costs."
type: 1

0 comments on commit b4ebe0a

Please sign in to comment.