Skip to content

Commit

Permalink
Some Minor Fixes (#67)
Browse files Browse the repository at this point in the history
* Use named exports more often

* More random words

* Fix queue messages not formatting right

* 1.4.1

* Update unit tests
  • Loading branch information
AverageHelper committed Apr 22, 2022
1 parent 0f7c126 commit d7b5c69
Show file tree
Hide file tree
Showing 46 changed files with 1,639 additions and 1,275 deletions.
2,751 changes: 1,539 additions & 1,212 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gamgee",
"version": "1.4.0",
"version": "1.4.1",
"description": "A Discord bot for managing a song request queue.",
"private": true,
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion src/actions/describeAllCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const OPT = "?";
* @param commands The collection of available commands.
* @returns a string describing all commands.
*/
export default async function describeAllCommands(
export async function describeAllCommands(
context: CommandContext,
commands: Discord.Collection<string, Command>
): Promise<string> {
Expand Down Expand Up @@ -140,3 +140,5 @@ function describeParameters(
push(composed(subDesc), cmdDesc);
});
}

export default describeAllCommands;
2 changes: 1 addition & 1 deletion src/actions/getVideoDetails.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("Video details", () => {

test("returns infinite duration for a live stream", async () => {
// 24/7 Brony Chill Music Radio - Beats to Study Friendship to
const url = "https://www.youtube.com/watch?v=mnCJHuH9Oxw";
const url = "https://www.youtube.com/watch?v=CmoUkFbk5VM";
const details = await getVideoDetails(url, null);
expect(details).toHaveProperty("url", url);
expect(details?.duration.seconds).toBeDefined();
Expand Down
4 changes: 3 additions & 1 deletion src/actions/getVideoDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export async function getPonyFmTrack(url: URL): Promise<VideoDetails> {
* @returns a details about the video, or `null` if no video could be
* found from the provided query.
*/
export default async function getVideoDetails(
export async function getVideoDetails(
urlOrString: URL | string,
logger: Logger | null = useLogger()
): Promise<VideoDetails | null> {
Expand All @@ -257,3 +257,5 @@ export default async function getVideoDetails(
return null;
}
}

export default getVideoDetails;
4 changes: 3 additions & 1 deletion src/actions/queue/getQueueChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ async function getQueueChannelFromGuild(guild: Discord.Guild): Promise<Discord.T
*
* @returns the guild's queue channel, or `null` if it has none.
*/
export default async function getQueueChannel(
export async function getQueueChannel(
source: CommandContext | Discord.Guild | null
): Promise<Discord.TextChannel | null> {
if (!source) return null;
if ("type" in source) return getQueueChannelFromCommand(source);
return getQueueChannelFromGuild(source);
}

export default getQueueChannel;
4 changes: 3 additions & 1 deletion src/actions/queue/processSongRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async function acceptSongRequest({
*
* @param request The song request context.
*/
export default async function processSongRequest(request: SongRequest): Promise<void> {
export async function processSongRequest(request: SongRequest): Promise<void> {
const { songUrl, context, queueChannel, logger } = request;
const senderId = context.user.id;

Expand Down Expand Up @@ -219,3 +219,5 @@ export default async function processSongRequest(request: SongRequest): Promise<
return reject_public(context, "That query gave me an error. Try again maybe? :shrug:");
}
}

export default processSongRequest;
13 changes: 9 additions & 4 deletions src/actions/queue/useQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { MessageButton } from "../../buttons.js";
import type { QueueEntry, UnsentQueueEntry } from "../../useQueueStorage.js";
import { actionRow, DELETE_BUTTON, DONE_BUTTON, RESTORE_BUTTON } from "../../buttons.js";
import { addStrikethrough } from "./strikethroughText.js";
import { composed, createPartialString, push, pushBold } from "../../helpers/composeStrings.js";
import { deleteMessage, editMessage, escapeUriInString } from "../messages/index.js";
import durationString from "../../helpers/durationString.js";
import {
Expand All @@ -14,6 +13,13 @@ import {
removeEntryFromMessage,
markEntryDone
} from "../../useQueueStorage.js";
import {
composed,
createPartialString,
push,
pushBold,
pushNewLine
} from "../../helpers/composeStrings.js";

// FIXME: Some of these may be inlined with functions from useQueueStorage.js, and should be inlined to avoid confusion between raw database function and full queue functions

Expand All @@ -35,12 +41,11 @@ function queueMessageFromEntry(
} else {
push(entry.url, partialContent);
}
pushNewLine(partialContent);

// Bold engangement counter if it's nonzero
const likeCount = entry.haveCalledNowPlaying.length;
const likeMessage = `\n${likeCount} ${
likeCount === 1 ? "person" : "people"
} asked for this link.`;
const likeMessage = `${likeCount} ${likeCount === 1 ? "person" : "people"} asked for this link.`;
if (likeCount === 0) {
push(likeMessage, partialContent);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isConfigKey, allKeys } from "../../constants/config/index.js";
import { getConfigValue } from "../../actions/config/getConfigValue.js";
import { resolveStringFromOption } from "../../helpers/optionResolvers.js";

const get: Subcommand = {
export const get: Subcommand = {
name: "get",
description: "Get the value of a configuration setting.",
options: [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const subargsList = namedSubcommands
.map(v => `\`${v}\``)
.join(", ");

const config: Command = {
export const config: Command = {
name: "config",
description: "Read and modify config options.",
options: namedSubcommands,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isConfigKey, isConfigValue } from "../../constants/config/index.js";
import { resolveStringFromOption } from "../../helpers/optionResolvers.js";
import { setConfigValue } from "../../actions/config/setConfigValue.js";

const set: Subcommand = {
export const set: Subcommand = {
name: "set",
description: "Set the value of a configuration setting.",
options: [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/unset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getConfigValue } from "../../actions/config/getConfigValue.js";
import { setConfigValue } from "../../actions/config/setConfigValue.js";
import { resolveStringFromOption } from "../../helpers/optionResolvers.js";

const unset: Subcommand = {
export const unset: Subcommand = {
name: "unset",
description: "Reset the value of a configuration setting to default.",
options: [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Command } from "./Command.js";
import describeAllCommands from "../actions/describeAllCommands.js";

const help: Command = {
export const help: Command = {
name: "help",
description: "Print a handy help message.",
requiresGuild: false,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/howto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
pushNewLine
} from "../helpers/composeStrings.js";

const howto: GuildedCommand = {
export const howto: GuildedCommand = {
name: "howto",
description: "Print instructions for using the common queue commands.",
requiresGuild: true,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import richErrorMessage from "../helpers/richErrorMessage.js";

let cachedMetadata: GitHubMetadata | null | "waiting" = null;

const languages: GlobalCommand = {
export const languages: GlobalCommand = {
name: "languages",
description: "Print my core repository's language statistics.",
requiresGuild: false,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getQueueConfig
} from "../useQueueStorage.js";

const limits: Command = {
export const limits: Command = {
name: "limits",
description: "Display the song queue's submission limits.",
requiresGuild: true,
Expand Down
8 changes: 4 additions & 4 deletions src/commands/nowPlaying.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type Discord from "discord.js";
import type { Command } from "./Command.js";
import { addUserToHaveCalledNowPlaying } from "../actions/queue/useQueue.js";
import { composed, createPartialString, push } from "../helpers/composeStrings.js";
import { fetchAllEntries } from "../useQueueStorage.js";
import { addUserToHaveCalledNowPlaying } from "../actions/queue/useQueue.js";
import getQueueChannel from "../actions/queue/getQueueChannel.js";
import randomElementOfArray from "../helpers/randomElementOfArray.js";
import { getQueueChannel } from "../actions/queue/getQueueChannel.js";
import { randomElementOfArray } from "../helpers/randomElementOfArray.js";

const uncertainties = ["There's a good chance", "I'm like 85% sure", "Very likely,", "I think"];
let lastUncertainty: string | null = null;
Expand All @@ -30,7 +30,7 @@ function randomCurrent(): string {
return random;
}

const nowPlaying: Command = {
export const nowPlaying: Command = {
name: "now-playing",
aliases: ["nowplaying"],
description: "Reveal the current song in the queue (or my best guess).",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type Discord from "discord.js";
import type { Command } from "./Command.js";
import { randomPhrase, unwrappingFirstWith } from "../helpers/randomStrings.js";

const ping: Command = {
export const ping: Command = {
name: "ping",
description: "Ping my host server to check latency.",
requiresGuild: false,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue/blacklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
pushNewLine
} from "../../helpers/composeStrings.js";

const blacklist: Subcommand = {
export const blacklist: Subcommand = {
name: "blacklist",
description: "Show the list of blacklisted users, or add a user to the blacklist.",
options: [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { GuildedSubcommand } from "../Command.js";
import { isQueueOpen, setQueueOpen } from "../../useGuildStorage.js";
import getQueueChannel from "../../actions/queue/getQueueChannel.js";

const close: GuildedSubcommand = {
export const close: GuildedSubcommand = {
name: "close",
description: "Stop accepting song requests to the queue.",
type: "SUB_COMMAND",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const namedSubcommands: NonEmptyArray<Subcommand> = [
restart
];

const sr: Command = {
export const sr: Command = {
name: "quo",
description: "Administrative commands to manage the song queue.",
options: namedSubcommands,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue/limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function isLimitKey(value: unknown): value is LimitKey {
);
}

const limit: Subcommand = {
export const limit: Subcommand = {
name: "limit", // TODO: Alias this to "limits"
description: "Set a limit value on the queue. (Time in seconds, where applicable)",
options: [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { GuildedSubcommand } from "../Command.js";
import { isQueueOpen, setQueueOpen } from "../../useGuildStorage.js";
import getQueueChannel from "../../actions/queue/getQueueChannel.js";

const open: GuildedSubcommand = {
export const open: GuildedSubcommand = {
name: "open",
description: "Start accepting song requests to the queue.",
type: "SUB_COMMAND",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { bulkDeleteMessagesWithIds } from "../../actions/messages/index.js";
import { clearEntries, fetchAllEntries } from "../../useQueueStorage.js";
import getQueueChannel from "../../actions/queue/getQueueChannel.js";

const restart: Subcommand = {
export const restart: Subcommand = {
name: "restart",
description: "Empty the queue and start a fresh queue session.",
type: "SUB_COMMAND",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Subcommand } from "../Command.js";
import { setQueueChannel } from "../../useGuildStorage.js";
import { resolveChannelFromOption } from "../../helpers/optionResolvers.js";

const setup: Subcommand = {
export const setup: Subcommand = {
name: "setup",
description: "Set a channel as the 'queue' channel.",
options: [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
playtimeTotalInQueue
} from "../../actions/queue/useQueue.js";

const stats: Subcommand = {
export const stats: Subcommand = {
name: "stats",
description: "Print statistics on the current queue.",
type: "SUB_COMMAND",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue/teardown.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Subcommand } from "../Command.js";
import { setQueueChannel } from "../../useGuildStorage.js";

const teardown: Subcommand = {
export const teardown: Subcommand = {
name: "teardown",
description: "Deletes and un-sets the current queue.",
type: "SUB_COMMAND",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/queue/whitelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { whitelistUser } from "../../useQueueStorage.js";
import getQueueChannel from "../../actions/queue/getQueueChannel.js";
import logUser from "../../helpers/logUser.js";

const whitelist: Subcommand = {
export const whitelist: Subcommand = {
name: "whitelist",
description: "Allows a previously-blacklisted user to make song requests.",
options: [
Expand Down
6 changes: 3 additions & 3 deletions src/commands/songRequest.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type Discord from "discord.js";
import type { GuildedCommand } from "./Command.js";
import type { SongRequest } from "../actions/queue/processSongRequest.js";
import { getQueueChannel } from "../actions/queue/getQueueChannel.js";
import { isQueueOpen } from "../useGuildStorage.js";
import { resolveStringFromOption } from "../helpers/optionResolvers.js";
import { sendMessageInChannel } from "../actions/messages/index.js";
import { URL } from "url";
import { isQueueOpen } from "../useGuildStorage.js";
import { useJobQueue } from "@averagehelper/job-queue";
import getQueueChannel from "../actions/queue/getQueueChannel.js";
import processRequest from "../actions/queue/processSongRequest.js";

const sr: GuildedCommand = {
export const sr: GuildedCommand = {
name: "sr",
description: "Submit a song to the queue.",
options: [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function addResult(result: FetchResult, embed: MessageEmbed): void {

let isTesting = false;

const type: Command = {
export const type: Command = {
name: "test",
description: "Make sure I still know how to talk to video services.",
requiresGuild: false,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Command } from "./Command.js";

const type: Command = {
export const type: Command = {
name: "t",
description: "Start a typing indicator.",
requiresGuild: false,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Command } from "./Command.js";
import { version as gamgeeVersion } from "../version.js";
import { randomCelebration, unwrappingFirstWith } from "../helpers/randomStrings.js";

const version: Command = {
export const version: Command = {
name: "version",
description: "Display the bot's current codebase version.",
requiresGuild: false,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import getVideoDetails from "../actions/getVideoDetails.js";
import durationString from "../helpers/durationString.js";
import richErrorMessage from "../helpers/richErrorMessage.js";

const video: Command = {
export const video: Command = {
name: "video",
description: "Reply with the video title and duration.",
options: [
Expand Down
4 changes: 3 additions & 1 deletion src/constants/config/defaultValueForConfigKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export function isConfigValue(value: unknown): value is ConfigValue {
);
}

export default function defaultValueForConfigKey(key: ConfigKey): ConfigValue {
export function defaultValueForConfigKey(key: ConfigKey): ConfigValue {
switch (key) {
case CONFIG_KEY_COMMAND_PREFIX:
return "?";
}
}

export default defaultValueForConfigKey;
Loading

0 comments on commit d7b5c69

Please sign in to comment.