Skip to content

Commit b4ebe0a

Browse files
committed
build discord commands with a .yaml file instead of a big inline blob
1 parent 82beffa commit b4ebe0a

File tree

2 files changed

+88
-113
lines changed

2 files changed

+88
-113
lines changed

apps/discord/management/commands/commands.py

Lines changed: 8 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import requests
2+
import yaml
23
from django.conf import settings
34
from django.core.management.base import BaseCommand, CommandError
5+
from pathlib import Path
46
from pprint import pformat
57

6-
from apps.players.models.game_type import GameType
7-
88

99
class Command(BaseCommand):
1010
"""Get Discord bot commands."""
@@ -45,117 +45,12 @@ def handle(self, *args, **options):
4545
)
4646
)
4747

48-
all_commands = [
49-
{
50-
"type": 1,
51-
"name": "challenges",
52-
"description": "Link to the list of MUD challenges.",
53-
},
54-
{
55-
"type": 1,
56-
"name": "cycle",
57-
"description": "Show when challenges will cycle next.",
58-
},
59-
{
60-
"type": 1,
61-
"name": "deadhead",
62-
"description": "Show the player with the most deaths.",
63-
},
64-
{
65-
"type": 1,
66-
"name": "events",
67-
"description": "Show any active events.",
68-
},
69-
{
70-
"type": 1,
71-
"name": "faq",
72-
"description": "Link to frequently asked questions (FAQs).",
73-
},
74-
{
75-
"type": 1,
76-
"name": "feedback",
77-
"description":
78-
"Link to feedback page to send bug report,"
79-
" idea, or suggestion.",
80-
},
81-
{
82-
"name": "leader",
83-
"type": 1,
84-
"description": "List the leading player, by game type.",
85-
"options": [{
86-
"name": "type",
87-
"description": "Game type to find the leader of.",
88-
"type": 3,
89-
"required": False,
90-
"choices": [
91-
{
92-
"name": "Classic",
93-
"value": str(GameType.CLASSIC.value)
94-
},
95-
{
96-
"name": "Hardcore",
97-
"value": str(GameType.HARDCORE.value)
98-
},
99-
{
100-
"name": "Survival",
101-
"value": str(GameType.SURVIVAL.value)
102-
}
103-
]
104-
}]
105-
},
106-
{
107-
"type": 1,
108-
"name": "leaders",
109-
"description": "Link to the list of leading MUD players.",
110-
},
111-
{
112-
"type": 1,
113-
"name": "mudhelp",
114-
"description": "Search MUD help for a topic.",
115-
"options": [
116-
{
117-
"name": "topic",
118-
"description": "Name of the help topic to search for.",
119-
"type": 3,
120-
"required": True,
121-
}
122-
],
123-
},
124-
{
125-
"type": 1,
126-
"name": "mudtime",
127-
"description": "Show current server time.",
128-
},
129-
{
130-
"type": 1,
131-
"name": "runtime",
132-
"description": "Show current server runtime.",
133-
},
134-
{
135-
"type": 1,
136-
"name": "season",
137-
"description": "Show the current season.",
138-
},
139-
{
140-
"type": 1,
141-
"name": "spell",
142-
"description": "Search MUD help for a spell.",
143-
"options": [
144-
{
145-
"name": "spell",
146-
"description": "Name of the spell to search for.",
147-
"type": 3,
148-
"required": True,
149-
}
150-
],
151-
},
152-
{
153-
"type": 1,
154-
"name": "upgrades",
155-
"description":
156-
"Link to available remort upgrades and their renown costs."
157-
},
158-
]
48+
with open(
49+
file=Path(Path(__file__).parent, "commands.yaml"),
50+
mode="r",
51+
encoding="utf-8"
52+
) as cmd_yml:
53+
all_commands = yaml.safe_load(cmd_yml)
15954

16055
reg = requests.put(
16156
url=discord_url,
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
3+
- name: "challenges"
4+
description: "Link to the list of MUD challenges."
5+
type: 1
6+
7+
- name: "cycle"
8+
description: "Show when challenges will cycle next."
9+
type: 1
10+
11+
- name: "deadhead"
12+
description: "Show the player with the most deaths."
13+
type: 1
14+
15+
- description: "Show any active events."
16+
name: "events"
17+
type: 1
18+
19+
- description: "Link to frequently asked questions (FAQs)."
20+
name: "faq"
21+
type: 1
22+
23+
- description: "Link to feedback page to send bug report, idea, or suggestion."
24+
name: "feedback"
25+
type: 1
26+
27+
- name: "leader"
28+
description: "List the leading player, by game type."
29+
options:
30+
- name: "type"
31+
choices:
32+
- name: "Classic"
33+
value: "0"
34+
- name: "Hardcore"
35+
value: "1"
36+
- name: "Survival"
37+
value: "2"
38+
description: "Game type to find the leader of."
39+
required: false
40+
type: 3
41+
type: 1
42+
43+
- name: "leaders"
44+
description: "Link to the list of leading MUD players."
45+
type: 1
46+
47+
- name: "mudhelp"
48+
description: "Search MUD help for a topic."
49+
options:
50+
- name: "topic"
51+
description: "Name of the help topic to search for."
52+
required: true
53+
type: 3
54+
type: 1
55+
56+
- name: "mudtime"
57+
description: "Show current server time."
58+
type: 1
59+
60+
- name: "runtime"
61+
description: "Show current server runtime."
62+
type: 1
63+
64+
- name: "season"
65+
description: "Show the current season."
66+
type: 1
67+
68+
- name: "spell"
69+
description: Search MUD help for a spell."
70+
options:
71+
- description: "Name of the spell to search for."
72+
name: "spell"
73+
required: true
74+
type: 3
75+
type: 1
76+
77+
- name: "upgrades"
78+
description: "Link to available remort upgrades and their renown costs."
79+
type: 1
80+

0 commit comments

Comments
 (0)