Skip to content

Commit b0c1009

Browse files
authored
Update ping command and some config and formatting cleanup (#147)
1 parent ea79d28 commit b0c1009

16 files changed

+357
-244
lines changed

.prettierrc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"singleQuote": true,
3-
"quoteProps": "as-needed",
4-
"trailingComma": "all",
5-
"bracketSpacing": true,
6-
"arrowParens": "always",
7-
"semi": true,
8-
"useTabs": false,
9-
"tabWidth": 4
10-
}
2+
"singleQuote": true,
3+
"quoteProps": "as-needed",
4+
"trailingComma": "all",
5+
"bracketSpacing": true,
6+
"arrowParens": "always",
7+
"semi": true,
8+
"useTabs": false,
9+
"tabWidth": 4
10+
}

package.json

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
{
2-
"name": "tauri-discord-bot",
3-
"private": true,
4-
"version": "0.0.0",
5-
"main": "src/index.ts",
6-
"type": "module",
7-
"scripts": {
8-
"dev": "nodemon --ext ts,js,mjs,json --legacy-watch --loader tsm .",
9-
"start": "tsm ."
10-
},
11-
"license": "MIT",
12-
"engines": {
13-
"node": "20.x"
14-
},
15-
"dependencies": {
16-
"discord.js": "14.15.2",
17-
"dotenv": "16.4.5",
18-
"express": "4.19.2",
19-
"jellycommands": "1.0.0-next.43",
20-
"ts-node": "10.9.2",
21-
"tsm": "2.3.0",
22-
"unfurl.js": "6.3.1",
23-
"url-regex-safe": "3.0.0"
24-
},
25-
"devDependencies": {
26-
"@types/express": "4.17.21",
27-
"@types/node": "20.12.12",
28-
"@types/url-regex-safe": "1.0.2",
29-
"nodemon": "3.1.1",
30-
"prettier": "3.2.5",
31-
"typescript": "5.4.5"
32-
}
2+
"name": "tauri-discord-bot",
3+
"private": true,
4+
"version": "0.0.0",
5+
"main": "src/index.ts",
6+
"type": "module",
7+
"scripts": {
8+
"dev": "nodemon --ext ts,js,mjs,json --legacy-watch --loader tsm .",
9+
"start": "tsm ."
10+
},
11+
"license": "MIT",
12+
"engines": {
13+
"node": ">=20.x"
14+
},
15+
"dependencies": {
16+
"discord.js": "14.15.2",
17+
"dotenv": "16.4.5",
18+
"express": "4.19.2",
19+
"jellycommands": "1.0.0-next.43",
20+
"ts-node": "10.9.2",
21+
"tsm": "2.3.0",
22+
"unfurl.js": "6.3.1",
23+
"url-regex-safe": "3.0.0"
24+
},
25+
"devDependencies": {
26+
"@types/express": "4.17.21",
27+
"@types/node": "20.12.12",
28+
"@types/url-regex-safe": "1.0.2",
29+
"nodemon": "3.1.1",
30+
"prettier": "3.2.5",
31+
"typescript": "5.4.5"
32+
}
3333
}

renovate.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"extends": [
3-
"config:base"
4-
]
2+
"extends": ["config:base"]
53
}

src/commands/ping.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { APIRole, Role, roleMention } from 'discord.js';
2+
import { command } from 'jellycommands';
3+
4+
export default command({
5+
name: 'ping',
6+
description: 'Ping a role',
7+
global: true,
8+
options: [
9+
{
10+
name: 'role',
11+
description: 'The role you want to ping',
12+
type: 'Role',
13+
required: true,
14+
},
15+
],
16+
run: async ({ interaction }) => {
17+
// Fetch the role and make sure it's pingable.
18+
const role = interaction.options.getRole('role', true);
19+
20+
// Fetch the member, since the interaction member might not be fully resolved.
21+
const member = await interaction.guild.members.fetch(
22+
interaction.user.id,
23+
);
24+
25+
// Check if the role is pingable or the member has permission to ping everyone anyways.
26+
let pingable = member.permissions.has('MentionEveryone', true)
27+
? 'yes'
28+
: pingableStatus(role);
29+
30+
if (pingable === 'no') {
31+
return await interaction.reply({
32+
content: 'This role is not pingable.',
33+
ephemeral: true,
34+
});
35+
}
36+
37+
// The user has to have the role to ping it in some circumstances.
38+
if (pingable === 'self') {
39+
if (!member.roles.cache.has(role.id)) {
40+
return await interaction.reply({
41+
content: 'You do not have permission to ping this role.',
42+
ephemeral: true,
43+
});
44+
}
45+
}
46+
47+
// Ping the role in a reply so that you can see the original sender of the command.
48+
await interaction.reply(`${roleMention(role.id)}`);
49+
},
50+
});
51+
52+
function pingableStatus(role: Role | APIRole): 'yes' | 'no' | 'self' {
53+
if (role.name === 'working-group' || role.name.startsWith('wg-')) {
54+
return 'self';
55+
} else if (['mod', 'moderator'].includes(role.name)) {
56+
return 'yes';
57+
} else {
58+
return 'no';
59+
}
60+
}

