Skip to content

Commit

Permalink
improved code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart6557 committed Oct 24, 2023
1 parent d36b474 commit ad632e4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ temp/

config.json
.idea/
.DS_Store
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "eslint src --ext .ts",
"lint:fix": "eslint src --ext .ts --fix",
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "tsc && NODE_ENV=development node dist/src/index.js",
"dev": "tsc && NODE_ENV=development node dist/src/index.js",
"start": "tsc && node dist/src/index.js"
},
"repository": {
Expand Down
16 changes: 8 additions & 8 deletions src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Collection, Client as DiscordClient } from 'discord.js';
import { Service } from 'typedi';
import { GatewayIntentBits } from 'discord-api-types';
import Logger from './utils/Logger';
import { BotSettings, BotClient, BotInitializationError } from './types';
import Command from './Command';
Expand Down Expand Up @@ -46,13 +45,14 @@ export default class Client extends DiscordClient implements BotClient {
super(
configuration.clientOptions || {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessageReactions,
'GUILDS',
'GUILD_INTEGRATIONS',
'GUILD_WEBHOOKS',
'GUILD_MESSAGES',
'GUILD_MEMBERS',
'DIRECT_MESSAGES',
'GUILD_MESSAGE_REACTIONS',
'DIRECT_MESSAGE_REACTIONS',
],
}
);
Expand Down
14 changes: 4 additions & 10 deletions src/commands/Checkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import QR from './QR';
/**
* This Command DM's the caller the checkin code and Express Checkin link for any current and
* upcoming events in today's timeframe. Optional argument `public` makes the embed with the
* checkin codes be returned in the same chat as the Command message instead of DMs. Optinoal
* checkin codes be returned in the same chat as the Command message instead of DMs. Optional
* argument 'widescreen' allows users to choose if they want a QR code by itself (false) or
* the widescreen slide QR (true). 'widescreen' is true by default.
*/
Expand Down Expand Up @@ -40,7 +40,7 @@ export default class Checkin extends Command {
boardRequired: true,
enabled: true,
description:
"Sends a private message with all check-in codes from today's events. Calling with `public` argument sends public embed of checkin code.",
"Sends a private message with all check-in codes from today's events. Calling with `public` argument sends public embed of checkin code in the current channel instead of via DM.",
category: 'Utility',
usage: client.settings.prefix.concat('checkin [now]'),
requiredPermissions: ['SEND_MESSAGES'],
Expand Down Expand Up @@ -84,8 +84,7 @@ export default class Checkin extends Command {
// Oh, boy, here come more dates and times to check.
// Luxon makes it much nicer, however.
//
// We need two sets of arrays for "checkin":
// - all events that have a start time within today's timeframe
// We need an array to store all events that have a start time within today's timeframe.
const todayEvents = futureEvents.filter(event => {
// get today's midnight
const midnightToday = DateTime.now().set({
Expand Down Expand Up @@ -123,10 +122,7 @@ export default class Checkin extends Command {
// If we just had `checkin` in our call, no arguments...
if (!isPublic) {
const author = await this.client.users.fetch(interaction.member!.user.id);
// What we need now is to construct the Payload to send for `checkin` with no arguments,
// as well as the Payload for when we have `checkin now`.
//
// Since this is private, we can list all of today's events.
// What we need now is to construct the Payload to send for `checkin`.
const privateMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide);
await author.send(privateMessage);
await super.edit(interaction, {
Expand All @@ -135,8 +131,6 @@ export default class Checkin extends Command {
});
await interaction.followUp(`**/checkin** was used privately by ${interaction.user}!`);
} else {
// This is public, so we only want to give events that are live RIGHT now (so no one can
// pre-emptively get checkin codes if they're left to be seen).
const publicMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide);
await super.edit(interaction, publicMessage);
}
Expand Down
16 changes: 8 additions & 8 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { GatewayIntentBits } from 'discord-api-types';
import { BotSettings } from '../types';

export default {
Expand All @@ -10,13 +9,14 @@ export default {
clientID: '',
clientOptions: {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessageReactions,
'GUILDS',
'GUILD_INTEGRATIONS',
'GUILD_WEBHOOKS',
'GUILD_MESSAGES',
'GUILD_MEMBERS',
'DIRECT_MESSAGES',
'GUILD_MESSAGE_REACTIONS',
'DIRECT_MESSAGE_REACTIONS',
],
},
portalAPI: {
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,11 @@ has-flag@^3.0.0:
resolved "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz"
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=

has-flag@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==

has-symbols@^1.0.1, has-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz"
Expand Down Expand Up @@ -2142,6 +2147,11 @@ ms@^2.1.1:
resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

nan@^2.14.0:
version "2.18.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.18.0.tgz#26a6faae7ffbeb293a39660e88a76b82e30b7554"
integrity sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==

nan@^2.17.0:
version "2.17.0"
resolved "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz"
Expand Down Expand Up @@ -2234,9 +2244,9 @@ object-inspect@^1.11.0, object-inspect@^1.9.0:
resolved "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.0.tgz"
integrity sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg==

object-keys@^1.1.1:
object-keys@^1.0.12, object-keys@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e"
integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==

object.assign@^4.1.2:
Expand Down Expand Up @@ -2388,6 +2398,11 @@ path-type@^3.0.0:
dependencies:
pify "^3.0.0"

path-type@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

picocolors@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz"
Expand Down

0 comments on commit ad632e4

Please sign in to comment.