Skip to content

Commit f1cedb7

Browse files
committed
feat: add presence shuffle
1 parent 5a72c1d commit f1cedb7

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/index.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,40 @@ import { config } from "./lib/config.js";
33
import registerCommandEvents from "./events/commands.js";
44
import registerWalkthroughEvents from "./events/walkthrough.js";
55

6-
import { Client, Events, GatewayIntentBits } from "discord.js";
6+
import { Client, Events, GatewayIntentBits, ActivityType } from "discord.js";
77

88
const client = new Client({ intents: [ GatewayIntentBits.Guilds ] });
99

10+
const presenceList = [
11+
{ name: "with Coder OSS", type: ActivityType.Playing },
12+
{ name: "with code-server", type: ActivityType.Playing },
13+
{ name: "with envbuilder", type: ActivityType.Playing },
14+
{ name: "with wush", type: ActivityType.Playing },
15+
{ name: "with Terraform", type: ActivityType.Playing },
16+
{ name: "to your issues", type: ActivityType.Listening },
17+
{ name: "over the Coder community", type: ActivityType.Watching },
18+
];
19+
20+
function shufflePresence() {
21+
const randomPresence = presenceList[Math.floor(Math.random() * presenceList.length)];
22+
23+
return client.user.setPresence({
24+
activities: [
25+
randomPresence
26+
],
27+
28+
status: "online"
29+
});
30+
}
31+
1032
client.once(Events.ClientReady, () => {
1133
console.log(`Logged in as ${client.user?.tag}!`);
1234

1335
registerCommandEvents(client);
1436
registerWalkthroughEvents(client);
37+
38+
shufflePresence();
39+
setInterval(shufflePresence, config.presenceDelay);
1540
});
1641

1742
client.login(config.token);

src/lib/channels.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export async function getChannelFromInteraction(interaction: ChatInputCommandInt
66
return interaction.channel ?? (interaction.client.channels.fetch(interaction.channelId) as Promise<GuildTextBasedChannel>);
77
}
88

9-
// TODO: check if we can replace by .isThreadOnly();
109
async function isForumPost(channel: GuildTextBasedChannel) {
1110
// If the channel is a thread, then we check if its parent is a Forum channel, if it is, then we are in a forum post.
1211
if (channel.isThread()) {

src/lib/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ interface Config {
2727
windows: string;
2828
vscode: string;
2929
}
30+
31+
presenceDelay: number;
3032
}
3133

3234
export const { config, layers } = await loadConfig<Config>({
@@ -39,7 +41,9 @@ export const { config, layers } = await loadConfig<Config>({
3941

4042
configs: ["config.json"],
4143

42-
defaults: {},
44+
defaults: {
45+
"presenceDelay": 10 * 60 * 1000
46+
},
4347
mandatory: [
4448
"token",
4549

0 commit comments

Comments
 (0)