src/commands/reping.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/commands/thread.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ export default command({
141141
);
142142
// Successfully solved the thread
143143
// Get the first message in the thread
144-
const start_message = await thread.fetchStarterMessage();
144+
const start_message =
145+
await thread.fetchStarterMessage();
145146
// Get the first 2 messages after the start message
146147
const messages = await thread.messages.fetch({
147148
limit: 2,
@@ -167,7 +168,9 @@ export default command({
167168
msg.components = [row];
168169
await bot_message.edit(msg);
169170
// Commands require a reply
170-
await interaction.followUp(wrap_in_embed('Thread solved.'));
171+
await interaction.followUp(
172+
wrap_in_embed('Thread solved.'),
173+
);
171174
// Delete the reply after 10 seconds
172175
setTimeout(async () => {
173176
await interaction.deleteReply();
@@ -177,21 +180,33 @@ export default command({
177180
if (!(thread.parent instanceof ForumChannel))
178181
throw new Error("Can't solve a non-help channel");
179182
// Parent forum channel
180-
const solveChannel = thread.guild.channels.cache.get(thread.parentId) as ForumChannel
183+
const solveChannel = thread.guild.channels.cache.get(
184+
thread.parentId,
185+
) as ForumChannel;
181186
// Solve tag
182-
const solveTag = solveChannel.availableTags.find(tag => tag.name === SOLVED_TAG).id
187+
const solveTag = solveChannel.availableTags.find(
188+
(tag) => tag.name === SOLVED_TAG,
189+
).id;
183190
// Unsolve tag
184-
const unsolveTag = solveChannel.availableTags.find(tag => tag.name === UNSOLVED_TAG).id
191+
const unsolveTag = solveChannel.availableTags.find(
192+
(tag) => tag.name === UNSOLVED_TAG,
193+
).id;
185194
// If this is a ThreadChannel
186-
let tags = thread.appliedTags.filter(tag => tag !== solveTag && tag !== unsolveTag).splice(0, 4)
195+
let tags = thread.appliedTags
196+
.filter((tag) => tag !== solveTag && tag !== unsolveTag)
197+
.splice(0, 4);
187198
// Add the solved tag
188-
tags.unshift(solveTag)
199+
tags.unshift(solveTag);
189200
// If neither tag is going to exist in the channel, add unsolved
190-
if (!tags.includes(solveTag) && !tags.includes(unsolveTag)) tags.unshift(unsolveTag)
201+
if (!tags.includes(solveTag) && !tags.includes(unsolveTag))
202+
tags.unshift(unsolveTag);
191203
// Ensure no duplicates are in the array
192-
tags = [...new Set(tags)].sort()
204+
tags = [...new Set(tags)].sort();
193205
// Apply tags
194-
if (tags.toString() !== thread.appliedTags.sort().toString()) thread.setAppliedTags(tags)
206+
if (
207+
tags.toString() !== thread.appliedTags.sort().toString()
208+
)
209+
thread.setAppliedTags(tags);
195210
// Commands require a reply
196211
await interaction.followUp(wrap_in_embed('Thread solved.'));
197212
// Delete the reply after 10 seconds

src/commands/threads.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ export default command({
2828
await interaction.guild.channels.fetchActiveThreads()
2929
).threads
3030
.map((x) => x)
31-
.filter(
32-
(thread) =>
33-
thread
34-
.permissionsFor(interaction.user)
35-
.has(['ReadMessageHistory', 'ViewChannel']),
31+
.filter((thread) =>
32+
thread
33+
.permissionsFor(interaction.user)
34+
.has(['ReadMessageHistory', 'ViewChannel']),
3635
);
3736

3837
switch (subcommand) {

0 commit comments

Comments
 (0)