Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ops: fixes some issues with resolveGuildPlugins #70

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/timezones.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = {
)
.addSubcommand((command) =>
command
.setName('difference')
.setDescription('Shows the differences between your timezone and another user')
.setName('diff')
.setDescription('Shows the differences between your timezone and another @user')
.addUserOption((option) =>
option.setName('user').setDescription('@username').setRequired(true),
),
Expand Down
23 changes: 12 additions & 11 deletions src/controllers/bot/plugins.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,31 @@ export const resolveGuildPlugins = async (
pluginName: string,
): Promise<GuildPluginData> => {
try {
const { data: guildPlugin } = await supabase
const { data: guildPluginResult } = await supabase
.from('guilds')
.select('*, guilds_plugins(*, plugins(enabled, description, premium))')
.select('*, guilds_plugins(*, plugins(enabled, description, premium, name))')
.eq('guild_id', guild_id)
.single()

// INFO: Not sure why this fails below, `guilds_plugins` is an array but the array methods wont show.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const matchingPlugin = guildPlugin.guilds_plugins.find(
if (!guildPluginResult) return

const guildPlugin = guildPluginResult?.guilds_plugins.find(
(ele: GuildPlugin) => ele.name === pluginName,
)

if (matchingPlugin && matchingPlugin.plugins[0].enabled && matchingPlugin.enabled) {
const botPlugin: Record<string, any> = guildPlugin?.plugins

if (guildPlugin && guildPlugin.enabled && botPlugin.enabled) {
return {
enabled: matchingPlugin.enabled || false,
metadata: JSON.parse(JSON.stringify(matchingPlugin.metadata)),
enabled: guildPlugin?.enabled || false,
metadata: JSON.parse(JSON.stringify(guildPlugin?.metadata)),
data: guildPlugin,
}
} else {
return {
enabled: false,
metadata: {},
data: {},
metadata: undefined,
data: undefined,
}
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/plugins/timezones.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const timezonesController = async (interaction: ChatInputCommandInteracti
},
],
})
} else if (command === 'compare') {
} else if (command === 'diff') {
// Get the target & author user
const targetUser = interaction.options.getUser('user', true)
const authorUser = interaction.user
Expand Down
4 changes: 3 additions & 1 deletion src/events/messageUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { NO_INTENT } from '../utils/constants'
module.exports = {
name: 'messageUpdate',
once: false,
enabled: true,
enabled: false,
async execute(Hans: Client, oldMessage: Message, newMessage: Message) {
try {
if (newMessage.author.bot && oldMessage.author.bot) return

const { enabled, metadata } = await resolveGuildPlugins(oldMessage.guildId, 'messageUpdate')

if (!enabled) return
Expand Down