Skip to content

Commit

Permalink
61 stats and server settings (#123)
Browse files Browse the repository at this point in the history
* Feat/Fix: Average Wait Time and Total Active Time stats

Previously, the average session time was incorrectly calculated, it was the average helper session time, not average student session time.

* Chore: formatting

* Feat: `/settings` menu for google sheets

Documentation doesn't exist yet so I haven't added it to the embed

* Feat: `/settings` menu for serious mode and help topic prompt

* fix: missing documentation links, error handling

* style: organize base attending server

Co-authored-by: Zhongning Li <[email protected]>
  • Loading branch information
KaoushikMurugan and tomli380576 authored Jan 7, 2023
1 parent c010169 commit cf49467
Show file tree
Hide file tree
Showing 12 changed files with 1,002 additions and 595 deletions.
1,080 changes: 551 additions & 529 deletions src/attending-server/base-attending-server.ts

Large diffs are not rendered by default.

151 changes: 150 additions & 1 deletion src/attending-server/server-settings-menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const documentationLinks = {
autoClear: `${documentationBaseUrl}#queue-auto-clear`,
loggingChannel: `${documentationBaseUrl}#logging-channel`,
afterSessionMessage: `${documentationBaseUrl}#after-session-message`,
autoGiveStudentRole: `${documentationBaseUrl}#auto-give-student-role`
autoGiveStudentRole: `${documentationBaseUrl}#auto-give-student-role`,
promptHelpTopic: `${documentationBaseUrl}#help-topic-prompt`,
seriousMode: `${documentationBaseUrl}#serious-mode`
};

/**
Expand Down Expand Up @@ -111,6 +113,24 @@ const serverSettingsMainMenuOptions: SettingsMenuOption[] = [
value: 'auto-give-student-role'
},
subMenu: AutoGiveStudentRoleConfigMenu
},
{
optionData: {
emoji: '🙋',
label: 'Help Topic Prompt',
description: 'Configure the help topic prompt',
value: 'help-topic-prompt'
},
subMenu: PromptHelpTopicConfigMenu
},
{
optionData: {
emoji: '🧐',
label: 'Serious Mode',
description: 'Configure the serious mode',
value: 'serious-mode'
},
subMenu: SeriousModeConfigMenu
}
];

Expand Down Expand Up @@ -626,6 +646,14 @@ function LoggingChannelConfigMenu(
};
}

/**
* Composes the auto give student role configuration menu
* @param server
* @param channelId
* @param isDm
* @param updateMessage
* @returns
*/
function AutoGiveStudentRoleConfigMenu(
server: AttendingServerV2,
channelId: string,
Expand Down Expand Up @@ -677,6 +705,125 @@ function AutoGiveStudentRoleConfigMenu(
return { embeds: [embed.data], components: [buttons, mainMenuRow] };
}

/**
* Composes the help topic prompt configuration menu
* @param server
* @param channelId
* @param isDm
* @param updateMessage
* @returns
*/
function PromptHelpTopicConfigMenu(
server: AttendingServerV2,
channelId: string,
isDm: boolean,
updateMessage = ''
): YabobEmbed {
const embed = new EmbedBuilder()
.setTitle(`🙋 Help Topic Prompt Configuration for ${server.guild.name} 🙋`)
.setColor(EmbedColor.Aqua)
.addFields(
{
name: 'Description',
value: `Whether to prompt students to select a help topic when they join the queue.`
},
{
name: 'Documentation',
value: `[Learn more about help topic prompts here.](${documentationLinks.promptHelpTopic})` //TODO: Add documentation link
},
{
name: 'Current Configuration',
value: server.promptHelpTopic
? `**Enabled** - Students will be prompted to enter a help topic when they join the queue.`
: `**Disabled** - Students will not be prompted when they join the queue.`
}
);
if (updateMessage.length > 0) {
embed.setFooter({ text: `✅ ${updateMessage}` });
}
const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents(
buildComponent(new ButtonBuilder(), [
isDm ? 'dm' : 'other',
ButtonNames.PromptHelpTopicConfig1,
server.guild.id,
channelId
])
.setEmoji('🔓')
.setLabel('Enable')
.setStyle(ButtonStyle.Secondary),
buildComponent(new ButtonBuilder(), [
isDm ? 'dm' : 'other',
ButtonNames.PromptHelpTopicConfig2,
server.guild.id,
channelId
])
.setEmoji('🔒')
.setLabel('Disable')
.setStyle(ButtonStyle.Secondary)
);
return { embeds: [embed.data], components: [buttons, mainMenuRow] };
}

/**
* Composes the serious mode configuration menu
* @param server
* @param channelId
* @param isDm
* @param updateMessage
* @returns
*/
function SeriousModeConfigMenu(
server: AttendingServerV2,
channelId: string,
isDm: boolean,
updateMessage = ''
): YabobEmbed {
const embed = new EmbedBuilder()
.setTitle(`🧐 Serious Mode Configuration for ${server.guild.name} 🧐`)
.setColor(EmbedColor.Aqua)
.addFields(
{
name: 'Description',
value: `When serious mode is enabled, YABOB will not use emojis or emoticons for fun purposes (e.g. Sleeping emoticon when queue is closed). This will also disable any commands that\
are not related to queue management`
},
{
name: 'Documentation',
value: `[Learn more about serious mode here.](${documentationLinks.seriousMode})` //TODO: Add documentation link
},
{
name: 'Current Configuration',
value: server.isSeriousServer()
? `**Enabled** - YABOB will not use emojis or emoticons for fun purposes.`
: `**Disabled** - YABOB can use emojis and emoticons for fun purposes.`
}
);
if (updateMessage.length > 0) {
embed.setFooter({ text: `✅ ${updateMessage}` });
}
const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents(
buildComponent(new ButtonBuilder(), [
isDm ? 'dm' : 'other',
ButtonNames.SeriousModeConfig1,
server.guild.id,
channelId
])
.setEmoji('🔓')
.setLabel('Enable')
.setStyle(ButtonStyle.Secondary),
buildComponent(new ButtonBuilder(), [
isDm ? 'dm' : 'other',
ButtonNames.SeriousModeConfig2,
server.guild.id,
channelId
])
.setEmoji('🔒')
.setLabel('Disable')
.setStyle(ButtonStyle.Secondary)
);
return { embeds: [embed.data], components: [buttons, mainMenuRow] };
}

export {
SettingsMainMenu,
RolesConfigMenu,
Expand All @@ -685,6 +832,8 @@ export {
QueueAutoClearConfigMenu,
LoggingChannelConfigMenu,
AutoGiveStudentRoleConfigMenu,
PromptHelpTopicConfigMenu as PromptHelpTopicConfigMenu,
SeriousModeConfigMenu,
mainMenuRow,
serverSettingsMainMenuOptions
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ExpectedSheetErrors = {
badGoogleSheetId: new GoogleSheetConnectionError(
`YABOB cannot access this google sheet. Make sure you share the google sheet with this YABOB's email: \`${environment.googleCloudCredentials.client_email}\``
),
unparsableDateString: (sheetName:string) => new CommandParseError(`Hmmm...YABOB cannot parse the data stored in ${sheetName}. Is the data format altered?`),
nonServerInteraction: (guildName?: string) =>
guildName === undefined
? new CommandParseError(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { EmbedBuilder } from 'discord.js';
import { EmbedColor } from '../../../utils/embed-helper.js';
import { SettingsMenuOption, YabobEmbed } from '../../../utils/type-aliases.js';
import { FrozenServer } from '../../extension-utils.js';
import { GoogleSheetExtensionState } from '../google-sheet-states.js';
import { mainMenuRow } from '../../../attending-server/server-settings-menus.js';

/**
* Options for the server settings main menu
* @see {@link serverSettingsMainMenuOptions}
*/
const googleSheetSettingsMainMenuOptions: SettingsMenuOption[] = [
{
optionData: {
emoji: '📊',
label: 'Google Sheet Logging Settings',
description: 'Configure the Google Sheet Logging settings',
value: 'google-sheet-settings'
},
subMenu: GoogleSheetSettingsConfigMenu
}
];

/** Compose the Google Sheet Logging settings settings menu */
function GoogleSheetSettingsConfigMenu(
server: FrozenServer,
channelId: string,
isDm: boolean,
updateMessage = ''
): YabobEmbed {
const state = GoogleSheetExtensionState.allStates.get(server.guild.id);
if (!state) {
throw new Error('Google Sheet Logging state for this server was not found');
}
const setGoogleSheetCommandID = server.guild.commands.cache.find(
command => command.name === 'set_google_sheet'
)?.id;
const embed = new EmbedBuilder()
.setTitle(`📊 Google Sheet Logging Configuration for ${server.guild.name} 📊`)
.setColor(EmbedColor.Aqua)
.setFields(
{
name: 'Description',
value: 'This setting controls which Google Sheet this server will be used for logging.'
},
{
name: 'Documentation',
value: `[Learn more about Google Sheet Logging settings here.](https://github.com/KaoushikMurugan/yet-another-better-office-hour-bot/wiki/Configure-YABOB-Settings-For-Your-Server#google-sheet-settings)` //TODO: Add link to documentation
},
{
name: 'Current Google Sheet',
value:
`[Google Sheet](${state.googleSheetURL}) \n ` +
`To change the Google Sheet, please use the ${
setGoogleSheetCommandID
? `</set_google_sheet:${setGoogleSheetCommandID}>`
: '`/set_google_sheet`'
} command. A select menu will be added in v4.3.1`
}
);
if (updateMessage.length > 0) {
embed.setFooter({ text: `✅ ${updateMessage}` });
}
return {
embeds: [embed],
components: [mainMenuRow]
};
}

export { googleSheetSettingsMainMenuOptions, GoogleSheetSettingsConfigMenu };
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
BaseInteractionExtension,
IInteractionExtension
} from '../extension-interface.js';
import { googleSheetSettingsMainMenuOptions } from './google-sheet-constants/google-sheet-settings-menu.js';
import { googleSheetsCommands } from './google-sheet-constants/google-sheet-slash-commands.js';
import { googleSheetCommandMap } from './interaction-handling/command-handler.js';
import { loadSheetById } from './shared-sheet-functions.js';
Expand Down Expand Up @@ -48,6 +49,8 @@ class GoogleSheetInteractionExtension
override slashCommandData = googleSheetsCommands;

override commandMap = googleSheetCommandMap;

override settingsMainMenuOptions = googleSheetSettingsMainMenuOptions;
}

export { GoogleSheetInteractionExtension };
6 changes: 6 additions & 0 deletions src/extensions/google-sheet-logging/google-sheet-states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class GoogleSheetExtensionState {
get googleSheet(): GoogleSpreadsheet {
return this._googleSheet;
}
/**
* The public url of the google sheet document
*/
get googleSheetURL(): string {
return `https://docs.google.com/spreadsheets/d/${this.googleSheet.spreadsheetId}`;
}

/**
* Loads the extension states for 1 guild
Expand Down
Loading

0 comments on commit cf49467

Please sign in to comment.