Skip to content

Commit

Permalink
Merge branch 'main' into v4.3-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
tomli380576 committed Jan 13, 2023
2 parents 922d8ec + f575d48 commit aa3babe
Show file tree
Hide file tree
Showing 42 changed files with 919 additions and 882 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<div align="center">
<div>
<img width="80%" alt="yet another better office hour bot" src="https://user-images.githubusercontent.com/60045212/210763246-f20c4ca0-61e6-4ba8-bd88-7beb1efba489.svg"/>
<img width="80%" alt="yet another better office hour bot" src="https://user-images.githubusercontent.com/60045212/211232336-e36c52ee-d74f-470d-ac82-48089e5860ed.svg"/>
</div>
</div>



<div align = "center">
<a href='https://www.gnu.org/licenses/gpl-3.0.en.html' target="_blank"><img alt='' src='https://img.shields.io/badge/GPL_V3-100000?style=for-the-badge&logo=&logoColor=white&labelColor=007acc&color=FE6F6E'/></a>&nbsp&nbsp<a href='https://www.typescriptlang.org/' target="_blank"><img alt='Typescript' src='https://img.shields.io/badge/Typescript-100000?style=for-the-badge&logo=Typescript&logoColor=white&labelColor=007acc&color=007acc'/></a>&nbsp&nbsp<a href='https://nodejs.org/en/' target="_blank"><img alt='Node.js' src='https://img.shields.io/badge/Node.JS_ LTS-100000?style=for-the-badge&logo=Node.js&logoColor=white&labelColor=339933&color=339933'/></a>&nbsp&nbsp<a href='https://discord.gg/p7HS92mHsG' target="_blank"><img alt='Discord' src='https://img.shields.io/badge/Join_our discord-100000?style=for-the-badge&logo=Discord&logoColor=white&labelColor=5865F2&color=5865F2'/></a>
</div>
Expand Down Expand Up @@ -50,7 +52,7 @@ Apart from basic queue operations, some of YABOB's other useful features are:
- Notifying students for the queues they're interested in
- Automatically clear queues after a specified amount of inactive time

