Skip to content

Commit

Permalink
Bug fixes and code revert
Browse files Browse the repository at this point in the history
### UPDATED
- Restored Finnhub Earnings earning hour text

### FIXED
- Toggle perms failed to recognize `CategoryChannel` as a permission overwrite-able channel
  • Loading branch information
mrjackyliang committed Jun 15, 2022
1 parent 6baf3a1 commit e6725f2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "discord-stocker-bot",
"displayName": "Discord Stonker Bot",
"version": "3.0.10",
"version": "3.0.11",
"description": "An advanced bot built for finance-related Discord servers",
"main": "build/src/index.js",
"private": true,
Expand Down
32 changes: 32 additions & 0 deletions src/lib/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import {
GenerateServerMessageLogMessage,
GenerateServerMessageReturns,
GenerateUserAgentReturns,
GetCategoryChannelGuild,
GetCategoryChannelId,
GetCategoryChannelReturns,
GetCollectionItemsCollection,
GetCollectionItemsReturns,
GetTextBasedChannelGuild,
Expand Down Expand Up @@ -452,6 +455,35 @@ export function generateUserAgent(): GenerateUserAgentReturns {
return _.sample(userAgents) ?? userAgents[0];
}

/**
* Get category channel.
*
* @param {GetCategoryChannelGuild} guild - Guild.
* @param {GetCategoryChannelId} id - Id.
*
* @returns {GetCategoryChannelReturns}
*
* @since 1.0.0
*/
export function getCategoryChannel(guild: GetCategoryChannelGuild, id: GetCategoryChannelId): GetCategoryChannelReturns {
const guildChannels = guild.channels;

if (id === undefined) {
return undefined;
}

const categoryChannel = guildChannels.resolve(id);

if (
categoryChannel !== null
&& categoryChannel.type === 'GUILD_CATEGORY'
) {
return categoryChannel;
}

return null;
}

/**
* Get collection items.
*
Expand Down
6 changes: 3 additions & 3 deletions src/modules/api-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,13 +724,13 @@ export function finnhubEarnings(message: FinnhubEarningsMessage, guild: FinnhubE

switch (filteredEarningHour) {
case 'bmo':
earningsCallTime = 'Before Open';
earningsCallTime = 'Before Market Open';
break;
case 'dmh':
earningsCallTime = 'During Market';
earningsCallTime = 'During Market Hour';
break;
case 'amc':
earningsCallTime = 'After Close';
earningsCallTime = 'After Market Close';
break;
default:
break;
Expand Down
3 changes: 2 additions & 1 deletion src/modules/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
fetchFormattedDate,
generateCron,
generateLogMessage,
getCategoryChannel,
getTextBasedNonThreadChannel,
getVoiceBasedChannel,
isTimeZoneValid,
Expand Down Expand Up @@ -87,7 +88,7 @@ export function togglePerms(message: TogglePermsMessage, guild: TogglePermsGuild
const theChannelChannelId = <TogglePermsEventToggleChannelChannelId>_.get(eventToggle, ['channel', 'channel-id']);
const thePermissions = <TogglePermsEventTogglePermissions>_.get(eventToggle, ['permissions']);

const channel = getTextBasedNonThreadChannel(guild, theChannelChannelId) ?? getVoiceBasedChannel(guild, theChannelChannelId);
const channel = getCategoryChannel(guild, theChannelChannelId) ?? getTextBasedNonThreadChannel(guild, theChannelChannelId) ?? getVoiceBasedChannel(guild, theChannelChannelId);

// If "toggle-perms[${eventKey}].toggles[${eventToggleKey}].channel.channel-id" is not configured properly.
if (
Expand Down
12 changes: 12 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BufferResolvable,
CategoryChannel,
ChannelMention,
Client,
Collection,
Expand Down Expand Up @@ -1204,6 +1205,17 @@ export type GetCollectionItemsCollection<Key, Value> = Collection<Key, Value>;

export type GetCollectionItemsReturns<Value> = Value[];

/**
* Get category channel.
*
* @since 1.0.0
*/
export type GetCategoryChannelGuild = Guild;

export type GetCategoryChannelId = Snowflake | undefined;

export type GetCategoryChannelReturns = CategoryChannel | null | undefined;

/**
* Get text-based channel.
*
Expand Down

0 comments on commit e6725f2

Please sign in to comment.