Skip to content

Commit

Permalink
format and trying to add wallet to root header
Browse files Browse the repository at this point in the history
  • Loading branch information
llllllluc committed Oct 21, 2023
1 parent ba0b670 commit 804d92f
Show file tree
Hide file tree
Showing 103 changed files with 2,495 additions and 1,977 deletions.
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"singleQuote": true,
"semi": false
"singleQuote": false,
"semi": true
}
4 changes: 2 additions & 2 deletions apps/bot/commands/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as markAnswer from './mark-answer.js'
import * as markAnswer from "./mark-answer.js";

export const contextMenuCommands = [markAnswer.command]
export const contextMenuCommands = [markAnswer.command];
88 changes: 44 additions & 44 deletions apps/bot/commands/context/mark-answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import {
ComponentType,
ContextMenuCommandBuilder,
PermissionFlagsBits,
} from 'discord.js'
import { ContextMenuCommand } from '../types.js'
} from "discord.js";
import { ContextMenuCommand } from "../types.js";
import {
isMessageInForumChannel,
isMessageSupported,
replyWithEmbed,
replyWithEmbedError,
} from '../../utils.js'
import { markMessageAsSolution } from '../../db/actions/messages.js'
import { env } from '../../env.js'
} from "../../utils.js";
import { markMessageAsSolution } from "../../db/actions/messages.js";
import { env } from "../../env.js";

export const command: ContextMenuCommand = {
data: new ContextMenuCommandBuilder()
.setName('Mark Solution')
.setName("Mark Solution")
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.SendMessages)
.setType(ApplicationCommandType.Message),
Expand All @@ -28,50 +28,50 @@ export const command: ContextMenuCommand = {
if (!interaction.channel || !isMessageInForumChannel(interaction.channel)) {
await replyWithEmbedError(interaction, {
description:
'This command can only be used in a supported forum channel',
})
"This command can only be used in a supported forum channel",
});

return
return;
}

if (!isMessageSupported(interaction.targetMessage)) {
await replyWithEmbedError(interaction, {
description:
"This type of message is not supported. Make sure the author isn't a bot and the post is indexed",
})
});

return
return;
}

const mainChannel = interaction.channel.parent
const mainChannel = interaction.channel.parent;
if (!mainChannel) {
await replyWithEmbedError(interaction, {
description:
'Could not find the parent channel, please try again later. If this issue persists, contact a staff member',
})
"Could not find the parent channel, please try again later. If this issue persists, contact a staff member",
});

return
return;
}

if (mainChannel.type !== ChannelType.GuildForum) {
await interaction.reply({
ephemeral: true,
content: 'The parent channel is not a forum channel',
})
content: "The parent channel is not a forum channel",
});

return
return;
}

const interactionMember = await interaction.guild?.members.fetch(
interaction.user
)
interaction.user,
);
if (!interactionMember) {
await replyWithEmbedError(interaction, {
description:
'Could not find your info in the server, please try again later. If this issue persists, contact a staff member',
})
"Could not find your info in the server, please try again later. If this issue persists, contact a staff member",
});

return
return;
}

if (
Expand All @@ -83,50 +83,50 @@ export const command: ContextMenuCommand = {
) {
await replyWithEmbedError(interaction, {
description:
'Only the post author, helpers or moderators can mark a message as the answer',
})
"Only the post author, helpers or moderators can mark a message as the answer",
});

return
return;
}

if (interaction.targetId === interaction.channelId) {
await replyWithEmbedError(interaction, {
description:
"You can't mark the post itself as the answer. If you figured out the issue by yourself, please send it as a separate message and mark it as the answer",
})
});

return
return;
}

await markMessageAsSolution(
interaction.targetMessage.id,
interaction.channelId
)
interaction.channelId,
);

const answeredTagId = mainChannel.availableTags.find((t) =>
t.name.includes('Answered')
)?.id
t.name.includes("Answered"),
)?.id;

if (answeredTagId) {
const newTags = Array.from(
new Set([...interaction.channel.appliedTags, answeredTagId])
)
interaction.channel.setAppliedTags(newTags)
new Set([...interaction.channel.appliedTags, answeredTagId]),
);
interaction.channel.setAppliedTags(newTags);
}

await replyWithEmbed(interaction, {
title: '✅ Success!',
title: "✅ Success!",
description:
'This question has been marked as answered! If you have any other questions, feel free to create another post',
"This question has been marked as answered! If you have any other questions, feel free to create another post",
color: Colors.Green,
fields: [
{
name: 'Jump to answer',
name: "Jump to answer",
value: `[Click here](${interaction.targetMessage.url})`,
inline: true,
},
],
})
});

// edit instructions message to add the button for message url (get the first message sent by the bot)
const instructionsMessage = (
Expand All @@ -136,7 +136,7 @@ export const command: ContextMenuCommand = {
})
)
.filter((m) => m.author.id === interaction.client.user?.id)
.last()
.last();

