Skip to content
This repository was archived by the owner on May 24, 2021. It is now read-only.

Commit 7f15c07

Browse files
committed
Added broadcasts and statuses
Changed some commands to be more concise Updated the way arguments are handled to allow for full sentences instead of single words
1 parent 1cca14e commit 7f15c07

File tree

1 file changed

+65
-12
lines changed

1 file changed

+65
-12
lines changed

wikilinker.js

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,21 @@ bot.on('message', (msg) => {
3737
if (msg.author.bot || !msg.guild || !trulyReady) return;
3838

3939
if (msg.content.startsWith(config.prefix)) {
40-
const args = msg.content.slice(config.prefix.length).split(' ');
40+
const args = msg.content.slice(config.prefix.length).split(/ (.+)/);
4141
const command = args.shift();
4242
if (commands.hasOwnProperty(command)) commands[command](msg, args);
4343
} else if (/\[\[([^\]|]+)(?:|[^\]]+)?\]\]/g.test(msg.cleanContent) || /\{\{([^}|]+)(?:|[^}]+)?\}\}/g.test(msg.cleanContent) || /--([^\-|]+)(?:|[^-]+)?--/g.test(msg.cleanContent)) {
4444
if (!msg.guild.settings.wiki) {
45-
// eslint-disable-next-line consistant-return
46-
return msg.channel.sendMessage([
45+
// eslint-disable-next-line consistent-return
46+
return msg.channel.send([
4747
'This server has not set a default wiki yet.',
48-
'Users with the "Administrator" permission can do this using %setWiki <wikiname>.'
48+
'Users with the "Administrator" permission can do this using wl~swiki <wikiname>.'
49+
]);
50+
} else if (!msg.guild.settings.broadcastChannel) {
51+
// eslint-disable-next-line consistent-return
52+
return msg.channel.send([
53+
'This server has not set a broadcast channel yet.',
54+
'Users with the "Administrator" permission can do this using wl~broadcastchan <channel mention>.'
4955
]);
5056
}
5157

@@ -92,7 +98,7 @@ bot.on('message', (msg) => {
9298
preparedSend = preparedSend.filter(item => item !== undefined);
9399
if (preparedSend.length > 1) {
94100
console.log('Sending message...');
95-
msg.channel.sendMessage(preparedSend);
101+
msg.channel.send(preparedSend);
96102
}
97103
})
98104
.catch(console.error);
@@ -106,35 +112,82 @@ bot.on('message', (msg) => {
106112

107113
const commands = {
108114
help: (msg) => {
109-
msg.channel.sendMessage('Syntax and commands: <https://github.com/ThePsionic/RSWikiLinker#syntax>');
115+
msg.channel.send('Syntax and commands: <https://github.com/ThePsionic/RSWikiLinker#syntax>');
110116
},
111117
restart: (msg) => {
112-
if (msg.author.id !== config.admin_snowflake) return msg.channel.sendMessage("Sorry, Dave. I can't let you do that.");
113-
return msg.channel.sendMessage('**Bot restarting!**')
118+
if (msg.author.id !== config.admin_snowflake) return msg.channel.send("Sorry, Dave. I can't let you do that.");
119+
return msg.channel.send('**Bot restarting!**')
114120
.then(() => {
115121
process.exit(1);
116122
});
117123
},
118-
setWiki: (msg, [wiki]) => {
124+
// eslint-disable-next-line consistent-return
125+
broadcast: (msg, [globalMessage]) => {
126+
if (msg.author.id !== config.admin_snowflake) return msg.reply("you don't get to yell at everyone!");
127+
var joinedGuilds = Array.from(bot.guilds.keys());
128+
for (var i = 0; i < joinedGuilds.length; i++) {
129+
var guildID = joinedGuilds[i];
130+
if (db[guildID].broadcastChannel) {
131+
return bot.channels.get(db[guildID].broadcastChannel).send(globalMessage);
132+
}
133+
}
134+
},
135+
swiki: (msg, [wiki]) => {
119136
if (msg.author.id !== config.admin_snowflake || !msg.member.hasPermission('ADMINISTRATOR')) {
120137
return msg.reply('You are not allowed to change the default wiki of this server.');
121138
}
122-
db[msg.guild.id].wiki = wiki;
139+
db[msg.guild.id].wiki = wiki.split(' ')[0];
123140
return saveDB().then(() => {
124141
msg.reply(`Wiki is now set to: ${wiki}.`);
125142
}).catch(console.error);
126143
},
127-
cOverride: (msg, [wiki]) => {
144+
cwiki: (msg, [wiki]) => {
128145
if (msg.author.id !== config.admin_snowflake || !msg.member.hasPermission('ADMINISTRATOR')) {
129146
return msg.reply('You are not allowed to override the wiki of this channel.');
130147
} else if (msg.channel.id === msg.guild.id) {
131148
return msg.reply('You can\'t override the default channel of a server.');
132149
}
133150
if (!db[msg.guild.id].channelOverrides) db[msg.guild.id].channelOverrides = {};
134-
db[msg.guild.id].channelOverrides[msg.channel.id] = wiki;
151+
db[msg.guild.id].channelOverrides[msg.channel.id] = wiki.split(' ')[0];
135152
return saveDB().then(() => {
136153
msg.reply(`Wiki in this channel is now set to: ${wiki}.`);
137154
}).catch(console.error);
155+
},
156+
broadcastchan: (msg) => {
157+
if (!msg.mentions.channels || msg.mentions.channels.size > 1) {
158+
return msg.reply('You need to mention exactly one channel to be set as broadcast channel.');
159+
} else {
160+
var channel = msg.mentions.channels.first();
161+
db[msg.guild.id].broadcastChannel = channel.id;
162+
return saveDB().then(() => {
163+
msg.reply(`The broadcast channel for this server is now set to: ${channel.name}.`);
164+
});
165+
}
166+
},
167+
serverinfo: (msg) => {
168+
if (!msg.guild) return;
169+
var totalMessage = `\`\`\`\nInfo for server: ${msg.guild.name}`;
170+
if (!msg.guild.settings.broadcastChannel) {
171+
totalMessage += '\nNo broadcast channel set';
172+
} else {
173+
totalMessage += `\nBroadcast channel: ${msg.guild.channels.get(msg.guild.settings.broadcastChannel).name}`;
174+
}
175+
if (!msg.guild.settings.wiki) {
176+
totalMessage += '\nNo main wiki set';
177+
} else {
178+
totalMessage += `\nMain wiki: ${msg.guild.settings.wiki}`;
179+
}
180+
if (!msg.guild.settings.channelOverrides) {
181+
totalMessage += '\nNo channel overrides set';
182+
} else {
183+
totalMessage += '\nChannel overrides:';
184+
var channelIDs = Object.keys(msg.guild.settings.channelOverrides);
185+
for (var i = 0; i < channelIDs.length; i++) {
186+
totalMessage += `\n Wiki ${msg.guild.settings.channelOverrides[channelIDs[i]]} in channel ${msg.guild.channels.get(channelIDs[i]).name}`;
187+
}
188+
}
189+
totalMessage += '\n```';
190+
msg.channel.send(totalMessage);
138191
}
139192
};
140193

0 commit comments

Comments
 (0)