V4.1.0 - Add unrestricted repeat roll system.
This commit is contained in:
parent
2f088907ad
commit
255955d854
10
PRIVACY.md
10
PRIVACY.md
|
@ -29,6 +29,11 @@ Like all Discord bots, _The Bot_ reads every message that it is allowed to, mean
|
|||
* The Inline Roll System only stores the Discord Guild ID upon usage. Discord Guild IDs are internal IDs generated and provided by Discord.
|
||||
* _The Bot_ only uses the stored Discord Guild IDs to determine which Guilds it should do a preliminary scan for Inline Rolls for all messages sent.
|
||||
* The Discord Guild IDs are only visible to _The Developer_ thru direct database administration. This direct database administration is only used when there are issues with _The Bot_'s database.
|
||||
* The Unrestricted Repeat Roll System (in Discord, these commands are known as `/toggle-unrestricted-repeat enable`, `[[repeat enable`, `[[repeat allow`, `/toggle-unrestricted-repeat disable`, `[[repeat block`, `[[repeat disable`, and `[[repeat delete`):
|
||||
* This system is entirely optional, meaning users never need to run these commands under normal usage of _The Bot_. This system is only intended to be used when a user wants to utilize Unrestricted Repeat Rolls in their Guild.
|
||||
* The Unrestricted Repeat Roll System only stores the Discord Guild ID upon usage. Discord Guild IDs are internal IDs generated and provided by Discord.
|
||||
* _The Bot_ only uses the stored Discord Guild IDs to determine which Guilds it should allow Unrestricted Repeat Rolls in.
|
||||
* The Discord Guild IDs are only visible to _The Developer_ thru direct database administration. This direct database administration is only used when there are issues with _The Bot_'s database.
|
||||
* The Roll Alias System (in Discord, this system contains all commands starting with `/alias`, `[[rollalias`, `[[ralias`, `[[alias`, `[[rolla`, and `[[ra`, and the subcommands that _The Bot_ will store data from are `add`, `create`, `set`, `update`, `replace`, `copy`, `clone`, and `rename`):
|
||||
* This system is entirely optional, meaning users never need to run these commands under normal usage of _The Bot_. This system is only intended to be used when a user wants to save roll commands for later reuse.
|
||||
* The Roll Alias System stores the user provided Alias Name, the user provided Roll String, and in Guild mode, the Discord Guild ID of the Guild the command was run in; and in personal mode, the Discord User ID of the user who ran the command. The Alias Name is string of up to 200 characters that the user provided to save the Roll String under. The Roll String is a string of up to 4,000 characters containing roll commands and formatting text the user provided. Discord Guild IDs and Discord User IDs are internal IDs generated and provided by Discord.
|
||||
|
@ -83,6 +88,11 @@ If you would like to remove your Discord Guild ID from _The Bot_'s database, sim
|
|||
|
||||
Additionally, _The Bot_ will automatically delete the Discord Guild ID from _The Bot_'s database when _The Bot_ is removed from your guild.
|
||||
|
||||
## Unrestricted Repeat Roll System Data Deletion
|
||||
If you would like to remove your Discord Guild ID from _The Bot_'s database, simply send one of the following commands in the Guild: `/toggle-unrestricted-repeat disable`, `[[repeat disable`, `[[repeat block`, or `[[repeat delete`. All variants of this delete the Discord Guild ID from _The Bot_'s database.
|
||||
|
||||
Additionally, _The Bot_ will automatically delete the Discord Guild ID from _The Bot_'s database when _The Bot_ is removed from your guild.
|
||||
|
||||
## Alias System Data Deletion
|
||||
### Personal Mode
|
||||
If you would like to remove all your Personal aliases from _The Bot_'s database, simply send one of the following commands in any channel you share with _The Bot_: `/alias personal delete-all`, `[[alias delete-all`, or `[[alias remove-all`. As deletion is irreversible, _The Bot_ requires a verification code to execute the deletion. _The Bot_ will create a verification code for you when you first send the command.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# The Artificer - A Dice Rolling Discord Bot | V4.0.2 - 2025/08/04
|
||||
# The Artificer - A Dice Rolling Discord Bot | V4.1.0 - 2025/08/05
|
||||
[](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
||||
[](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer) [](https://sonarcloud.io/summary/new_code?id=TheArtificer)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export const config = {
|
||||
name: 'The Artificer', // Name of the bot
|
||||
maxFileSize: 8_388_290, // Max file size bot can send
|
||||
version: '4.0.2', // Version of the bot
|
||||
version: '4.1.0', // Version of the bot
|
||||
token: 'the_bot_token', // Discord API Token for this bot
|
||||
localtoken: 'local_testing_token', // Discord API Token for a secondary OPTIONAL testing bot, THIS MUST BE DIFFERENT FROM "token"
|
||||
prefix: '[[', // Prefix for all commands
|
||||
|
|
|
@ -22,8 +22,20 @@ await dbClient.execute(`DROP TABLE IF EXISTS command_cnt;`);
|
|||
await dbClient.execute(`DROP TABLE IF EXISTS ignore_list;`);
|
||||
await dbClient.execute(`DROP TABLE IF EXISTS allow_inline;`);
|
||||
await dbClient.execute(`DROP TABLE IF EXISTS aliases;`);
|
||||
await dbClient.execute(`DROP TABLE IF EXISTS allow_unrestricted_repeat;`);
|
||||
console.log('Tables dropped');
|
||||
|
||||
// Holds guilds that have explicitly allowed anyone to repeat anyone's rolls
|
||||
console.log('Attempting to create table allow_unrestricted_repeat');
|
||||
await dbClient.execute(`
|
||||
CREATE TABLE allow_unrestricted_repeat (
|
||||
guildid bigint unsigned NOT NULL,
|
||||
PRIMARY KEY (guildid),
|
||||
UNIQUE KEY allow_unrestricted_repeat_guildid_UNIQUE (guildid)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
`);
|
||||
console.log('Table created');
|
||||
|
||||
// Holds all aliases that have been created
|
||||
console.log('Attempting to create table aliases');
|
||||
await dbClient.execute(`
|
||||
|
|
|
@ -25,6 +25,7 @@ const commands = [
|
|||
'ping',
|
||||
'privacy',
|
||||
'rip',
|
||||
'repeat',
|
||||
'report',
|
||||
'roll',
|
||||
'rolldecorators',
|
||||
|
|
|
@ -60,6 +60,22 @@ This document uses the default prefix (`[[`) on all commands listed. If a comma
|
|||
* `/toggle-inline-rolls disable`
|
||||
* `[[inline block` or `[[inline disable` or `[[inline delete`
|
||||
* Blocks inline rolls in the guild.
|
||||
* `/toggle-unrestricted-repeat [subcommand]` or `[[repeat [subcommand]`
|
||||
* Controls whether or not unrestricted repeat rolls can be done in a guild, defaults off. Unrestricted Repeat Rolls are whether or not anyone in a guild can use the `Repeat Roll` button on anyone's roll or only the original roller can use them. These commands may only be used by the Owner or Admins of your guild.
|
||||
* An inline roll is a roll that does not immediately start with `[[`, such as `test [[d20]]`.
|
||||
* Available subcommands:
|
||||
* `/toggle-unrestricted-repeat help`
|
||||
* `[[repeat help`
|
||||
* Provides a message similar to this subcommand description.
|
||||
* `/toggle-unrestricted-repeat status`
|
||||
* `[[repeat status`
|
||||
* Shows the current status of unrestricted repeat rolls for this guild.
|
||||
* `/toggle-unrestricted-repeat enable`
|
||||
* `[[repeat allow` or `[[repeat enable`
|
||||
* Allows unrestricted repeat rolls in the guild.
|
||||
* `/toggle-unrestricted-repeat disable`
|
||||
* `[[repeat block` or `[[repeat disable` or `[[repeat delete`
|
||||
* Blocks unrestricted repeat rolls in the guild.
|
||||
* `/alias [subcommand]` or `[[rollalias [subcommand]` or `[[ralias [subcommand]` or `[[alias [subcommand]` or `[[rolla [subcommand]` or `[[ra [subcommand]`
|
||||
* Custom Roll Alias System
|
||||
* Allows anyone to store a roll string as a shortcut/alias for later use/reuse.
|
||||
|
|
|
@ -28,6 +28,15 @@ import utils from 'utils/utils.ts';
|
|||
import { STATUS_CODE, STATUS_TEXT } from '@std/http/status';
|
||||
|
||||
const getUserIdForEmbed = (rollRequest: QueuedRoll): bigint => {
|
||||
if (rollRequest.apiRoll) return rollRequest.api.userId;
|
||||
if (rollRequest.ddRoll) {
|
||||
if (rollRequest.dd.overrideAuthorId === 0n) return rollRequest.dd.authorId;
|
||||
return rollRequest.dd.overrideAuthorId;
|
||||
}
|
||||
return 0n;
|
||||
};
|
||||
|
||||
const getAuthorIdForButton = (rollRequest: QueuedRoll): bigint => {
|
||||
if (rollRequest.apiRoll) return rollRequest.api.userId;
|
||||
if (rollRequest.ddRoll) return rollRequest.dd.authorId;
|
||||
return 0n;
|
||||
|
@ -189,6 +198,7 @@ export const onWorkerComplete = async (workerMessage: MessageEvent<SolvedRoll>,
|
|||
});
|
||||
} else {
|
||||
newMsg = await rollRequest.dd.myResponse.edit({
|
||||
content: rollRequest.dd.overrideAuthorId === 0n ? '' : `<@${rollRequest.dd.overrideAuthorId}> used the \`Repeat Roll\` button for the referenced message:`,
|
||||
embeds: pubEmbeds,
|
||||
components: [
|
||||
{
|
||||
|
@ -197,7 +207,7 @@ export const onWorkerComplete = async (workerMessage: MessageEvent<SolvedRoll>,
|
|||
{
|
||||
type: MessageComponentTypes.Button,
|
||||
label: 'Repeat Roll',
|
||||
customId: `${repeatRollCustomId}${InteractionValueSeparator}${getUserIdForEmbed(rollRequest).toString()}`,
|
||||
customId: `${repeatRollCustomId}${InteractionValueSeparator}${getAuthorIdForButton(rollRequest).toString()}`,
|
||||
style: ButtonStyles.Secondary,
|
||||
emoji: '🎲',
|
||||
},
|
||||
|
@ -286,7 +296,7 @@ Please click on "<@${botId}> *Click to see attachment*" above this message to se
|
|||
embeds: [
|
||||
(
|
||||
await generateRollEmbed(
|
||||
rollRequest.dd.authorId,
|
||||
0n,
|
||||
<SolvedRoll> {
|
||||
error: true,
|
||||
errorMsg:
|
||||
|
|
|
@ -28,7 +28,7 @@ export const terminateWorker = async (rollWorker: Worker, rollRequest: QueuedRol
|
|||
embeds: [
|
||||
(
|
||||
await generateRollEmbed(
|
||||
rollRequest.dd.authorId,
|
||||
0n,
|
||||
<SolvedRoll> {
|
||||
error: true,
|
||||
errorCode: 'TooComplex',
|
||||
|
|
|
@ -26,6 +26,7 @@ interface DDQueuedRoll extends BaseQueuedRoll {
|
|||
dd: {
|
||||
myResponse: DiscordenoMessage;
|
||||
originalMessage: DiscordenoMessage;
|
||||
overrideAuthorId: bigint;
|
||||
authorId: bigint;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@ import { roll, rollSC } from 'commands/roll.ts';
|
|||
import { rollHelp } from 'commands/rollHelp.ts';
|
||||
import { stats, statsSC } from 'commands/stats.ts';
|
||||
import { toggleInline, toggleInlineSC } from 'commands/toggleInline.ts';
|
||||
import { toggleRepeat, toggleRepeatSC } from 'commands/toggleUnrestrictedRepeat.ts';
|
||||
import { version, versionSC } from 'commands/version.ts';
|
||||
|
||||
export const announceSlashCommands = () => {
|
||||
upsertSlashCommands([aliasSC, heatmapSC, helpSC, infoSC, privacySC, reportSC, ripSC, rollSC, statsSC, toggleInlineSC, versionSC]);
|
||||
upsertSlashCommands([aliasSC, heatmapSC, helpSC, infoSC, privacySC, reportSC, ripSC, rollSC, statsSC, toggleInlineSC, toggleRepeatSC, versionSC]);
|
||||
};
|
||||
|
||||
export const commands = {
|
||||
|
@ -43,6 +44,7 @@ export const commands = {
|
|||
rollHelp,
|
||||
stats,
|
||||
toggleInline,
|
||||
toggleRepeat,
|
||||
version,
|
||||
};
|
||||
|
||||
|
@ -57,5 +59,6 @@ export const slashCommandDetails = {
|
|||
rollSC,
|
||||
statsSC,
|
||||
toggleInlineSC,
|
||||
toggleRepeatSC,
|
||||
versionSC,
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@ import { RollAliasHelpPages } from 'commands/helpLibrary/aliasHelp.ts';
|
|||
import { ApiHelpPages } from 'commands/helpLibrary/apiHelp.ts';
|
||||
import { HelpContents, HelpPage } from 'commands/helpLibrary/helpLibrary.d.ts';
|
||||
import { InlineHelpPages } from 'commands/helpLibrary/inlineHelp.ts';
|
||||
import { RepeatHelpPages } from 'commands/helpLibrary/repeatHelp.ts';
|
||||
|
||||
import { RootRollHelpPages } from 'commands/helpLibrary/rollHelp/_rootRollHelp.ts';
|
||||
|
||||
|
@ -13,6 +14,7 @@ const dict = new Map<string, HelpPage | HelpContents>([
|
|||
['roll-help', RootRollHelpPages],
|
||||
['alias', RollAliasHelpPages],
|
||||
['inline', InlineHelpPages],
|
||||
['repeat', RepeatHelpPages],
|
||||
[
|
||||
'opt-out',
|
||||
{
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
import config from '~config';
|
||||
|
||||
import { HelpContents, HelpPage } from 'commands/helpLibrary/helpLibrary.d.ts';
|
||||
|
||||
const name = 'Unrestricted Repeat';
|
||||
const description = `${config.name} has an option to allow anyone to use the \`Repeat Roll\` button.
|
||||
|
||||
By default, Unrestricted Repeat Rolls are disabled in your guild, meaning only the original roller can use the \`Repeat Roll\` button. These commands may only be used by the Owner or Admins of your guild.`;
|
||||
const dict = new Map<string, HelpContents>([
|
||||
[
|
||||
'status',
|
||||
{
|
||||
name: 'Status',
|
||||
description: `**Usage:** \`${config.prefix}repeat status\`
|
||||
|
||||
Shows the current status of Repeat Rolling for this guild.`,
|
||||
},
|
||||
],
|
||||
[
|
||||
'enable',
|
||||
{
|
||||
name: 'Allow Unrestricted Repeat',
|
||||
description: `**Usage:** \`${config.prefix}repeat allow\` or \`${config.prefix}repeat enable\`
|
||||
|
||||
Allows Unrestricted Repeat Rolls for this guild. This allows anyone in the guild to use the \`Repeat Roll\` button on any roll from anyone.`,
|
||||
},
|
||||
],
|
||||
[
|
||||
'disable',
|
||||
{
|
||||
name: 'Block Unrestricted Repeat',
|
||||
description: `**Usage:** \`${config.prefix}repeat block\` or \`${config.prefix}repeat disable\` or \`${config.prefix}repeat delete\`
|
||||
|
||||
Blocks Unrestricted Repeat rolls for this guild. This only allows the original roller to use the \`Repeat Roll\` button.`,
|
||||
},
|
||||
],
|
||||
[
|
||||
'help',
|
||||
{
|
||||
name: 'Help',
|
||||
description: `**Usage:** \`${config.prefix}repeat help\` or \`${config.prefix}repeat h\`
|
||||
|
||||
Opens the help library to the Unrestricted Repeat Help section.`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
export const RepeatHelpPages: HelpPage = {
|
||||
name,
|
||||
description,
|
||||
isPage: true,
|
||||
dict,
|
||||
};
|
|
@ -27,7 +27,13 @@ export const rollSC: CreateGlobalApplicationCommand = {
|
|||
],
|
||||
};
|
||||
|
||||
export const roll = async (msgOrInt: DiscordenoMessage | Interaction, args: string[], command: string) => {
|
||||
export const roll = async (
|
||||
msgOrInt: DiscordenoMessage | Interaction,
|
||||
args: string[],
|
||||
command: string,
|
||||
overrideAuthor?: bigint,
|
||||
forceOriginalAuthor?: bigint,
|
||||
) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
const currDateTime = new Date();
|
||||
dbClient.execute(queries.callIncCnt('roll')).catch((e) => utils.commonLoggers.dbError('roll.ts:20', 'call sproc INC_CNT on', e));
|
||||
|
@ -44,7 +50,7 @@ export const roll = async (msgOrInt: DiscordenoMessage | Interaction, args: stri
|
|||
originalCommand = `${config.prefix}${originalCommand.trim()}`;
|
||||
}
|
||||
|
||||
const m = await utils.sendOrInteract(msgOrInt, 'roll.ts:47', rollingEmbed, true);
|
||||
const m = await utils.sendOrInteract(msgOrInt, 'roll.ts:47', rollingEmbed, true, !overrideAuthor);
|
||||
if (!m) {
|
||||
throw new Error("My message didn't send!");
|
||||
}
|
||||
|
@ -72,7 +78,8 @@ export const roll = async (msgOrInt: DiscordenoMessage | Interaction, args: stri
|
|||
ddRoll: true,
|
||||
testRoll: false,
|
||||
dd: {
|
||||
authorId: utils.getAuthorIdFromMessageOrInteraction(msgOrInt),
|
||||
overrideAuthorId: overrideAuthor ?? 0n,
|
||||
authorId: forceOriginalAuthor ? forceOriginalAuthor : utils.getAuthorIdFromMessageOrInteraction(msgOrInt),
|
||||
myResponse: m,
|
||||
originalMessage: hasOwnProperty(msgOrInt, 'token') ? m : msgOrInt,
|
||||
},
|
||||
|
|
|
@ -42,8 +42,8 @@ export const toggleInline = async (msgOrInt: DiscordenoMessage | Interaction, ar
|
|||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(queries.callIncCnt('inline')).catch((e) => utils.commonLoggers.dbError('toggleInline.ts:16', 'call sproc INC_CNT on', e));
|
||||
|
||||
// Local apiArg in lowercase
|
||||
const apiArg = (args[0] || '').toLowerCase();
|
||||
// Local inlineArg in lowercase
|
||||
const inlineArg = (args[0] || '').toLowerCase();
|
||||
|
||||
const guildId = BigInt(msgOrInt.guildId ?? '0');
|
||||
|
||||
|
@ -78,7 +78,7 @@ export const toggleInline = async (msgOrInt: DiscordenoMessage | Interaction, ar
|
|||
|
||||
if (await hasGuildPermissions(guildId, utils.getAuthorIdFromMessageOrInteraction(msgOrInt), ['ADMINISTRATOR'])) {
|
||||
let enable = false;
|
||||
switch (apiArg) {
|
||||
switch (inlineArg) {
|
||||
case 'allow':
|
||||
case 'enable':
|
||||
enable = true;
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
import { CreateGlobalApplicationCommand, DiscordApplicationCommandOptionTypes, DiscordenoMessage, hasGuildPermissions, Interaction } from '@discordeno';
|
||||
|
||||
import config from '~config';
|
||||
|
||||
import { generateHelpMessage } from 'commands/helpLibrary/generateHelpMessage.ts';
|
||||
|
||||
import dbClient from 'db/client.ts';
|
||||
import { queries, repeatList } from 'db/common.ts';
|
||||
|
||||
import { failColor, infoColor1, successColor } from 'embeds/colors.ts';
|
||||
|
||||
import utils from 'utils/utils.ts';
|
||||
|
||||
export const toggleRepeatSC: CreateGlobalApplicationCommand = {
|
||||
name: 'toggle-unrestricted-repeat',
|
||||
description: 'Enable or disable unrestricted repeat rolling for this guild.',
|
||||
options: [
|
||||
{
|
||||
type: DiscordApplicationCommandOptionTypes.SubCommand,
|
||||
name: 'enable',
|
||||
description: 'Enables/Allows unrestricted repeat rolling in this guild.',
|
||||
},
|
||||
{
|
||||
type: DiscordApplicationCommandOptionTypes.SubCommand,
|
||||
name: 'disable',
|
||||
description: 'Disables/Blocks unrestricted repeat rolling in this guild.',
|
||||
},
|
||||
{
|
||||
type: DiscordApplicationCommandOptionTypes.SubCommand,
|
||||
name: 'status',
|
||||
description: 'Gets the current status of repeat rolling for this guild.',
|
||||
},
|
||||
{
|
||||
type: DiscordApplicationCommandOptionTypes.SubCommand,
|
||||
name: 'help',
|
||||
description: 'Opens the help library to the Toggle Repeat help page.',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const toggleRepeat = async (msgOrInt: DiscordenoMessage | Interaction, args: string[]) => {
|
||||
// Light telemetry to see how many times a command is being run
|
||||
dbClient.execute(queries.callIncCnt('repeat')).catch((e) => utils.commonLoggers.dbError('toggleRepeat.ts:16', 'call sproc INC_CNT on', e));
|
||||
|
||||
// Local repeatArg in lowercase
|
||||
const repeatArg = (args[0] || '').toLowerCase();
|
||||
|
||||
const guildId = BigInt(msgOrInt.guildId ?? '0');
|
||||
|
||||
// Alert users who DM the bot that this command is for guilds only
|
||||
if (guildId === 0n) {
|
||||
utils.sendOrInteract(msgOrInt, 'toggleRepeat.ts:45', {
|
||||
embeds: [
|
||||
{
|
||||
color: failColor,
|
||||
title: 'Toggle Repeat commands are only available in guilds.',
|
||||
},
|
||||
],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let errorOut = false;
|
||||
const guildQuery = await dbClient.query(`SELECT guildid FROM allow_unrestricted_repeat WHERE guildid = ?`, [guildId]).catch((e0) => {
|
||||
utils.commonLoggers.dbError('toggleRepeat.ts:36', 'query', e0);
|
||||
utils.sendOrInteract(msgOrInt, 'toggleRepeat.ts:59', {
|
||||
embeds: [
|
||||
{
|
||||
color: failColor,
|
||||
title: 'Failed to check Unrestricted Repeat status for this guild.',
|
||||
description: 'If this issue persists, please report this to the developers.',
|
||||
},
|
||||
],
|
||||
});
|
||||
errorOut = true;
|
||||
});
|
||||
if (errorOut) return;
|
||||
|
||||
if (await hasGuildPermissions(guildId, utils.getAuthorIdFromMessageOrInteraction(msgOrInt), ['ADMINISTRATOR'])) {
|
||||
let enable = false;
|
||||
switch (repeatArg) {
|
||||
case 'allow':
|
||||
case 'enable':
|
||||
enable = true;
|
||||
if (!repeatList.includes(guildId)) {
|
||||
await dbClient.execute('INSERT INTO allow_unrestricted_repeat(guildid) values(?)', [guildId]).catch((e) => {
|
||||
utils.commonLoggers.dbError('toggleRepeat.ts:58', 'insert into allow_unrestricted_repeat', e);
|
||||
errorOut = true;
|
||||
});
|
||||
if (!errorOut) {
|
||||
repeatList.push(guildId);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'block':
|
||||
case 'disable':
|
||||
case 'delete':
|
||||
await dbClient.execute('DELETE FROM allow_unrestricted_repeat WHERE guildid = ?', [guildId]).catch((e) => {
|
||||
utils.commonLoggers.dbError('toggleRepeat.ts:65', 'delete from allow_unrestricted_repeat', e);
|
||||
errorOut = true;
|
||||
});
|
||||
if (!errorOut && repeatList.includes(guildId)) {
|
||||
repeatList.splice(repeatList.indexOf(guildId), 1);
|
||||
}
|
||||
break;
|
||||
case 'status':
|
||||
utils.sendOrInteract(msgOrInt, 'toggleRepeat.ts:98', {
|
||||
embeds: [
|
||||
{
|
||||
color: infoColor1,
|
||||
title: `Unrestricted Repeat is ${guildQuery.length ? 'Enabled' : 'Disabled'} for this guild`,
|
||||
description: `This means ${guildQuery.length ? 'anyone' : 'only the original roller'} can use the \`Repeat Roll\` button.
|
||||
|
||||
To ${guildQuery.length ? 'disable' : 'enable'} it, run the following command:\n\`${config.prefix}repeat ${guildQuery.length ? 'disable' : 'enable'}\``,
|
||||
},
|
||||
],
|
||||
});
|
||||
return;
|
||||
case 'h':
|
||||
case 'help':
|
||||
default:
|
||||
utils.sendOrInteract(msgOrInt, 'toggleRepeat.ts:113', generateHelpMessage('repeat'));
|
||||
return;
|
||||
}
|
||||
if (errorOut) {
|
||||
utils.sendOrInteract(msgOrInt, 'toggleRepeat.ts:117', {
|
||||
embeds: [
|
||||
{
|
||||
color: failColor,
|
||||
title: `Failed to ${enable ? 'Enable' : 'Disable'} Unrestricted Repeat for this guild`,
|
||||
description: 'Please try the command again. If this issue persists, please report this to the developers.',
|
||||
},
|
||||
],
|
||||
});
|
||||
return;
|
||||
}
|
||||
utils.sendOrInteract(msgOrInt, 'toggleRepeat.ts:128', {
|
||||
embeds: [
|
||||
{
|
||||
color: successColor,
|
||||
title: `Successfully ${enable ? 'Enabled' : 'Disabled'} Unrestricted Repeat for this guild`,
|
||||
description: `${enable ? 'Anyone' : 'Only the original roller'} may now use the \`Repeat Roll\` button.`,
|
||||
},
|
||||
],
|
||||
});
|
||||
} else {
|
||||
utils.sendOrInteract(msgOrInt, 'toggleRepeat.ts:137', {
|
||||
embeds: [
|
||||
{
|
||||
color: failColor,
|
||||
title: 'Toggle Unrestricted Repeat commands are powerful and can only be used by guild Owners and Admins.',
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
};
|
|
@ -21,6 +21,13 @@ dbInlineList.forEach((guildIdObj: GuildIdObj) => {
|
|||
inlineList.push(guildIdObj.guildid);
|
||||
});
|
||||
|
||||
// List of guilds who have allowed unrestricted repeat rolls
|
||||
export const repeatList: Array<bigint> = [];
|
||||
const dbRepeatList = await dbClient.query('SELECT * FROM allow_unrestricted_repeat');
|
||||
dbRepeatList.forEach((guildIdObj: GuildIdObj) => {
|
||||
repeatList.push(guildIdObj.guildid);
|
||||
});
|
||||
|
||||
export const weekDays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
|
||||
|
||||
export const queries = {
|
||||
|
|
|
@ -42,7 +42,10 @@ export const guildDeleteHandler = (guild: DiscordenoGuild) => {
|
|||
.execute('DELETE FROM allowed_guilds WHERE guildid = ? AND banned = 0', [guild.id])
|
||||
.catch((e) => utils.commonLoggers.dbError('guildDelete.ts:41', 'delete from', e));
|
||||
dbClient.execute('DELETE FROM allow_inline WHERE guildid = ?', [guild.id]).catch((e) => utils.commonLoggers.dbError('guildDelete.ts:42', 'delete from', e));
|
||||
dbClient
|
||||
.execute('DELETE FROM allow_unrestricted_repeat WHERE guildid = ?', [guild.id])
|
||||
.catch((e) => utils.commonLoggers.dbError('guildDelete.ts:47', 'delete from', e));
|
||||
dbClient
|
||||
.execute('DELETE FROM aliases WHERE guildid = ? AND userid = ?', [guild.id, 0n])
|
||||
.catch((e) => utils.commonLoggers.dbError('guildDelete.ts:45', 'delete from', e));
|
||||
.catch((e) => utils.commonLoggers.dbError('guildDelete.ts:50', 'delete from', e));
|
||||
};
|
||||
|
|
|
@ -15,6 +15,8 @@ import {
|
|||
} from '@discordeno';
|
||||
import { log, LogTypes as LT } from '@Log4Deno';
|
||||
|
||||
import config from '~config';
|
||||
|
||||
import { Modifiers } from 'artigen/dice/getModifiers.ts';
|
||||
|
||||
import { repeatRollCustomId } from 'artigen/managers/handler/workerComplete.ts';
|
||||
|
@ -26,6 +28,8 @@ import { commands, slashCommandDetails } from 'commands/_index.ts';
|
|||
|
||||
import { generateHelpMessage, helpCustomId } from 'commands/helpLibrary/generateHelpMessage.ts';
|
||||
|
||||
import { repeatList } from 'db/common.ts';
|
||||
|
||||
import { failColor } from 'embeds/colors.ts';
|
||||
|
||||
import { messageCreateHandler } from 'events/messageCreate.ts';
|
||||
|
@ -83,9 +87,10 @@ export const interactionCreateHandler = async (interaction: Interaction) => {
|
|||
}
|
||||
|
||||
if (interaction.data.customId.startsWith(repeatRollCustomId) && interaction.message) {
|
||||
const missingUserId = 'missingUserId';
|
||||
const ownerId = interaction.data.customId.split(InteractionValueSeparator)[1] ?? 'missingOwnerId';
|
||||
const userInteractingId = interaction.member?.user.id ?? interaction.user?.id ?? 'missingUserId';
|
||||
if (ownerId === userInteractingId) {
|
||||
const userInteractingId = interaction.member?.user.id ?? interaction.user?.id ?? missingUserId;
|
||||
if (ownerId === userInteractingId || (userInteractingId !== missingUserId && repeatList.includes(BigInt(interaction.guildId ?? '0')))) {
|
||||
const botMsg: DiscordenoMessage = await structures.createDiscordenoMessage(interaction.message);
|
||||
if (botMsg && botMsg.messageReference) {
|
||||
const rollMsg = await getMessage(BigInt(botMsg.messageReference.channelId ?? '0'), BigInt(botMsg.messageReference.messageId ?? '0')).catch((e) =>
|
||||
|
@ -98,7 +103,11 @@ export const interactionCreateHandler = async (interaction: Interaction) => {
|
|||
);
|
||||
if (rollMsg && !rollMsg.isBot) {
|
||||
ackInteraction(interaction);
|
||||
if (ownerId === userInteractingId) {
|
||||
messageCreateHandler(rollMsg);
|
||||
} else {
|
||||
messageCreateHandler(rollMsg, BigInt(userInteractingId));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +129,28 @@ export const interactionCreateHandler = async (interaction: Interaction) => {
|
|||
}
|
||||
rollStr += ` ${Modifiers.YVars} ${yVarVals.join(',')}`;
|
||||
}
|
||||
commands.roll(interaction, rollStr.split(argSpacesSplitRegex), '');
|
||||
|
||||
let responseInteraction: Interaction | DiscordenoMessage = interaction;
|
||||
if (botMsg && botMsg.messageReference) {
|
||||
const rollMsg = await getMessage(BigInt(botMsg.messageReference.channelId ?? '0'), BigInt(botMsg.messageReference.messageId ?? '0')).catch((e) =>
|
||||
utils.commonLoggers.messageGetError(
|
||||
'interactionCreate.ts:92',
|
||||
botMsg.messageReference?.channelId ?? '0',
|
||||
botMsg.messageReference?.messageId ?? '0',
|
||||
e,
|
||||
)
|
||||
);
|
||||
if (rollMsg) {
|
||||
ackInteraction(interaction);
|
||||
responseInteraction = rollMsg;
|
||||
}
|
||||
}
|
||||
|
||||
if (ownerId === userInteractingId) {
|
||||
commands.roll(responseInteraction, rollStr.split(argSpacesSplitRegex), '');
|
||||
} else {
|
||||
commands.roll(responseInteraction, rollStr.split(argSpacesSplitRegex), '', BigInt(userInteractingId), BigInt(ownerId));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +163,9 @@ export const interactionCreateHandler = async (interaction: Interaction) => {
|
|||
{
|
||||
color: failColor,
|
||||
title: 'Not Allowed!',
|
||||
description: 'Only the original user that requested this roll can repeat it.',
|
||||
description: `Only the original user that requested this roll can repeat it.
|
||||
|
||||
Do you want to be able to use the \`Repeat Roll\` button on any rolls from anyone? Ask your Guild Owner or Admins to run \`${config.prefix}repeat enable\`. More information can be found in the help library under \`Unrestricted Repeat\`.`,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -220,6 +252,12 @@ export const interactionCreateHandler = async (interaction: Interaction) => {
|
|||
commands.toggleInline(interaction, [subCommand]);
|
||||
return;
|
||||
}
|
||||
case slashCommandDetails.toggleRepeatSC.name: {
|
||||
const option = (interaction.data.options as ApplicationCommandInteractionDataOptionSubCommand[])?.shift();
|
||||
const subCommand = option ? option.name : '';
|
||||
commands.toggleRepeat(interaction, [subCommand]);
|
||||
return;
|
||||
}
|
||||
case slashCommandDetails.versionSC.name:
|
||||
commands.version(interaction);
|
||||
return;
|
||||
|
|
|
@ -8,7 +8,7 @@ import { commands } from 'commands/_index.ts';
|
|||
import { ignoreList, inlineList } from 'db/common.ts';
|
||||
import { argSpacesSplitRegex } from 'artigen/utils/escape.ts';
|
||||
|
||||
export const messageCreateHandler = (message: DiscordenoMessage) => {
|
||||
export const messageCreateHandler = (message: DiscordenoMessage, overrideAuthor?: bigint) => {
|
||||
// Ignore all other bots
|
||||
if (message.isBot) return;
|
||||
|
||||
|
@ -31,6 +31,7 @@ export const messageCreateHandler = (message: DiscordenoMessage) => {
|
|||
.split(argSpacesSplitRegex)
|
||||
.filter((x) => x),
|
||||
'',
|
||||
overrideAuthor,
|
||||
);
|
||||
}
|
||||
// return as we are done handling this message
|
||||
|
@ -160,11 +161,16 @@ export const messageCreateHandler = (message: DiscordenoMessage) => {
|
|||
// Manage and roll using aliases
|
||||
commands.alias(message, argSpaces);
|
||||
break;
|
||||
case 'repeat':
|
||||
// [[repeat arg
|
||||
// Enable or Disable unrestricted repeat rolling
|
||||
commands.toggleRepeat(message, args);
|
||||
break;
|
||||
case 'roll':
|
||||
case 'r':
|
||||
// [[roll or [[r
|
||||
// Dice rolling commence!
|
||||
commands.roll(message, argSpaces, '');
|
||||
commands.roll(message, argSpaces, '', overrideAuthor);
|
||||
break;
|
||||
default:
|
||||
// Non-standard commands
|
||||
|
@ -175,7 +181,7 @@ export const messageCreateHandler = (message: DiscordenoMessage) => {
|
|||
} else if (command && `${command}${args.join('')}`.includes(config.postfix)) {
|
||||
// [[roll]]
|
||||
// Dice rolling commence!
|
||||
commands.roll(message, argSpaces, `${config.prefix}${command}`);
|
||||
commands.roll(message, argSpaces, `${config.prefix}${command}`, overrideAuthor);
|
||||
} else if (command) {
|
||||
// [[emoji or [[emoji-alias
|
||||
// Check if the unhandled command is an emoji request
|
||||
|
|
|
@ -22,6 +22,7 @@ const sendOrInteract = async (
|
|||
callLocation: string,
|
||||
payload: CreateMessage,
|
||||
tryGetOriginal = false,
|
||||
mentionUser = true,
|
||||
): Promise<void | DiscordenoMessage> => {
|
||||
let newMsg;
|
||||
if (hasOwnProperty(msgOrInt, 'token')) {
|
||||
|
@ -32,7 +33,7 @@ const sendOrInteract = async (
|
|||
}).catch((e: Error) => messageSendError(callLocation, interaction, e));
|
||||
if (tryGetOriginal) newMsg = await getOriginalInteractionResponse(interaction.token);
|
||||
} else {
|
||||
newMsg = await msgOrInt.reply(payload).catch((e: Error) => messageSendError(callLocation, msgOrInt, e));
|
||||
newMsg = await msgOrInt.reply(payload, mentionUser).catch((e: Error) => messageSendError(callLocation, msgOrInt, e));
|
||||
}
|
||||
return newMsg;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue