Skip to content

Commit f6a88b3

Browse files
fix: defer, formatting, debug mode (#61)
* fix defer problem and moved the debug mode switch to .env * fix editReply * formatting
1 parent 6f9aef6 commit f6a88b3

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

.env_sample

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
TOKEN=[ENTER_YOUR_TOKEN_HERE]
2-
DEFAULT_GUILD=[GUILD_ID]
2+
DEFAULT_GUILD=[GUILD_ID]
3+
4+
# "1" or "0" (true or false). In debug mode no config validation will be made.
5+
DEBUG_MODE=0

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ We're all part of a game jam/hackothon server with monthly events and wanted to
1616
We won't host the bot for you. If you want to use it on your own server you have to do that yourself :)
1717
To see how to use this bot on your own visit our [wiki](https://github.com/Cowoding-Jams/Jambo/wiki). It's really good! We promise. It can help you a lot.
1818

19-
20-
2119
## License
2220

2321
This project is licensed under the [Anti-Capitalist Software License](https://anticapitalist.software/). See [LICENSE](LICENSE).

src/config.ts

-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export const config: BotConfig = {
1212

1313
// --- Development ---
1414
logLevel: "debug",
15-
debugMode: false,
1615

1716
// --- Management ---
1817
adminRoleId: "855348792025939988", // cowoding-jams/roles: admin
@@ -73,8 +72,6 @@ interface BotConfig {
7372
// --- Development ---
7473
/** Also available: error, warn, info, http, verbose, debug, silly. */
7574
logLevel: "debug" | "info" | "warn" | "error" | "verbose";
76-
/** In debug mode no config validation will be made. */
77-
debugMode: boolean;
7875

7976
// --- Management ---
8077
/** Moderators of the server (to manage proposals) */

src/ctx.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { config } from "./config";
44

55
class Context {
66
public readonly defaultGuild;
7+
public readonly debugMode;
78
public readonly commands: Collection<string, Command> = new Collection<string, Command>();
89
public readonly buttons: Collection<string, Button> = new Collection<string, Button>();
910
public readonly selectMenus: Collection<string, SelectMenu> = new Collection<string, SelectMenu>();
@@ -15,6 +16,7 @@ class Context {
1516
if (!process.env.DEFAULT_GUILD) throw new Error("Default guild not defined!");
1617

1718
this.defaultGuild = process.env.DEFAULT_GUILD;
19+
this.debugMode = process.env.DEBUG_MODE === "1";
1820
this.logLevel = config.logLevel || "error";
1921
}
2022

src/events/ready.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { logger } from "../logger";
55
import CodingJamsCommand from "../commands/CodingJamsCommand";
66
import { validateConfigParameters } from "../config-validate";
77
import BirthdayCommand from "../commands/BirthdayCommand";
8-
import { config } from "../config";
98

109
export default async function ready(client: Client) {
1110
const guild = client.guilds.cache.get(ctx.defaultGuild)!;
@@ -46,7 +45,7 @@ export default async function ready(client: Client) {
4645

4746
logger.info("Setup successful!");
4847

49-
if (!config.debugMode) {
48+
if (!ctx.debugMode) {
5049
logger.debug("Validating config parameters...");
5150
await validateConfigParameters(guild);
5251
logger.debug("Config parameters validated!");

src/util/proposal/listProposals.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export async function listProposals(
1616
page = 0,
1717
proposalsPerPage = 6
1818
): Promise<void> {
19+
if (interaction instanceof ChatInputCommandInteraction) await interaction.deferReply();
20+
else await interaction.deferUpdate();
21+
1922
const pages = Math.ceil(proposalDb.size / proposalsPerPage);
2023

2124
if (page < 0) page = pages - 1;
@@ -26,7 +29,7 @@ export async function listProposals(
2629
let embed = addEmbedFooter(new EmbedBuilder().setTitle(`${proposalDb.size} Proposals`));
2730

2831
const list = numberedList(
29-
proposals.map((p) => p.title),
32+
proposals.map((p) => `${p.title} (${p.abbreviation})`),
3033
proposals.map((p) => durationToReadable(p.duration)),
3134
page * proposalsPerPage
3235
);
@@ -63,9 +66,7 @@ export async function listProposals(
6366
.setStyle(ButtonStyle.Secondary)
6467
);
6568

66-
if (interaction instanceof ChatInputCommandInteraction)
67-
await interaction.reply({ embeds: [embed], components: proposalDb.size != 0 ? [row] : [] });
68-
else await interaction.update({ embeds: [embed], components: proposalDb.size != 0 ? [row] : [] });
69+
await interaction.editReply({ embeds: [embed], components: proposalDb.size != 0 ? [row] : [] });
6970
}
7071

7172
export async function viewProposal(interaction: ChatInputCommandInteraction): Promise<void> {

0 commit comments

Comments
 (0)