Skip to content

Commit

Permalink
updated getGuild cache options
Browse files Browse the repository at this point in the history
  • Loading branch information
GhomKrosmonaute committed Sep 15, 2024
1 parent 08fd947 commit 4a0cfca
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/commands/active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export default new app.Command({
async run(message) {
used = true

const config = await app.getGuild(message.guild, true)
const config = await app.getGuild(message.guild, {
forceExists: true,
forceFetch: true,
})

const waiting = await message.channel.send(
`${app.emote(message, "Loading")} Fetching members...`,
Expand Down Expand Up @@ -73,7 +76,7 @@ export default new app.Command({
}),
],
run: async (message) => {
const guild = await app.getGuild(message.guild, true)
const guild = await app.getGuild(message.guild, { forceExists: true })

app.activeLadder(guild._id).send(message.channel, {
pageLineCount: message.args.lines,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/autoRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default new app.Command({
},
],
async run(message) {
const guild = await app.getGuild(message.guild, true)
const guild = await app.getGuild(message.guild, { forceExists: true })

await autoRole.query.delete().where("guild_id", guild._id)
await autoRole.query.insert(
Expand Down Expand Up @@ -72,7 +72,7 @@ export default new app.Command({
},
],
async run(message) {
const guild = await app.getGuild(message.guild, true)
const guild = await app.getGuild(message.guild, { forceExists: true })

await autoRole.query.insert({
guild_id: guild._id,
Expand All @@ -91,7 +91,7 @@ export default new app.Command({
description: "List auto roles",
channelType: "guild",
async run(message) {
const guild = await app.getGuild(message.guild, true)
const guild = await app.getGuild(message.guild, { forceExists: true })

const autoRoles = await autoRole.query.where("guild_id", guild._id)

Expand Down
5 changes: 4 additions & 1 deletion src/commands/elders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export default new app.Command({
`${app.emote(message, "Loading")} Fetching elder roles...`,
)

const config = await app.getGuild(message.guild, true)
const config = await app.getGuild(message.guild, {
forceFetch: true,
forceExists: true,
})

const pattern = config.elders_role_pattern!

Expand Down
2 changes: 1 addition & 1 deletion src/commands/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default new app.Command({

let found = 0

const guild = await app.getGuild(message.guild, true)
const guild = await app.getGuild(message.guild, { forceExists: true })

const userCache = new Map()

Expand Down
2 changes: 1 addition & 1 deletion src/commands/labs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default new app.Command({
async run(message) {
const guild = message.args.id
? await app.getGuild({ id: message.args.id })
: await app.getGuild(message.guild, true)
: await app.getGuild(message.guild, { forceExists: true })

if (!guild)
return message.channel.send(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default new app.Command({
}),
],
async run(message) {
const guild = await app.getGuild(message.guild, true)
const guild = await app.getGuild(message.guild, { forceExists: true })

const ladders = [
app.ratingLadder(guild._id),
Expand Down
4 changes: 2 additions & 2 deletions src/commands/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default new app.Command({

const fromUser = await app.getUser(message.author, true)
const toUser = await app.getUser(message.args.member, true)
const guild = await app.getGuild(message.guild, true)
const guild = await app.getGuild(message.guild, { forceExists: true })

const pack = {
guild_id: guild._id,
Expand Down Expand Up @@ -87,7 +87,7 @@ export default new app.Command({
run: async (message) => {
const guild = message.args.global
? undefined
: await app.getGuild(message.guild, true)
: await app.getGuild(message.guild, { forceExists: true })

app.ratingLadder(guild?._id).send(message.channel, {
pageLineCount: message.args.lines,
Expand Down
2 changes: 1 addition & 1 deletion src/listeners/activity.messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const listener: app.Listener<"messageCreate"> = {
if (!message.guild) return

const user = await app.getUser(message.author, true)
const guild = await app.getGuild(message.guild, true)
const guild = await app.getGuild(message.guild, { forceExists: true })

await messages.query.insert({
author_id: user._id,
Expand Down
2 changes: 1 addition & 1 deletion src/listeners/traffic.guildMemberAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const listener: app.Listener<"guildMemberAdd"> = {
if (!app.cache.ensure<boolean>("turn", true)) return
if (await app.isIgnored(member.guild.id)) return

const config = await app.getGuild(member.guild, true)
const config = await app.getGuild(member.guild, { forceExists: true })

await app.applyAutoRoles(member)

Expand Down
4 changes: 3 additions & 1 deletion src/listeners/traffic.guildMemberRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const listener: app.Listener<"guildMemberRemove"> = {
if (!app.cache.ensure<boolean>("turn", true)) return
if (await app.isIgnored(member.guild.id)) return

const config = await app.getGuild(member.guild, true)
const config = await app.getGuild(member.guild)

if (!config) return

if (member.user.bot) {
if (config.general_channel_id && config.bot_leave_message) {
Expand Down
2 changes: 1 addition & 1 deletion src/namespaces/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function userRating(
const query = table.query.where("to_id", userId)

if (guild) {
const { _id: guildId } = await app.getGuild(guild, true)
const { _id: guildId } = await app.getGuild(guild, { forceExists: true })

query.and.where("guild_id", guildId)
}
Expand Down
2 changes: 1 addition & 1 deletion src/slash/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default new app.SlashCommand({
})

const { resolved_channel_indicator, resolved_channel_tag } =
await app.getGuild(interaction.guild, true)
await app.getGuild(interaction.guild, { forceExists: true })

if (topic.name.startsWith(resolved_channel_indicator))
return interaction.base.reply({
Expand Down

0 comments on commit 4a0cfca

Please sign in to comment.