Skip to content

Commit

Permalink
Merge pull request #26 from raid-guild/feat/add-scribe-command
Browse files Browse the repository at this point in the history
Add tipScribe command
  • Loading branch information
ECWireless authored May 2, 2024
2 parents cfc2891 + 6e83677 commit 6a07888
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 21 deletions.
12 changes: 12 additions & 0 deletions src/commands/characterSheets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ export const tipJesterCommand = new SlashCommandBuilder()
.setRequired(true)
);

export const tipScribeCommand = new SlashCommandBuilder()
.setName('tip-scribe')
.setDescription('Gives the meeting Scribe 50 Scribe XP (CharacterSheets)')
.addStringOption(option =>
option
.setName('recipient')
.setDescription(
'Use @mention to tip an existing character in CharacterSheets'
)
.setRequired(true)
);

export const syncInvoiceDataCommand = new SlashCommandBuilder()
.setName('sync-invoice-data')
.setDescription(
Expand Down
4 changes: 3 additions & 1 deletion src/deploy-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
queryCommand,
// syncInvoiceDataCommand,
tipJesterCommand,
tipScribeCommand,
propsCommand
// tipXpMcCommand
} from '@/commands';
Expand All @@ -17,7 +18,8 @@ const commands = [
propsCommand.toJSON(),
queryCommand.toJSON(),
// syncInvoiceDataCommand.toJSON(),
tipJesterCommand.toJSON()
tipJesterCommand.toJSON(),
tipScribeCommand.toJSON()
// tipXpAttendanceCommand.toJSON()
];

Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
queryCommand,
syncInvoiceDataCommand,
tipJesterCommand,
tipScribeCommand,
tipXpAttendanceCommand
} from '@/commands';
import { setupGuardWorker } from '@/guardWorker';
Expand All @@ -22,7 +23,8 @@ import {
queryInteraction,
syncInvoiceDataInteraction,
tipXpAttendanceInteraction,
tipJesterInteraction
tipJesterInteraction,
tipScribeInteraction
} from '@/interactions';
import { completeJesterTip } from '@/interactions';
import { getMcTipProposal } from '@/lib';
Expand All @@ -49,6 +51,7 @@ export const setupDungeonMasterWorker = () => {
client.commands.set(queryCommand.name, queryCommand);
client.commands.set(syncInvoiceDataCommand.name, syncInvoiceDataCommand);
client.commands.set(tipJesterCommand.name, tipJesterCommand);
client.commands.set(tipScribeCommand.name, tipScribeCommand);
client.commands.set(tipXpAttendanceCommand.name, tipXpAttendanceCommand);

client.once(Events.ClientReady, c => {
Expand All @@ -72,6 +75,7 @@ export const setupDungeonMasterWorker = () => {
const allowedAnywhereCommands = [
propsCommand.name,
tipJesterCommand.name,
tipScribeCommand.name,
tipXpAttendanceCommand.name
];

Expand Down Expand Up @@ -102,6 +106,9 @@ export const setupDungeonMasterWorker = () => {
case tipJesterCommand.name:
await tipJesterInteraction(client, interaction);
break;
case tipScribeCommand.name:
await tipScribeInteraction(client, interaction);
break;
case tipXpAttendanceCommand.name:
await tipXpAttendanceInteraction(client, interaction);
break;
Expand Down
1 change: 1 addition & 0 deletions src/interactions/cs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from '@/interactions/cs/props';
export * from '@/interactions/cs/tipXpAttendance';
export * from '@/interactions/cs/tipJester';
export * from '@/interactions/cs/tipJester/completeJesterTip';
export * from '@/interactions/cs/tipScribe';
12 changes: 6 additions & 6 deletions src/interactions/cs/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import {
updateLatestXpTip
} from '@/lib';
import { ClientWithCommands } from '@/types';
import { EXPLORER_URL } from '@/utils/constants';
import { CHAIN_ID, EXPLORER_URL } from '@/utils/constants';
import { discordLogger } from '@/utils/logger';

const TIP_AMOUNT = '10';
const TABLE_NAME = 'latestProps';

export const propsInteraction = async (
client: ClientWithCommands,
interaction:
| ChatInputCommandInteraction
| MessageContextMenuCommandInteraction
| UserContextMenuCommandInteraction
) => {
const TIP_AMOUNT = '10';
const TABLE_NAME = 'latestXpTips';

if (!EXPLORER_URL) {
discordLogger('Missing EXPLORER_URL env', client);
return;
Expand Down Expand Up @@ -229,12 +229,12 @@ export const propsInteraction = async (
lastSenderDiscordId: senderId,
newSenderDiscordId: senderId,
senderDiscordTag: interaction.user.tag,
chainId: '5',
chainId: CHAIN_ID,
txHash,
message
};

await updateLatestXpTip(client, 'latestXpTips', data);
await updateLatestXpTip(client, TABLE_NAME, data);

await interaction.editReply({
embeds: [embed]
Expand Down
10 changes: 5 additions & 5 deletions src/interactions/cs/tipJester/completeJesterTip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
MessageReaction
} from 'discord.js';

import { JESTER_TIP_AMOUNT } from '@/interactions/cs/tipJester';
import { JESTER_TIP_AMOUNT, TABLE_NAME } from '@/interactions/cs/tipJester';
import { giveClassExp, updateLatestXpMcTip } from '@/lib';
import { JesterTipData } from '@/lib/dbHelpers';
import { ClientWithCommands } from '@/types';
Expand Down Expand Up @@ -54,7 +54,7 @@ export const completeJesterTip = async (
txHash: '',
tipPending: true
};
await updateLatestXpMcTip(client, 'latestXpMcTips', data);
await updateLatestXpMcTip(client, TABLE_NAME, data);

const tx = await giveClassExp(client, receivingAddress, '14');
if (!tx) {
Expand All @@ -64,7 +64,7 @@ export const completeJesterTip = async (
txHash: '',
tipPending: false
};
await updateLatestXpMcTip(client, 'latestXpMcTips', data);
await updateLatestXpMcTip(client, TABLE_NAME, data);
return;
}

Expand Down Expand Up @@ -96,7 +96,7 @@ export const completeJesterTip = async (
txHash,
tipPending: false
};
await updateLatestXpMcTip(client, 'latestXpMcTips', data);
await updateLatestXpMcTip(client, TABLE_NAME, data);

embed = new EmbedBuilder()
.setTitle(
Expand Down Expand Up @@ -135,7 +135,7 @@ export const completeJesterTip = async (
tipPending: false
};

await updateLatestXpMcTip(client, 'latestXpMcTips', data);
await updateLatestXpMcTip(client, TABLE_NAME, data);

if (proposalMessage) {
await proposalMessage.edit({ embeds: [embed] });
Expand Down
28 changes: 20 additions & 8 deletions src/interactions/cs/tipJester/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { discordLogger } from '@/utils/logger';
import { completeJesterTip } from './completeJesterTip';

export const JESTER_TIP_AMOUNT = '50';
export const TABLE_NAME = 'latestJesterTips';
const MINIMUM_ATTENDEES = 6;
const PROPOSAL_EXPIRATION_TIME = 5 * 60 * 1000; // 5 minutes

export const tipJesterInteraction = async (
client: ClientWithCommands,
Expand All @@ -33,11 +36,6 @@ export const tipJesterInteraction = async (
| MessageContextMenuCommandInteraction
| UserContextMenuCommandInteraction
) => {
const TABLE_NAME = 'latestXpMcTips';

const MINIMUM_ATTENDEES = 2;
const PROPOSAL_EXPIRATION_TIME = 60 * 1000; // 5 minutes

if (!EXPLORER_URL) {
discordLogger('Missing EXPLORER_URL env', client);
return;
Expand Down Expand Up @@ -71,7 +69,7 @@ export const tipJesterInteraction = async (

if (needsCooldown) {
const embed = new EmbedBuilder()
.setTitle('<:jester:1222930129999626271> Jester Tipping Cooldown')
.setTitle('<:jester:1222930129999626271> Jester Tip Cooldown')
.setDescription(
`All members must wait ${
endTime
Expand All @@ -93,6 +91,20 @@ export const tipJesterInteraction = async (
const voiceChannel = interaction.guild?.channels.cache.get(
channelId ?? ''
) as VoiceBasedChannel;

if (!voiceChannel.isVoiceBased()) {
const embed = new EmbedBuilder()
.setTitle('Not a Voice Channel')
.setDescription(`You must be in a voice channel to tip the Jester.`)
.setColor('#ff3864')
.setTimestamp();

await interaction.followUp({
embeds: [embed]
});
return;
}

const { members } = voiceChannel;
const discordAttendeeMembers = members.map(m => m);

Expand Down Expand Up @@ -228,6 +240,7 @@ export const tipJesterInteraction = async (
const isSyncSteward = senderId === process.env.DISCORD_SYNC_STEWARD_ID;

if (isSyncSteward && interaction.channel) {
await updateLatestXpMcTip(client, TABLE_NAME, jesterTipData);
await completeJesterTip(
client,
{
Expand Down Expand Up @@ -261,7 +274,6 @@ export const tipJesterInteraction = async (
await interaction.followUp({
content: '@here ^^^'
});
await updateLatestXpMcTip(client, TABLE_NAME, jesterTipData);
}

await updateLatestXpMcTip(client, TABLE_NAME, jesterTipData);
};
Loading

0 comments on commit 6a07888

Please sign in to comment.