Add /q command for converting Q-Code (case-insensitive) to Question/Answer combination

This commit is contained in:
2026-08-31 22:04:07 +02:00
parent c056b1b67a
commit 44d13ab071
7 changed files with 144 additions and 3 deletions
-2
View File
@@ -7,8 +7,6 @@
#include <hammy/job.h>
#include <hammy/refdb.h>
#include <dlibc/vector.h>
// The reply goes out as an embed description, which Discord caps at 4096
// characters, so the two halves get separate budgets that still leave room for
// the labels between them. Capping at all is what keeps an unbounded,
+39
View File
@@ -0,0 +1,39 @@
#include <concord/discord.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <hammy/command.h>
#include <hammy/job.h>
#include <hammy/refdb.h>
#include <hammy/utils.h>
#define HAMMY_QCODE_ECHO_MAX 16
#define HAMMY_QCODE_CODE_MAX 3072
#define HAMMY_QCODE_TRUNCATED " ... (truncated)"
void hammy_cmd_q(const hammy_job_t* job, struct discord* client, hammy_refdb_t* refdb) {
// Get the qcode argument from the job
const char* qcode = hammy_job_get_arg(job, "q-code");
if (!qcode) {
hammy_job_respond(job, client, "Error", "No text provided for Q-Code conversion.", true);
return;
}
char body[HAMMY_QCODE_CODE_MAX + sizeof(HAMMY_QCODE_TRUNCATED)]; // Generally, since the bottom pointers can only point to max 128-character strings (set as preprocesor header)
// So yeah - if we ever change the above for some reason to stupid values... yeah. Technically "unsafe" but yeah.
const char* questionStr = NULL;
const char* answerStr = NULL;
if (!hammy_refdb_get_qcode(refdb, qcode, &questionStr, &answerStr)) {
hammy_job_respond(job, client, "Q-Code Not Found!", "Failed to find the Q-Code specified. Please check your query!", true);
return;
}
hammy_to_uppercase(qcode);
snprintf(body, sizeof(body), "Q-Code: `%s`\nQuestion: `%s`\nAnswer: `%s`", qcode, (questionStr ? questionStr : "Not Specified"), (answerStr ? answerStr : "Not Specified"));
hammy_job_respond(job, client, "Q-Code Conversion", body, false);
}