Skip to content

Commit

Permalink
Admin commands + purge (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa authored Mar 3, 2024
1 parent 2e9c5c7 commit f9fe606
Show file tree
Hide file tree
Showing 11 changed files with 552 additions and 78 deletions.
2 changes: 2 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ steps:
from_secret: DISCORD_GUILD_ID
DISCORD_OWNER_ID:
from_secret: DISCORD_OWNER_ID
DRONE_TOKEN:
from_secret: DRONE_TOKEN
DISCORD_CLIENT_SECRET:
from_secret: DISCORD_CLIENT_SECRET
DISCORD_CLIENT_REDIRECT_URI:
Expand Down
6 changes: 5 additions & 1 deletion assets/data/combinedDB.json
Original file line number Diff line number Diff line change
Expand Up @@ -20749,7 +20749,7 @@
"exact toxic dosage is unknown"
],
"tolerance": {
"full": "develops with prolonged and repeated use",
"full": null,
"half": "3 - 7 days",
"zero": "1 - 2 weeks"
},
Expand Down Expand Up @@ -26559,6 +26559,10 @@
"url": "https://psychonautwiki.org/wiki/Eugeroics",
"name": "Eugeroics"
},
{
"url": "https://psychonautwiki.org/wiki/Experience:%22DPH_(700mg,_Oral)_-_Arachnophobia_Awakened",
"name": "Experience:\"DPH (700mg, Oral) - Arachnophobia Awakened"
},
{
"url": "https://psychonautwiki.org/wiki/F-Phenibut",
"name": "F-Phenibut",
Expand Down
123 changes: 122 additions & 1 deletion assets/data/psychonautDB.json
Original file line number Diff line number Diff line change
Expand Up @@ -15817,7 +15817,7 @@
]
},
"tolerance": {
"full": "develops with prolonged and repeated use",
"full": null,
"half": "3 - 7 days",
"zero": "1 - 2 weeks"
},
Expand Down Expand Up @@ -20048,6 +20048,127 @@
"dangerousInteractions": null,
"roa": null
},
{
"url": "https://psychonautwiki.org/wiki/Experience:%22DPH_(700mg,_Oral)_-_Arachnophobia_Awakened",
"name": "Experience:\"DPH (700mg, Oral) - Arachnophobia Awakened",
"summary": "",
"addictionPotential": null,
"toxicity": null,
"crossTolerances": null,
"commonNames": null,
"class": {
"chemical": [
"Substituted tryptamines"
],
"psychoactive": [
"Psychedelic"
]
},
"tolerance": null,
"uncertainInteractions": null,
"unsafeInteractions": null,
"dangerousInteractions": null,
"roa": {
"oral": {
"name": "oral",
"dose": {
"units": "mg",
"threshold": null,
"heavy": null,
"common": null,
"light": null,
"strong": null
},
"duration": {
"afterglow": {
"min": null,
"max": null,
"units": "hours"
},
"comeup": {
"min": null,
"max": null,
"units": "minutes"
},
"duration": null,
"offset": {
"min": null,
"max": null,
"units": "hours"
},
"onset": {
"min": null,
"max": null,
"units": "minutes"
},
"peak": {
"min": null,
"max": null,
"units": "hours"
},
"total": {
"min": null,
"max": null,
"units": "hours"
}
},
"bioavailability": null
},
"sublingual": {
"name": "sublingual",
"dose": {
"units": "mg",
"threshold": null,
"heavy": null,
"common": null,
"light": null,
"strong": null
},
"duration": {
"afterglow": {
"min": null,
"max": null,
"units": "hours"
},
"comeup": {
"min": null,
"max": null,
"units": "minutes"
},
"duration": null,
"offset": {
"min": null,
"max": null,
"units": "hours"
},
"onset": {
"min": null,
"max": null,
"units": "minutes"
},
"peak": {
"min": null,
"max": null,
"units": "hours"
},
"total": {
"min": null,
"max": null,
"units": "hours"
}
},
"bioavailability": null
},
"buccal": null,
"insufflated": null,
"rectal": null,
"transdermal": null,
"subcutaneous": null,
"intramuscular": null,
"intravenous": null,
"smoked": null
}
},
{
"url": "https://psychonautwiki.org/wiki/F-Phenibut",
"name": "F-Phenibut",
Expand Down
8 changes: 8 additions & 0 deletions src/discord/@types/commandDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
// InteractionReplyOptions,
// InteractionEditReplyOptions,
Message,
InteractionReplyOptions,
} from 'discord.js';

