Skip to content

Commit a262e05

Browse files
committed
slash command localization
1 parent 02e0a1c commit a262e05

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE
3434
)
3535

3636
set_target_properties(${PROJECT_NAME} PROPERTIES
37-
CXX_STANDARD 20
37+
CXX_STANDARD 23
3838
CXX_STANDARD_REQUIRED ON
3939
)

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ It can be used for individual tenants.
1010
#### Build requirements
1111

1212
- [cmake](https://cmake.org/) (version 3.15+)
13-
- [g++](https://gcc.gnu.org) (version 8 or higher)
13+
- [g++](https://gcc.gnu.org) (version 14 or higher)
1414

1515
#### Included dependencies (in the `/libs` folder)
1616

@@ -47,7 +47,7 @@ make -j8
4747

4848
Tip: Replace the number after -j with the number of CPU cores available on your machine for optimal performance.
4949

50-
After the build process completes, an executable will be generated. You can execute this executable to start the Discord bot.
50+
After the build process completes, an executable named `Cordactyl_Bot` will be generated. You can execute this executable to start the Discord bot.
5151

5252
Before running the bot, make sure to set the following environment variables:
5353
- `BOT_TOKEN`
@@ -64,11 +64,15 @@ Description=Cordactyl Discord-Bot
6464
After=network.target
6565

6666
[Service]
67+
Type=simple
6768
WorkingDirectory=/path_to_project
6869
ExecStart=/build/Cordactyl_Bot
69-
Type=simple
70+
Environment="BOT_TOKEN=paste_your_discord_bot_token_here"
71+
Environment="API_TOKEN=paste_your_cordactyl_api_token_here"
7072
Restart=always
71-
# User=cordactyl # If you have setup a custom user for the discord-bot
73+
# exits with code 24 on invalid api token
74+
RestartPreventExitStatus=24
75+
User=cordactyl # If you have setup a custom user for the discord-bot
7276

7377
[Install]
7478
WantedBy=multi-user.target

lang/de.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
"Error. Couldn't generate a response. Please try again later.": "Fehler. Es konnte kein Link erstellt werden. Bitte versuche es später noch einmal.",
44
"The server is currently undergoing maintenance. Please try again later.": "Der Server wird derzeit gewartet. Bitte versuche es später noch einmal.",
55
"Cordactyl API error. Please try again later.": "Cordactyl API-Fehler. Bitte versuche es später noch einmal.",
6-
"You must be in a guild to use this command.": "Du kannst diesen Befehl nur in einem Server ausführen."
6+
"You must be in a guild to use this command.": "Du kannst diesen Befehl nur in einem Server ausführen.",
7+
"appeal": "entbannungsantrag",
8+
"Create an appeal": "Erstelle einen Entbannungsantrag"
79
}

src/class/acknowledge_payload.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ namespace cordactyl
3434
return result;
3535
}
3636

37-
dpp::task<void> acknowledge_payload::send_acknowledgement(processed_message_cache &processed_messages) {
37+
dpp::task<void> acknowledge_payload::send_acknowledgement(processed_message_cache &processed_messages, bool is_startup) {
3838
dpp::http_request_completion_t response = co_await bot.co_request(
39-
std::string(getenv("API_URL")) + "/acknowledge",
39+
std::string(getenv("API_URL")) + "/acknowledge" + (is_startup ? "?startup=true" : ""),
4040
dpp::m_post,
4141
this->pull_payload().dump(),
4242
"application/json",
4343
API_HEADERS
4444
);
4545
if (response.status == 401) {
4646
bot.log(dpp::ll_error, "Acknowledge failed. Invalid API_TOKEN");
47+
if (!getenv("IS_CENTRAL")) {
48+
exit(EXIT_INVALID_API_TOKEN);
49+
}
4750
} else if (response.status >= 300 || response.error != dpp::http_error::h_success) {
4851
bot.log(dpp::ll_error, "Acknowledge failed. Error: " + std::to_string(response.error) + " Status: " + std::to_string(response.status) + "\nResponse:\n" + response.body);
4952
}

src/class/acknowledge_payload.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace cordactyl
1818

1919
nlohmann::json pull_payload();
2020

21-
dpp::task<void> send_acknowledgement(processed_message_cache &processed_messages);
21+
dpp::task<void> send_acknowledgement(processed_message_cache &processed_messages, bool is_startup = false);
2222

2323
dpp::task<void> fetch_current_application();
2424

src/globals.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
{"Accept", "application/json"}, \
1010
{"User-Agent", "cordactyl-discord-bot/2.0"} \
1111
}
12+
#define EXIT_INVALID_API_TOKEN 24

src/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,16 @@ int main() {
6161

6262
if (dpp::run_once<struct startup>()) {
6363
co_await acknowledge.fetch_current_application();
64+
co_await acknowledge.send_acknowledgement(processed_messages, true);
6465
if (!getenv("IS_CENTRAL")) {
6566
acknowledge.edit_current_application();
6667
}
67-
bot.global_command_create(dpp::slashcommand("appeal", "Create an appeal", bot.me.id));
68+
69+
auto appeal_command = dpp::slashcommand("appeal", "Create an appeal", bot.me.id);
70+
for (auto &translation : cordactyl::translations) {
71+
appeal_command.add_localization(translation.first, cordactyl::_("appeal", translation.first), cordactyl::_("Create an appeal", translation.first));
72+
}
73+
bot.global_bulk_command_create({appeal_command});
6874

6975
acknowledge_timer = bot.start_timer([](const dpp::timer on_tick) -> dpp::task<void> {
7076
co_await acknowledge.send_acknowledgement(processed_messages);

0 commit comments

Comments
 (0)