2021-01-07 05:34:14 -08:00
|
|
|
/* The Artificer was built in memory of Babka
|
|
|
|
* With love, Ean
|
|
|
|
*
|
|
|
|
* December 21, 2020
|
|
|
|
*/
|
|
|
|
|
2022-05-20 01:43:22 -07:00
|
|
|
import config from './config.ts';
|
|
|
|
import { DEBUG, DEVMODE, LOCALMODE } from './flags.ts';
|
2021-01-07 05:34:14 -08:00
|
|
|
import {
|
2022-05-20 01:43:22 -07:00
|
|
|
botId,
|
|
|
|
cache,
|
|
|
|
DiscordActivityTypes,
|
|
|
|
DiscordenoGuild,
|
|
|
|
DiscordenoMessage,
|
|
|
|
editBotNickname,
|
|
|
|
editBotStatus,
|
|
|
|
initLog,
|
2021-11-21 19:14:57 -08:00
|
|
|
Intents,
|
2022-05-20 01:43:22 -07:00
|
|
|
log,
|
2022-05-04 23:49:06 -07:00
|
|
|
// Log4Deno deps
|
2022-05-20 01:43:22 -07:00
|
|
|
LT,
|
|
|
|
sendMessage,
|
|
|
|
// Discordeno deps
|
|
|
|
startBot,
|
|
|
|
} from './deps.ts';
|
|
|
|
import api from './src/api.ts';
|
|
|
|
import commands from './src/commands/_index.ts';
|
|
|
|
import intervals from './src/intervals.ts';
|
|
|
|
import utils from './src/utils.ts';
|
2021-01-27 00:34:49 -08:00
|
|
|
|
2021-03-14 20:27:53 -07:00
|
|
|
// Initialize logging client with folder to use for logs, needs --allow-write set on Deno startup
|
2022-05-20 01:43:22 -07:00
|
|
|
initLog('logs', DEBUG);
|
2021-03-14 20:27:53 -07:00
|
|
|
|
2021-01-14 05:47:18 -08:00
|
|
|
// Start up the Discord Bot
|
2021-01-07 05:34:14 -08:00
|
|
|
startBot({
|
V1.4.0 Completed
This update adds a handful of new features and readies the API for public use. Detailed changes below:
config.example.ts - Bumped version, added local testing options, added prefill data, changed default logging to false, moved long strings for help and rollhelp to longStrings.ts
db/initialize.ts (previously initDB.ts) - Relocated file for organization, added local options, added new command count and allowed guilds table, created stored procedure for counting commands
db/populateDefaults.ts - Fills in db with default values, adding admin's api key and populating the command count table
flags.ts - Centralized flags for dev/local modes
longStrings.ts - Moved all long string commands to here, contains help, rollhelp, apihelp, info, and privacy commands
mod.ts - Moved flags out into flags.ts, implemented local mode for development, implemented command counting for basic statistics, added info and privacy commands for user help, added more stats to the stats command, added api command, allowing users to allow or block api rolls from happening in their server, reformatted API code, using proper HTTP methods, makes sure api is allowed to roll into chosen guild, added delete endpoint to remove user's data from the database, added endpoint to allow the general public to generate their own api keys
PRIVACY.md - I got bored and wrote a privacy policy, detailing how little data is collected and how the user can have their data removed
README.md - Added new commands to README, updated API documentation, added delete endpoint, updated self hosting details
src/utils.ts - Bumped discordeno version
www/api - Built API website
www/home (previously located in www) - Moved for better organization, minor fixes, updated API details,
2021-02-12 20:26:33 -08:00
|
|
|
token: LOCALMODE ? config.localtoken : config.token,
|
2021-11-21 19:14:57 -08:00
|
|
|
intents: [Intents.GuildMessages, Intents.DirectMessages, Intents.Guilds],
|
2021-01-07 05:34:14 -08:00
|
|
|
eventHandlers: {
|
|
|
|
ready: () => {
|
2022-05-04 23:49:06 -07:00
|
|
|
log(LT.INFO, `${config.name} Logged in!`);
|
2021-11-21 19:14:57 -08:00
|
|
|
editBotStatus({
|
|
|
|
activities: [{
|
2022-05-20 01:43:22 -07:00
|
|
|
name: 'Booting up . . .',
|
2021-11-21 19:14:57 -08:00
|
|
|
type: DiscordActivityTypes.Game,
|
2022-05-20 01:43:22 -07:00
|
|
|
createdAt: new Date().getTime(),
|
2021-11-21 19:14:57 -08:00
|
|
|
}],
|
2022-05-20 01:43:22 -07:00
|
|
|
status: 'online',
|
2021-11-21 19:14:57 -08:00
|
|
|
});
|
2021-02-19 17:44:38 -08:00
|
|
|
|
|
|
|
// Interval to rotate the status text every 30 seconds to show off more commands
|
2021-11-21 19:14:57 -08:00
|
|
|
setInterval(async () => {
|
2022-05-20 01:43:22 -07:00
|
|
|
log(LT.LOG, 'Changing bot status');
|
2021-02-19 17:44:38 -08:00
|
|
|
try {
|
|
|
|
// Wrapped in try-catch due to hard crash possible
|
2021-11-21 19:14:57 -08:00
|
|
|
editBotStatus({
|
|
|
|
activities: [{
|
|
|
|
name: await intervals.getRandomStatus(),
|
|
|
|
type: DiscordActivityTypes.Game,
|
2022-05-20 01:43:22 -07:00
|
|
|
createdAt: new Date().getTime(),
|
2021-11-21 19:14:57 -08:00
|
|
|
}],
|
2022-05-20 01:43:22 -07:00
|
|
|
status: 'online',
|
2021-11-21 19:14:57 -08:00
|
|
|
});
|
2021-03-14 20:27:53 -07:00
|
|
|
} catch (e) {
|
2022-05-04 23:49:06 -07:00
|
|
|
log(LT.ERROR, `Failed to update status: ${JSON.stringify(e)}`);
|
2021-02-19 17:44:38 -08:00
|
|
|
}
|
2021-02-12 22:59:25 -08:00
|
|
|
}, 30000);
|
2021-02-19 17:44:38 -08:00
|
|
|
|
2021-03-13 12:10:35 -08:00
|
|
|
// Interval to update bot list stats every 24 hours
|
2022-05-20 01:43:22 -07:00
|
|
|
LOCALMODE ? log(LT.INFO, 'updateListStatistics not running') : setInterval(() => {
|
|
|
|
log(LT.LOG, 'Updating all bot lists statistics');
|
2021-11-21 19:14:57 -08:00
|
|
|
intervals.updateListStatistics(botId, cache.guilds.size);
|
2021-03-27 21:29:06 -07:00
|
|
|
}, 86400000);
|
2021-03-13 12:10:35 -08:00
|
|
|
|
2021-01-07 11:00:46 -08:00
|
|
|
// setTimeout added to make sure the startup message does not error out
|
2021-01-07 05:34:14 -08:00
|
|
|
setTimeout(() => {
|
2021-11-21 19:14:57 -08:00
|
|
|
LOCALMODE && editBotNickname(config.devServer, `LOCAL - ${config.name}`);
|
2022-05-20 01:43:22 -07:00
|
|
|
LOCALMODE ? log(LT.INFO, 'updateListStatistics not running') : intervals.updateListStatistics(botId, cache.guilds.size);
|
2021-11-21 19:14:57 -08:00
|
|
|
editBotStatus({
|
|
|
|
activities: [{
|
2022-05-20 01:43:22 -07:00
|
|
|
name: 'Booting Complete',
|
2021-11-21 19:14:57 -08:00
|
|
|
type: DiscordActivityTypes.Game,
|
2022-05-20 01:43:22 -07:00
|
|
|
createdAt: new Date().getTime(),
|
2021-11-21 19:14:57 -08:00
|
|
|
}],
|
2022-05-20 01:43:22 -07:00
|
|
|
status: 'online',
|
2021-11-21 19:14:57 -08:00
|
|
|
});
|
2022-05-20 01:43:22 -07:00
|
|
|
sendMessage(config.logChannel, `${config.name} has started, running version ${config.version}.`).catch((e) => {
|
2022-05-04 23:49:06 -07:00
|
|
|
log(LT.ERROR, `Failed to send message: ${JSON.stringify(e)}`);
|
2021-01-07 05:34:14 -08:00
|
|
|
});
|
|
|
|
}, 1000);
|
|
|
|
},
|
2021-11-21 19:14:57 -08:00
|
|
|
guildCreate: (guild: DiscordenoGuild) => {
|
2022-05-04 23:49:06 -07:00
|
|
|
log(LT.LOG, `Handling joining guild ${JSON.stringify(guild)}`);
|
2022-05-20 01:43:22 -07:00
|
|
|
sendMessage(config.logChannel, `New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`).catch((e) => {
|
2022-05-04 23:49:06 -07:00
|
|
|
log(LT.ERROR, `Failed to send message: ${JSON.stringify(e)}`);
|
2021-01-07 05:34:14 -08:00
|
|
|
});
|
|
|
|
},
|
2021-11-21 19:14:57 -08:00
|
|
|
guildDelete: (guild: DiscordenoGuild) => {
|
2022-05-04 23:49:06 -07:00
|
|
|
log(LT.LOG, `Handling leaving guild ${JSON.stringify(guild)}`);
|
2022-05-20 01:43:22 -07:00
|
|
|
sendMessage(config.logChannel, `I have been removed from: ${guild.name} (id: ${guild.id}).`).catch((e) => {
|
2022-05-04 23:49:06 -07:00
|
|
|
log(LT.ERROR, `Failed to send message: ${JSON.stringify(e)}`);
|
2021-01-07 05:34:14 -08:00
|
|
|
});
|
|
|
|
},
|
2022-05-20 01:43:22 -07:00
|
|
|
debug: DEVMODE ? (dmsg) => log(LT.LOG, `Debug Message | ${JSON.stringify(dmsg)}`) : () => {},
|
2022-05-04 21:57:34 -07:00
|
|
|
messageCreate: (message: DiscordenoMessage) => {
|
2021-01-07 05:34:14 -08:00
|
|
|
// Ignore all other bots
|
2021-11-21 19:14:57 -08:00
|
|
|
if (message.isBot) return;
|
2022-05-20 01:43:22 -07:00
|
|
|
|
2021-01-07 05:34:14 -08:00
|
|
|
// Ignore all messages that are not commands
|
2022-05-13 15:57:45 -07:00
|
|
|
if (message.content.indexOf(config.prefix) !== 0) {
|
|
|
|
// Handle @bot messages
|
|
|
|
if (message.mentionedUserIds[0] === botId && (message.content.trim().startsWith(`<@${botId}>`) || message.content.trim().startsWith(`<@!${botId}>`))) {
|
|
|
|
commands.handleMentions(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return as we are done handling this command
|
|
|
|
return;
|
|
|
|
}
|
2022-05-20 01:43:22 -07:00
|
|
|
|
2022-05-13 16:25:23 -07:00
|
|
|
log(LT.LOG, `Handling ${config.prefix}command message: ${JSON.stringify(message)}`);
|
2021-01-07 05:34:14 -08:00
|
|
|
|
|
|
|
// Split into standard command + args format
|
2021-03-27 21:29:06 -07:00
|
|
|
const args = message.content.slice(config.prefix.length).trim().split(/[ \n]+/g);
|
2021-01-07 05:34:14 -08:00
|
|
|
const command = args.shift()?.toLowerCase();
|
|
|
|
|
|
|
|
// All commands below here
|
|
|
|
|
|
|
|
// [[ping
|
|
|
|
// Its a ping test, what else do you want.
|
2022-05-20 01:43:22 -07:00
|
|
|
if (command === 'ping') {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.ping(message);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[rip [[memory
|
2021-01-07 22:02:38 -08:00
|
|
|
// Displays a short message I wanted to include
|
2022-05-20 01:43:22 -07:00
|
|
|
else if (command === 'rip' || command === 'memory') {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.rip(message);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[rollhelp or [[rh or [[hr or [[??
|
2021-01-26 23:35:46 -08:00
|
|
|
// Help command specifically for the roll command
|
2022-05-20 01:43:22 -07:00
|
|
|
else if (command === 'rollhelp' || command === 'rh' || command === 'hr' || command === '??' || command?.startsWith('xdy')) {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.rollHelp(message);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[help or [[h or [[?
|
2021-01-07 05:34:14 -08:00
|
|
|
// Help command, prints from help file
|
2022-05-20 01:43:22 -07:00
|
|
|
else if (command === 'help' || command === 'h' || command === '?') {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.help(message);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[info or [[i
|
V1.4.0 Completed
This update adds a handful of new features and readies the API for public use. Detailed changes below:
config.example.ts - Bumped version, added local testing options, added prefill data, changed default logging to false, moved long strings for help and rollhelp to longStrings.ts
db/initialize.ts (previously initDB.ts) - Relocated file for organization, added local options, added new command count and allowed guilds table, created stored procedure for counting commands
db/populateDefaults.ts - Fills in db with default values, adding admin's api key and populating the command count table
flags.ts - Centralized flags for dev/local modes
longStrings.ts - Moved all long string commands to here, contains help, rollhelp, apihelp, info, and privacy commands
mod.ts - Moved flags out into flags.ts, implemented local mode for development, implemented command counting for basic statistics, added info and privacy commands for user help, added more stats to the stats command, added api command, allowing users to allow or block api rolls from happening in their server, reformatted API code, using proper HTTP methods, makes sure api is allowed to roll into chosen guild, added delete endpoint to remove user's data from the database, added endpoint to allow the general public to generate their own api keys
PRIVACY.md - I got bored and wrote a privacy policy, detailing how little data is collected and how the user can have their data removed
README.md - Added new commands to README, updated API documentation, added delete endpoint, updated self hosting details
src/utils.ts - Bumped discordeno version
www/api - Built API website
www/home (previously located in www) - Moved for better organization, minor fixes, updated API details,
2021-02-12 20:26:33 -08:00
|
|
|
// Info command, prints short desc on bot and some links
|
2022-05-20 01:43:22 -07:00
|
|
|
else if (command === 'info' || command === 'i') {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.info(message);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[privacy
|
V1.4.0 Completed
This update adds a handful of new features and readies the API for public use. Detailed changes below:
config.example.ts - Bumped version, added local testing options, added prefill data, changed default logging to false, moved long strings for help and rollhelp to longStrings.ts
db/initialize.ts (previously initDB.ts) - Relocated file for organization, added local options, added new command count and allowed guilds table, created stored procedure for counting commands
db/populateDefaults.ts - Fills in db with default values, adding admin's api key and populating the command count table
flags.ts - Centralized flags for dev/local modes
longStrings.ts - Moved all long string commands to here, contains help, rollhelp, apihelp, info, and privacy commands
mod.ts - Moved flags out into flags.ts, implemented local mode for development, implemented command counting for basic statistics, added info and privacy commands for user help, added more stats to the stats command, added api command, allowing users to allow or block api rolls from happening in their server, reformatted API code, using proper HTTP methods, makes sure api is allowed to roll into chosen guild, added delete endpoint to remove user's data from the database, added endpoint to allow the general public to generate their own api keys
PRIVACY.md - I got bored and wrote a privacy policy, detailing how little data is collected and how the user can have their data removed
README.md - Added new commands to README, updated API documentation, added delete endpoint, updated self hosting details
src/utils.ts - Bumped discordeno version
www/api - Built API website
www/home (previously located in www) - Moved for better organization, minor fixes, updated API details,
2021-02-12 20:26:33 -08:00
|
|
|
// Privacy command, prints short desc on bot's privacy policy
|
2022-05-20 01:43:22 -07:00
|
|
|
else if (command === 'privacy') {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.privacy(message);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[version or [[v
|
2021-01-07 05:34:14 -08:00
|
|
|
// Returns version of the bot
|
2022-05-20 01:43:22 -07:00
|
|
|
else if (command === 'version' || command === 'v') {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.version(message);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[report or [[r (command that failed)
|
2021-01-07 05:34:14 -08:00
|
|
|
// Manually report a failed roll
|
2022-05-20 01:43:22 -07:00
|
|
|
else if (command === 'report' || command === 'r') {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.report(message, args);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[stats or [[s
|
2021-01-07 05:34:14 -08:00
|
|
|
// Displays stats on the bot
|
2022-05-20 01:43:22 -07:00
|
|
|
else if (command === 'stats' || command === 's') {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.stats(message);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[api arg
|
V1.4.0 Completed
This update adds a handful of new features and readies the API for public use. Detailed changes below:
config.example.ts - Bumped version, added local testing options, added prefill data, changed default logging to false, moved long strings for help and rollhelp to longStrings.ts
db/initialize.ts (previously initDB.ts) - Relocated file for organization, added local options, added new command count and allowed guilds table, created stored procedure for counting commands
db/populateDefaults.ts - Fills in db with default values, adding admin's api key and populating the command count table
flags.ts - Centralized flags for dev/local modes
longStrings.ts - Moved all long string commands to here, contains help, rollhelp, apihelp, info, and privacy commands
mod.ts - Moved flags out into flags.ts, implemented local mode for development, implemented command counting for basic statistics, added info and privacy commands for user help, added more stats to the stats command, added api command, allowing users to allow or block api rolls from happening in their server, reformatted API code, using proper HTTP methods, makes sure api is allowed to roll into chosen guild, added delete endpoint to remove user's data from the database, added endpoint to allow the general public to generate their own api keys
PRIVACY.md - I got bored and wrote a privacy policy, detailing how little data is collected and how the user can have their data removed
README.md - Added new commands to README, updated API documentation, added delete endpoint, updated self hosting details
src/utils.ts - Bumped discordeno version
www/api - Built API website
www/home (previously located in www) - Moved for better organization, minor fixes, updated API details,
2021-02-12 20:26:33 -08:00
|
|
|
// API sub commands
|
2022-05-20 01:43:22 -07:00
|
|
|
else if (command === 'api') {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.api(message, args);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[roll]]
|
2021-01-07 05:34:14 -08:00
|
|
|
// Dice rolling commence!
|
2022-05-20 01:43:22 -07:00
|
|
|
else if (command && (`${command}${args.join('')}`).indexOf(config.postfix) > -1) {
|
2022-05-04 21:57:34 -07:00
|
|
|
commands.roll(message, args, command);
|
2022-05-20 01:43:22 -07:00
|
|
|
} // [[emoji or [[emojialias
|
2021-01-18 08:50:22 -08:00
|
|
|
// Check if the unhandled command is an emoji request
|
2022-05-04 21:57:34 -07:00
|
|
|
else if (command) {
|
|
|
|
commands.emoji(message, command);
|
2021-01-18 08:50:22 -08:00
|
|
|
}
|
2022-05-20 01:43:22 -07:00
|
|
|
},
|
|
|
|
},
|
2021-01-07 05:34:14 -08:00
|
|
|
});
|
|
|
|
|
2021-01-07 11:00:46 -08:00
|
|
|
// Start up the command prompt for debug usage
|
|
|
|
if (DEBUG) {
|
2021-11-21 19:14:57 -08:00
|
|
|
utils.cmdPrompt(config.logChannel, config.name);
|
2021-01-07 11:00:46 -08:00
|
|
|
}
|
2021-01-11 00:42:57 -08:00
|
|
|
|
|
|
|
// Start up the API for rolling from third party apps (like excel macros)
|
|
|
|
if (config.api.enable) {
|
2022-05-04 21:57:34 -07:00
|
|
|
api.start();
|
2021-01-11 00:42:57 -08:00
|
|
|
}
|