If you would like to host your own YABOB instance, see the [Setup Guide](https://github.com/KaoushikMurugan/YABOB/wiki/Setup-Guide) to get started with running the bot.
If you would like to host your own YABOB instance, see the [Development Setup Guide](https://github.com/KaoushikMurugan/yet-another-better-office-hour-bot/wiki/Development-Setup-Guide) to get started with running the bot.

# Server Roles

Expand Down
18 changes: 9 additions & 9 deletions help-channel-messages/AdminCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { client } from '../src/global-states.js';
import { EmbedColor } from '../src/utils/embed-helper.js';
import { HelpMessage } from '../src/utils/type-aliases.js';

const adminCommandsTileMessage: HelpMessage = {
const adminCommandsTitleMessage: HelpMessage = {
nameValuePair: {
name: 'Admin Commands Title',
value: 'admin-commands-title'
Expand Down Expand Up @@ -339,7 +339,7 @@ const seriousModeHelp: HelpMessage = {
value: 'serious_mode'
},
useInHelpChannel: true,
useInHelpCommand: true,
useInHelpCommand: false,
message: {
embeds: [
{
Expand Down Expand Up @@ -374,7 +374,7 @@ const settingsHelp: HelpMessage = {
value: 'settings'
},
useInHelpChannel: true,
useInHelpCommand: true,
useInHelpCommand: false,
message: {
embeds: [
{
Expand Down Expand Up @@ -409,7 +409,7 @@ const setAutoGiveStudentRoleHelp: HelpMessage = {
value: 'set_auto_give_student_role'
},
useInHelpChannel: true,
useInHelpCommand: true,
useInHelpCommand: false,
message: {
embeds: [
{
Expand Down Expand Up @@ -439,7 +439,7 @@ const setAutoGiveStudentRoleHelp: HelpMessage = {
};

const adminCommandHelpMessages: HelpMessage[] = [
adminCommandsTileMessage,
adminCommandsTitleMessage,
queueAddHelp,
queueRemoveHelp,
cleanupQueueHelp,
Expand All @@ -449,10 +449,10 @@ const adminCommandHelpMessages: HelpMessage[] = [
setLoggingChannelHelp,
stopLoggingHelp,
setQueueAutoClearHelp,
seriousModeHelp
// ! Temporarily removed since it causes the /help command to fail generation as it get too many fields
//settingsHelp,
//setAutoGiveStudentRoleHelp
seriousModeHelp,
// ! Temporarily have useInHelpCommand=false since it causes the /help command to fail generation as it get too many fields
settingsHelp,
setAutoGiveStudentRoleHelp
];

export { adminCommandHelpMessages };
22 changes: 11 additions & 11 deletions help-channel-messages/HelperCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { client } from '../src/global-states.js';
import { EmbedColor } from '../src/utils/embed-helper.js';
import { HelpMessage } from '../src/utils/type-aliases.js';

const helperCommandsTileMessage: HelpMessage = {
const helperCommandsTitleMessage: HelpMessage = {
nameValuePair: {
name: 'Helper Commands Title',
name: 'Staff Commands Title',
value: 'helper-commands-title'
},
useInHelpChannel: true,
Expand All @@ -13,7 +13,7 @@ const helperCommandsTileMessage: HelpMessage = {
embeds: [
{
color: EmbedColor.Neutral,
title: 'Bot Admin & Helper Only Commands',
title: 'Bot Admin & Staff Only Commands',
timestamp: new Date().toISOString(),
author: {
name: 'YABOB V4.',
Expand Down Expand Up @@ -169,7 +169,7 @@ const clearHelp: HelpMessage = {
value: 'clear'
},
useInHelpChannel: true,
useInHelpCommand: true,
useInHelpCommand: false,
message: {
embeds: [
{
Expand Down Expand Up @@ -203,7 +203,7 @@ const pauseHelp: HelpMessage = {
value: 'pause'
},
useInHelpChannel: true,
useInHelpCommand: true,
useInHelpCommand: false,
message: {
embeds: [
{
Expand Down Expand Up @@ -237,7 +237,7 @@ const resumeHelp: HelpMessage = {
value: 'resume'
},
useInHelpChannel: true,
useInHelpCommand: true,
useInHelpCommand: false,
message: {
embeds: [
{
Expand Down Expand Up @@ -266,15 +266,15 @@ const resumeHelp: HelpMessage = {
};

const helperCommandHelpMessages: HelpMessage[] = [
helperCommandsTileMessage,
helperCommandsTitleMessage,
startHelp,
stopHelp,
nextHelp,
announceHelp
announceHelp,
// ! Over choice limit
// clearHelp,
// pauseHelp,
// resumeHelp
clearHelp,
pauseHelp,
resumeHelp
];

export { helperCommandHelpMessages };
4 changes: 2 additions & 2 deletions help-channel-messages/StudentCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { client } from '../src/global-states.js';
import { EmbedColor } from '../src/utils/embed-helper.js';
import { HelpMessage } from '../src/utils/type-aliases.js';

const studentCommandsTileMessage: HelpMessage = {
const studentCommandsTitleMessage: HelpMessage = {
nameValuePair: {
name: 'Student Commands Title',
value: 'student-commands-title'
Expand Down Expand Up @@ -164,7 +164,7 @@ const helpHelp: HelpMessage = {
};

const studentCommandHelpMessages: HelpMessage[] = [
studentCommandsTileMessage,
studentCommandsTitleMessage,
enqueueHelp,
leaveHelp,
listHelpersHelp,
Expand Down
32 changes: 17 additions & 15 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Guild, Interaction, Events } from 'discord.js';
import { AttendingServerV2 } from './attending-server/base-attending-server.js';
import { magenta, cyan, green, red, yellow } from './utils/command-line-colors.js';
import { EmbedColor, SimpleEmbed } from './utils/embed-helper.js';
import { client, attendingServers } from './global-states.js';
import { client } from './global-states.js';
import { environment } from './environment/environment-manager.js';
import { updatePresence } from './utils/discord-presence.js';
import {
Expand Down Expand Up @@ -63,9 +63,10 @@ client.on(Events.ClientReady, async () => {
*/
client.on(Events.GuildCreate, async guild => {
console.log(`${magenta('Got invited to:')} '${guild.name}'!`);
await joinGuild(guild).catch(() =>
console.error(`${red('Please give me the highest role in:')} '${guild.name}'.`)
);
await joinGuild(guild).catch(err => {
console.error(err);
console.error(`${red('Please give me the highest role in:')} '${guild.name}'.`);
});
});

/**
Expand All @@ -74,11 +75,12 @@ client.on(Events.GuildCreate, async guild => {
* - Deletes server from server map
*/
client.on(Events.GuildDelete, async guild => {
const server = attendingServers.get(guild.id);
if (server !== undefined) {
const getResult = AttendingServerV2.safeGet(guild.id);
if (getResult.ok) {
const server = getResult.value;
server.clearAllServerTimers();
await server.gracefulDelete();
attendingServers.delete(guild.id);
AttendingServerV2.allServers.delete(guild.id);
console.log(
red(`Leaving ${guild.name}. Backups will be saved by the extensions.`)
);
Expand Down Expand Up @@ -109,8 +111,7 @@ client.on(Events.InteractionCreate, async (interaction: Interaction) => {
* Gives the Student role to new members
*/
client.on(Events.GuildMemberAdd, async member => {
const server =
attendingServers.get(member.guild.id) ?? (await joinGuild(member.guild));
const server = AttendingServerV2.get(member.guild.id);
if (!server.autoGiveStudentRole) {
return;
}
Expand All @@ -131,7 +132,7 @@ client.on(Events.GuildMemberAdd, async member => {
* Once YABOB has the highest role, start the initialization call
*/
client.on(Events.GuildRoleUpdate, async role => {
if (attendingServers.has(role.guild.id)) {
if (AttendingServerV2.allServers.has(role.guild.id)) {
return;
}
if (
Expand Down Expand Up @@ -161,11 +162,11 @@ client.on(Events.VoiceStateUpdate, async (oldVoiceState, newVoiceState) => {
}
const serverId = oldVoiceState.guild.id;
if (isLeaveVC(oldVoiceState, newVoiceState)) {
await attendingServers
await AttendingServerV2.allServers
.get(serverId)
?.onMemberLeaveVC(newVoiceState.member, oldVoiceState);
} else if (isJoinVC(oldVoiceState, newVoiceState)) {
await attendingServers
await AttendingServerV2.allServers
.get(serverId)
?.onMemberJoinVC(newVoiceState.member, newVoiceState);
}
Expand All @@ -175,7 +176,7 @@ client.on(Events.VoiceStateUpdate, async (oldVoiceState, newVoiceState) => {
* Emit the on role delete event
*/
client.on(Events.GuildRoleDelete, async role => {
attendingServers.get(role.guild.id)?.onRoleDelete(role);
await AttendingServerV2.allServers.get(role.guild.id)?.onRoleDelete(role);
});

/**
Expand Down Expand Up @@ -208,15 +209,16 @@ async function joinGuild(guild: Guild): Promise<AttendingServerV2> {
: interactionExtensions.flatMap(ext => ext.slashCommandData);
await postSlashCommands(guild, externalCommandData);
await guild.commands.fetch(); // populate cache
// Extensions for server&queue are loaded inside the create method
// Extensions for server & queue are loaded inside the create method
const server = await AttendingServerV2.create(guild);
attendingServers.set(guild.id, server);
AttendingServerV2.allServers.set(guild.id, server);
return server;
}

/**
* Combines all the extension help messages and settings menu options
* - if we have more static data in interaction level extensions, collect them here
* - extensions only need to specify the corresponding properties
*/
function collectInteractionExtensionStaticData(): void {
adminCommandHelpMessages.push(
Expand Down
Loading

0 comments on commit aa3babe

Please sign in to comment.