-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
165 lines (121 loc) · 4.96 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { config as dotenv } from "dotenv";
import { readFileSync, createReadStream } from "fs";
import { join } from 'path';
//import { config } from './config.json';
dotenv();
import { Client, Intents, VoiceChannel } from "discord.js";
import { joinVoiceChannel, VoiceConnectionStatus, getVoiceConnection, createAudioPlayer, createAudioResource,AudioPlayerStatus,StreamType } from "@discordjs/voice";
import path from 'path';
const __dirname = path.resolve();
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_MESSAGE_TYPING] });
const TextChannelIDs = ['874108308489908244'];
const VoiceChannelID = '874110429155192873';
const ServerID = '874089774342873159';
const TrustedRoles = ['874094274273214555'];
const audioPlayer = createAudioPlayer();
let soundResetNow = createAudioResource(join(__dirname,'resetnow.mp3'), { inlineVolume: true });
soundResetNow.volume.setVolume(.9);
let soundResetWarn = createAudioResource(join(__dirname, '5minwarning.mp3'), { inlineVolume: true })
soundResetWarn.volume.setVolume(.9);
console.log('Bot Loaded')
function sendToChannels(text){
TextChannelIDs.forEach(function(channelid){
sendToTextChannel(text,channelid);
})
}
async function sendToTextChannel(text,channelid){
const channel = await client.channels.fetch(channelid);
channel.send(text);
}
client.once('ready', () => {
sendToChannels('New World Timer Bot is online. Current countdown set to 30 minutes.');
console.log('Bot Online')
})
client.on("ready", async () => {
const vChan = await client.channels.fetch(VoiceChannelID)
const guild = await vChan.client.guilds.fetch(ServerID)
const connection = joinVoiceChannel({
channelId: VoiceChannelID,
guildId: ServerID,
adapterCreator: guild.voiceAdapterCreator,
});
const subscription = connection.subscribe(audioPlayer);
})
audioPlayer.on(AudioPlayerStatus.Playing, () => {
console.log("currently playing");
console.log("resource started:", soundResetNow.started);
});
audioPlayer.on('error', error => {
console.error(`Error: ${error.message} with resource ${error.soundResetNow.metadata.title}`);
});
audioPlayer.on(AudioPlayerStatus.AutoPaused, () => {
console.log("done");
});
function isTrustedUser (user, author){
let trusted = false;
if (author.tag == 'Saereth#7836')
trusted = true;
TrustedRoles.forEach(function(roleID){
if (user.roles.cache.has(roleID))
trusted = true;
})
return trusted;
}
var timer = -1; // 30 minutes
console.log('Initial Timer set to off')
setInterval(function () {
if (timer > 0){
timer -= 15000;
//console.log("NW Timer Bot: " + Math.round((timer/1000/60)) + " Minutes until townboard reset.");
if (timer == 0){
sendToChannels('Town Board Timer is Resetting NOW!');
audioPlayer.play(soundResetNow);
timer = 1800000;
}
if (timer == 300000){
sendToChannels('Town Board Resetting in 5 Minutes!');
audioPlayer.play(soundResetWarn);
}
}
}, 15000)
client.on("messageCreate", message => {
if (message.author.bot) return;
let trusted = isTrustedUser(message.member, message.author);
const args = message.content.slice(1).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if(command === 'newt') {
let subCommand = args[0];
let param = args[1];
if (!trusted){
message.channel.send('You are not authorized to use this bot.');
}
else{
switch (subCommand) {
case "setTimer" :
if (!isNaN(param) && param > 0 && param < 1440){
timer = param*60*1000; //convert to ms
message.channel.send('Board Timer Updated to: ' + param + " minutes");
}
else {
message.channel.send('Board Timer must be between 1 and 1440 minutes');
}
break;
case "stopTimer" :
timer = -1;
message.channel.send('Board Timer Stopped.');
break;
case "status" :
if (timer < 0)
message.channel.send('Board Timer is not currently running.');
else
message.channel.send('Board Timer\'s Current Time until reset is: ~' + Math.round((timer/1000)/60));
break;
case "help" :
message.channel.send('subCommands are: \nsetTimer parameter - Sets the timer; parameter is time in second\nstopTimer - Stops the Timer.\nstatus - displays the current countdown value of the timer in minutes.');
break;
}
}
}
});
client.login(process.env.DJS_TOKEN);
// client.login(config.token);