Skip to content

Commit

Permalink
Update ping command and some config and formatting cleanup (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity authored Jun 3, 2024
1 parent ea79d28 commit b0c1009
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 244 deletions.
18 changes: 9 additions & 9 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "always",
"semi": true,
"useTabs": false,
"tabWidth": 4
}
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "always",
"semi": true,
"useTabs": false,
"tabWidth": 4
}
62 changes: 31 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
{
"name": "tauri-discord-bot",
"private": true,
"version": "0.0.0",
"main": "src/index.ts",
"type": "module",
"scripts": {
"dev": "nodemon --ext ts,js,mjs,json --legacy-watch --loader tsm .",
"start": "tsm ."
},
"license": "MIT",
"engines": {
"node": "20.x"
},
"dependencies": {
"discord.js": "14.15.2",
"dotenv": "16.4.5",
"express": "4.19.2",
"jellycommands": "1.0.0-next.43",
"ts-node": "10.9.2",
"tsm": "2.3.0",
"unfurl.js": "6.3.1",
"url-regex-safe": "3.0.0"
},
"devDependencies": {
"@types/express": "4.17.21",
"@types/node": "20.12.12",
"@types/url-regex-safe": "1.0.2",
"nodemon": "3.1.1",
"prettier": "3.2.5",
"typescript": "5.4.5"
}
"name": "tauri-discord-bot",
"private": true,
"version": "0.0.0",
"main": "src/index.ts",
"type": "module",
"scripts": {
"dev": "nodemon --ext ts,js,mjs,json --legacy-watch --loader tsm .",
"start": "tsm ."
},
"license": "MIT",
"engines": {
"node": ">=20.x"
},
"dependencies": {
"discord.js": "14.15.2",
"dotenv": "16.4.5",
"express": "4.19.2",
"jellycommands": "1.0.0-next.43",
"ts-node": "10.9.2",
"tsm": "2.3.0",
"unfurl.js": "6.3.1",
"url-regex-safe": "3.0.0"
},
"devDependencies": {
"@types/express": "4.17.21",
"@types/node": "20.12.12",
"@types/url-regex-safe": "1.0.2",
"nodemon": "3.1.1",
"prettier": "3.2.5",
"typescript": "5.4.5"
}
}
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"config:base"
]
"extends": ["config:base"]
}
60 changes: 60 additions & 0 deletions src/commands/ping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { APIRole, Role, roleMention } from 'discord.js';
import { command } from 'jellycommands';

export default command({
name: 'ping',
description: 'Ping a role',
global: true,
options: [
{
name: 'role',
description: 'The role you want to ping',
type: 'Role',
required: true,
},
],
run: async ({ interaction }) => {
// Fetch the role and make sure it's pingable.
const role = interaction.options.getRole('role', true);

// Fetch the member, since the interaction member might not be fully resolved.
const member = await interaction.guild.members.fetch(
interaction.user.id,
);

// Check if the role is pingable or the member has permission to ping everyone anyways.
let pingable = member.permissions.has('MentionEveryone', true)
? 'yes'
: pingableStatus(role);

if (pingable === 'no') {
return await interaction.reply({
content: 'This role is not pingable.',
ephemeral: true,
});
}

// The user has to have the role to ping it in some circumstances.
if (pingable === 'self') {
if (!member.roles.cache.has(role.id)) {
return await interaction.reply({
content: 'You do not have permission to ping this role.',
ephemeral: true,
});
}
}

// Ping the role in a reply so that you can see the original sender of the command.
await interaction.reply(`${roleMention(role.id)}`);
},
});

function pingableStatus(role: Role | APIRole): 'yes' | 'no' | 'self' {
if (role.name === 'working-group' || role.name.startsWith('wg-')) {
return 'self';
} else if (['mod', 'moderator'].includes(role.name)) {
return 'yes';
} else {
return 'no';
}
}
38 changes: 0 additions & 38 deletions src/commands/reping.ts

This file was deleted.

35 changes: 25 additions & 10 deletions src/commands/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export default command({
);
// Successfully solved the thread
// Get the first message in the thread
const start_message = await thread.fetchStarterMessage();
const start_message =
await thread.fetchStarterMessage();
// Get the first 2 messages after the start message
const messages = await thread.messages.fetch({
limit: 2,
Expand All @@ -167,7 +168,9 @@ export default command({
msg.components = [row];
await bot_message.edit(msg);
// Commands require a reply
await interaction.followUp(wrap_in_embed('Thread solved.'));
await interaction.followUp(
wrap_in_embed('Thread solved.'),
);
// Delete the reply after 10 seconds
setTimeout(async () => {
await interaction.deleteReply();
Expand All @@ -177,21 +180,33 @@ export default command({
if (!(thread.parent instanceof ForumChannel))
throw new Error("Can't solve a non-help channel");
// Parent forum channel
const solveChannel = thread.guild.channels.cache.get(thread.parentId) as ForumChannel
const solveChannel = thread.guild.channels.cache.get(
thread.parentId,
) as ForumChannel;
// Solve tag
const solveTag = solveChannel.availableTags.find(tag => tag.name === SOLVED_TAG).id
const solveTag = solveChannel.availableTags.find(
(tag) => tag.name === SOLVED_TAG,
).id;
// Unsolve tag
const unsolveTag = solveChannel.availableTags.find(tag => tag.name === UNSOLVED_TAG).id
const unsolveTag = solveChannel.availableTags.find(
(tag) => tag.name === UNSOLVED_TAG,
).id;
// If this is a ThreadChannel
let tags = thread.appliedTags.filter(tag => tag !== solveTag && tag !== unsolveTag).splice(0, 4)
let tags = thread.appliedTags
.filter((tag) => tag !== solveTag && tag !== unsolveTag)
.splice(0, 4);
// Add the solved tag
tags.unshift(solveTag)
tags.unshift(solveTag);
// If neither tag is going to exist in the channel, add unsolved
if (!tags.includes(solveTag) && !tags.includes(unsolveTag)) tags.unshift(unsolveTag)
if (!tags.includes(solveTag) && !tags.includes(unsolveTag))
tags.unshift(unsolveTag);
// Ensure no duplicates are in the array
tags = [...new Set(tags)].sort()
tags = [...new Set(tags)].sort();
// Apply tags
if (tags.toString() !== thread.appliedTags.sort().toString()) thread.setAppliedTags(tags)
if (
tags.toString() !== thread.appliedTags.sort().toString()
)
thread.setAppliedTags(tags);
// Commands require a reply
await interaction.followUp(wrap_in_embed('Thread solved.'));
// Delete the reply after 10 seconds
Expand Down
9 changes: 4 additions & 5 deletions src/commands/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ export default command({
await interaction.guild.channels.fetchActiveThreads()
).threads
.map((x) => x)
.filter(
(thread) =>
thread
.permissionsFor(interaction.user)
.has(['ReadMessageHistory', 'ViewChannel']),
.filter((thread) =>
thread
.permissionsFor(interaction.user)
.has(['ReadMessageHistory', 'ViewChannel']),
);

switch (subcommand) {
Expand Down
Loading

0 comments on commit b0c1009

Please sign in to comment.