Skip to content

Commit

Permalink
GH-388: Add configurable duel request embed color
Browse files Browse the repository at this point in the history
  • Loading branch information
utarwyn committed Dec 16, 2022
1 parent 5010bdb commit d4cc689
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"textCommand": "!ttt",
"allowedChannelIds": [],
"allowedRoleIds": [],
"requestExpireTime": 60,
"requestCooldownTime": 0,
"requestEmbedColor": "#2980B9",
"requestExpireTime": 60,
"requestReactions": false,
"simultaneousGames": false,
"gameExpireTime": 30,
Expand Down
12 changes: 10 additions & 2 deletions src/bot/entity/DuelRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ComponentInteractionMessagingTunnel from '@bot/messaging/ComponentInteractionMessagingTunnel';
import MessagingTunnel from '@bot/messaging/MessagingTunnel';
import GameStateManager from '@bot/state/GameStateManager';
import { EmbedColor } from '@config/InteractionConfig';
import localize from '@i18n/localize';
import {
Collection,
Expand Down Expand Up @@ -42,6 +43,10 @@ export default class DuelRequest {
* Interact with reactions instead of buttons
*/
private readonly useReactions: boolean;
/**
* Color used for the embed.
*/
private readonly embedColor: EmbedColor;
/**
* Tunnel that initiated the duel request.
*/
Expand All @@ -55,19 +60,22 @@ export default class DuelRequest {
* @param invited invited member object
* @param expireTime expiration time of the mesage, undefined for default
* @param useReactions interact with reactions instead of buttons
* @param embedColor color used for the embed
*/
constructor(
manager: GameStateManager,
tunnel: MessagingTunnel,
invited: GuildMember,
expireTime?: number,
useReactions?: boolean
useReactions?: boolean,
embedColor?: EmbedColor
) {
this.manager = manager;
this.tunnel = tunnel;
this.invited = invited;
this.expireTime = expireTime ?? 60;
this.useReactions = useReactions ?? false;
this.embedColor = embedColor ?? 2719929;
}

/**
Expand Down Expand Up @@ -102,7 +110,7 @@ export default class DuelRequest {
content: this.invited.toString(),
embeds: [
{
color: 2719929, // #2980B9
color: this.embedColor,
title: localize.__('duel.title'),
description: content
}
Expand Down
3 changes: 2 additions & 1 deletion src/bot/state/GameStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export default class GameStateManager {
tunnel,
invited,
this.bot.configuration.requestExpireTime,
this.bot.configuration.requestReactions
this.bot.configuration.requestReactions,
this.bot.configuration.requestEmbedColor
);

// Reply with the duel request and attach the created message
Expand Down
1 change: 1 addition & 0 deletions src/config/ConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class ConfigProvider implements Config {

public allowedChannelIds = [];
public allowedRoleIds = [];
public requestEmbedColor = 2719929;
public requestExpireTime = 60;
public requestCooldownTime = 0;
public simultaneousGames = false;
Expand Down
6 changes: 6 additions & 0 deletions src/config/InteractionConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type EmbedColor = number | [number, number, number] | `#${string}`;

/**
* Configuration about user interaction with the module.
*
Expand All @@ -17,6 +19,10 @@ export default interface InteractionConfig {
* Cooldown time of a duel request.
*/
requestCooldownTime?: number;
/**
* Color used for the duel request embed.
*/
requestEmbedColor?: EmbedColor;
/**
* Expiration time of a duel request.
*/
Expand Down

0 comments on commit d4cc689

Please sign in to comment.