export interface SlashCommand {
Expand All @@ -17,6 +18,13 @@ export interface SlashCommand {
execute: (interaction: ChatInputCommandInteraction) => Promise<boolean>;
}

export interface SlashCommandReply {
data:
| Omit<SlashCommandBuilder, 'addSubcommandGroup' | 'addSubcommand'>
| SlashCommandSubcommandsOnlyBuilder;
execute: (interaction: ChatInputCommandInteraction) => Promise<InteractionReplyOptions>;
}

export interface SlashCommandBeta {
data:
| Omit<SlashCommandBuilder, 'addSubcommandGroup' | 'addSubcommand'>
Expand Down
49 changes: 0 additions & 49 deletions src/discord/commands/archive/d.admin.ts

This file was deleted.

111 changes: 111 additions & 0 deletions src/discord/commands/guild/d.admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {
ChatInputCommandInteraction,
SlashCommandBuilder,
TextChannel,
} from 'discord.js';
import axios from 'axios';
import { stripIndents } from 'common-tags';
import { SlashCommand } from '../../@types/commandDef';
import commandContext from '../../utils/context';
import deployCommands from '../../utils/commandDeploy';

const F = f(__filename);

async function restart(
interaction: ChatInputCommandInteraction,
):Promise<void> {
log.info(F, 'Restarting');
await interaction.editReply('Restarting');
const channelTripbot = interaction.guild?.channels.cache.get(env.CHANNEL_BOTLOG) as TextChannel;
if (channelTripbot) {
await channelTripbot.send(`${interaction.member} restarted the bot <@${env.DISCORD_OWNER_ID}>.`);
}
// This doesn't work for some reason
// Process.exit() doesn't work in a lambda function
process.kill(process.pid, 'SIGTERM');
}

async function rebuild(
interaction: ChatInputCommandInteraction,
):Promise<void> {
log.info(F, 'Rebuilding');
await interaction.editReply('Rebuilding');
const channelTripbot = interaction.guild?.channels.cache.get(env.CHANNEL_BOTLOG) as TextChannel;
if (channelTripbot) {
await channelTripbot.send(`${interaction.member} triggered a rebuild <@${env.DISCORD_OWNER_ID}>.`);
}

axios.post('https://drone.tripsit.me/api/repos/TripSit/TripBot/builds', {}, {
headers: { Authorization: `Bearer ${env.DRONE_TOKEN}` },
})
.then(response => {
log.debug(F, `Build triggered successfully ${JSON.stringify(response.data, null, 2)}`);
})
.catch(error => {
log.error(F, `Error triggering build ${JSON.stringify(error, null, 2)}`);
});
}

async function deploy(
interaction: ChatInputCommandInteraction,
):Promise<void> {
log.info(F, 'Deploying commands');
await interaction.editReply('Deploying commands!!');
const channelTripbot = interaction.guild?.channels.cache.get(env.CHANNEL_BOTLOG) as TextChannel;
if (channelTripbot) {
await channelTripbot.send(`${interaction.member} triggered a command deploy <@${env.DISCORD_OWNER_ID}>.`);
}
const commandData = await deployCommands();
// log.debug(F, `CommandData: ${JSON.stringify(commandData, null, 2)}`);
log.info(F, stripIndents`
I deployed ${commandData.globalCommands.length + commandData.guildCommands.length} commands!
${commandData.globalCommands.length} global commands and ${commandData.guildCommands.length} guild commands`);
await interaction.editReply(stripIndents`
I deployed ${commandData.globalCommands.length + commandData.guildCommands.length} commands!
${commandData.globalCommands.length} global commands and ${commandData.guildCommands.length} guild commands`);
}

export const dAdmin: SlashCommand = {
data: new SlashCommandBuilder()
.setName('admin')
.setDescription('Admin Commands')
// .addSubcommand(subcommand => subcommand
// .setName('restart')
// .setDescription('Restart the bot'))
.addSubcommand(subcommand => subcommand
.setName('rebuild')
.setDescription('Rebuild the bot'))
.addSubcommand(subcommand => subcommand
.setName('deploy')
.setDescription('Deploy commands')),
async execute(interaction) {
if (!interaction.channel) return false;
if (!interaction.guild) return false;
log.info(F, await commandContext(interaction));
const command = interaction.options.getSubcommand() as 'restart' | 'rebuild' | 'deploy';
// By default we want to make the reply private
await interaction.deferReply({ ephemeral: true });
// eslint-disable-next-line sonarjs/no-small-switch
switch (command) {
case 'restart': {
await restart(interaction);
break;
}
case 'rebuild': {
await rebuild(interaction);
break;
}
case 'deploy': {
await deploy(interaction);
break;
}
default: {
log.debug(F, `default ${command}`);
await interaction.editReply('Command not found');
}
}
return true;
},
};

export default dAdmin;
Loading

0 comments on commit f9fe606

Please sign in to comment.