if (instructionsMessage) {
try {
Expand All @@ -148,16 +148,16 @@ export const command: ContextMenuCommand = {
{
type: ComponentType.Button,
style: ButtonStyle.Link,
label: 'Jump to Answer',
label: "Jump to Answer",
url: interaction.targetMessage.url,
},
],
},
],
})
});
} catch (err) {
console.error('Failed to update instructions message:', err)
console.error("Failed to update instructions message:", err);
}
}
},
}
};
10 changes: 5 additions & 5 deletions apps/bot/commands/slash/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as refreshAnswerCount from './refresh-answer-count.js'
import * as refreshLastActive from './refresh-last-active.js'
import * as lockLowEffortPost from './lock-low-effort-post.js'
import * as removePostAnswer from './remove-post-answer.js'
import * as refreshAnswerCount from "./refresh-answer-count.js";
import * as refreshLastActive from "./refresh-last-active.js";
import * as lockLowEffortPost from "./lock-low-effort-post.js";
import * as removePostAnswer from "./remove-post-answer.js";

export const slashCommands = [
refreshAnswerCount.command,
refreshLastActive.command,
lockLowEffortPost.command,
removePostAnswer.command,
]
];
40 changes: 20 additions & 20 deletions apps/bot/commands/slash/lock-low-effort-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,55 @@ import {
Colors,
PermissionFlagsBits,
SlashCommandBuilder,
} from 'discord.js'
import { dedent } from 'ts-dedent'
import { SlashCommand } from '../types.js'
import { replyWithEmbedError } from '../../utils.js'
} from "discord.js";
import { dedent } from "ts-dedent";
import { SlashCommand } from "../types.js";
import { replyWithEmbedError } from "../../utils.js";

export const command: SlashCommand = {
data: new SlashCommandBuilder()
.setName('lock-low-effort-post')
.setDescription('Locks a post and sends a message explaining the reason')
.setName("lock-low-effort-post")
.setDescription("Locks a post and sends a message explaining the reason")
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageThreads),

async execute(interaction) {
if (!interaction.channel?.isThread()) {
await replyWithEmbedError(interaction, {
description: 'This command can only be used in a thread/forum post',
})
return
description: "This command can only be used in a thread/forum post",
});
return;
}

const mainChannel = interaction.channel.parent
const mainChannel = interaction.channel.parent;
if (mainChannel && mainChannel.type === ChannelType.GuildForum) {
const lockedTagId = mainChannel.availableTags.find((t) =>
t.name.includes('Locked')
)?.id
t.name.includes("Locked"),
)?.id;

if (lockedTagId) {
const newTags = Array.from(
new Set([...interaction.channel.appliedTags, lockedTagId])
)
interaction.channel.setAppliedTags(newTags)
new Set([...interaction.channel.appliedTags, lockedTagId]),
);
interaction.channel.setAppliedTags(newTags);
}
}

interaction.reply({ content: 'Ok!', ephemeral: true })
interaction.reply({ content: "Ok!", ephemeral: true });

await interaction.channel.setLocked(true)
await interaction.channel.setLocked(true);
await interaction.channel.send({
embeds: [
{
color: Colors.Blue,
title: '🔒 Post Locked',
title: "🔒 Post Locked",
description: dedent`
This post has been locked because it was considered low-effort by the moderation team. We encourage you to create a new post, keeping in mind the guidelines described here: https://discord.com/channels/752553802359505017/1138338531983491154
Try to add as much information possible in your question, describing your objective and what you have tried doing to solve it. This helps our members to understand better the question and give a better and faster answer. If you have any questions, feel free to reach out to the moderation team.
`,
},
],
})
});
},
}
};
46 changes: 23 additions & 23 deletions apps/bot/commands/slash/refresh-answer-count.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import { Colors, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'
import { SlashCommand } from '../types.js'
import { replyWithEmbed } from '../../utils.js'
import { db } from '@member-protocol/db/node'
import { Colors, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
import { SlashCommand } from "../types.js";
import { replyWithEmbed } from "../../utils.js";
import { db } from "@member-protocol/db/node";

export const command: SlashCommand = {
data: new SlashCommandBuilder()
.setName('refresh-answer-count')
.setName("refresh-answer-count")
.setDescription(
'Refreshes the count of answers for every user (expensive call so only use it if really necessary)'
"Refreshes the count of answers for every user (expensive call so only use it if really necessary)",
)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),

async execute(interaction) {
await replyWithEmbed(interaction, {
title: '⌛ Processing...',
title: "⌛ Processing...",
description:
'Your request has been queued. This might take a while to complete...',
})
"Your request has been queued. This might take a while to complete...",
});

try {
await db
.updateTable('users')
.updateTable("users")
.set({
answersCount: (eb) =>
eb
.selectFrom('posts')
.select(eb.fn.countAll<number>().as('count'))
.innerJoin('messages', (join) =>
.selectFrom("posts")
.select(eb.fn.countAll<number>().as("count"))
.innerJoin("messages", (join) =>
join
.onRef('messages.snowflakeId', '=', 'posts.answerId')
.onRef('messages.userId', '=', 'users.snowflakeId')
.onRef("messages.snowflakeId", "=", "posts.answerId")
.onRef("messages.userId", "=", "users.snowflakeId"),
),
})
.execute()
.execute();

await interaction.editReply({
embeds: [
{
title: '✅ Success!',
description: 'The answer count of the users has been updated',
title: "✅ Success!",
description: "The answer count of the users has been updated",
color: Colors.Green,
},
],
})
});
} catch (err) {
const description = err instanceof Error ? err.message : 'Unknown reason'
const description = err instanceof Error ? err.message : "Unknown reason";

await interaction.editReply({
embeds: [
{
title: 'Error',
title: "Error",
description,
},
],
})
});
}
},
}
};
Loading

0 comments on commit 804d92f

Please sign in to comment.