New preferred channels
This commit is contained in:
1 parent
4f4de80ed7
commit
c4644ce44d
1 file changed
+60
-2
@@ -415,6 +415,25 @@ class Bot {
|
|||||||
return message.channel.send(`You are in the community \`${community.community.name}\` ${message.author}!`);
|
return message.channel.send(`You are in the community \`${community.community.name}\` ${message.author}!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setChannel(message, args) {
|
||||||
|
if (args.length==0) return message.channel.send(`You must provide a channel ${message.author}!`);
|
||||||
|
let channel = client.channels.cache.get(args[0].replace('<#', '').replace('>', ''));
|
||||||
|
if (!channel) return message.channel.send(`Cannot find that channel ${message.author}!`);
|
||||||
|
if (channel.type=="voice") return message.channel.send(`Connot set voice channel to preferred channel ${message.author}!`);
|
||||||
|
if (channel.deleted) return message.channel.send(`Connot set deleted channel to preferred channel ${message.author}!`);
|
||||||
|
this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$set:{"server.preferredChannelId":channel.id}},function(err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
return message.channel.send(`Successfuly set \` ${channel.name} \` to prefered channel ${message.author}!`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeChannel(message) {
|
||||||
|
this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$set:{"server.preferredChannelId":null}},function(err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
return message.channel.send(`Successfuly removed preferred channel ${message.author}!`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async getPrefix(message) {
|
async getPrefix(message) {
|
||||||
let prefix;
|
let prefix;
|
||||||
if (message.channel.type!="dm") {
|
if (message.channel.type!="dm") {
|
||||||
@@ -437,16 +456,41 @@ class Bot {
|
|||||||
return prefix
|
return prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getPreferredChannel(message) {
|
||||||
|
let channelId;
|
||||||
|
if (message.channel.type!="dm") {
|
||||||
|
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild);
|
||||||
|
|
||||||
|
if (!guild) {
|
||||||
|
let newGuild = {
|
||||||
|
server: {
|
||||||
|
serverID: message.guild.id,
|
||||||
|
prefix: this.config.defaultPrefix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.dbo.collection("prefixes").insertOne(newGuild, function(err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
prefix = newGuild.server.serverID;
|
||||||
|
} else channelId = guild.server.preferredChannelId;
|
||||||
|
} else channelId = null;
|
||||||
|
return channelId;
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
console.log(`Logged in as ${client.user.tag}`);
|
console.log(`Logged in as ${client.user.tag}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Basic Commands
|
// Basic Commands
|
||||||
client.on('message', (message) => {
|
client.on('message', async (message) => {
|
||||||
this.getPrefix(message).then(prefix => {
|
this.getPrefix(message).then(prefix => {
|
||||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
||||||
|
|
||||||
|
this.getPreferredChannel(message).then(channelId => {
|
||||||
|
if (channelId != null && message.channel.id!=channelId) {
|
||||||
|
return message.channel.send(`This is not the preferred channel, please use the channel <#${channelId}> ${message.author}!`);
|
||||||
|
}
|
||||||
const args = message.content.slice(prefix.length).trim().split(' ');
|
const args = message.content.slice(prefix.length).trim().split(' ');
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
@@ -497,7 +541,9 @@ class Bot {
|
|||||||
{ name: `**${prefix}panic**`, value: '\`Enables or disables your panic button\`', inline: true },
|
{ name: `**${prefix}panic**`, value: '\`Enables or disables your panic button\`', inline: true },
|
||||||
{ name: `**${prefix}joincommunity** <community code>`, value: '\`Joined a community with the given code\`', inline: true },
|
{ name: `**${prefix}joincommunity** <community code>`, value: '\`Joined a community with the given code\`', inline: true },
|
||||||
{ name: `**${prefix}leavecommunity**`, value: '\`Leaves your current active community\`', inline: true },
|
{ name: `**${prefix}leavecommunity**`, value: '\`Leaves your current active community\`', inline: true },
|
||||||
{ name: `**${prefix}community**`, value: '\`Returns the name of the Community your currenty in\`', inline: true }
|
{ name: `**${prefix}community**`, value: '\`Returns the name of the Community your currenty in\`', inline: true },
|
||||||
|
{ name: `**${prefix}setChannel** <channel>`, value: `\`Sets preferred channel allowed for commands (Admin only command)\``, inline: true },
|
||||||
|
{ name: `**${prefix}removeChannel**`, value: `\nRemoves preferred channel (Admin only command)\n`, inline: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
const stats = new Discord.MessageEmbed()
|
const stats = new Discord.MessageEmbed()
|
||||||
@@ -516,6 +562,17 @@ class Bot {
|
|||||||
if(!message.member.hasPermission(["ADMINISTRATOR","MANAGE_GUILD"])) return message.channel.send(`You don't have permission to used this command ${message.author}`);
|
if(!message.member.hasPermission(["ADMINISTRATOR","MANAGE_GUILD"])) return message.channel.send(`You don't have permission to used this command ${message.author}`);
|
||||||
this.newPrefix(message, args);
|
this.newPrefix(message, args);
|
||||||
}
|
}
|
||||||
|
if (command == 'setchannel') {
|
||||||
|
if (message.channel.type=="dm") return message.author.send(`You cannot set a prefix in a dm ${message.author}!`);
|
||||||
|
if (!message.member.hasPermission(["ADMINISTRATOR","MANAGE_GUILD"])) return message.channel.send(`You don't have permission to used this command ${message.author}`);
|
||||||
|
this.setChannel(message, args);
|
||||||
|
}
|
||||||
|
if (command == 'removechannel') {
|
||||||
|
if (message.channel.type=="dm") return message.author.send(`You cannot set a prefix in a dm ${message.author}!`);
|
||||||
|
if (!message.member.hasPermission(["ADMINISTRATOR","MANAGE_GUILD"])) return message.channel.send(`You don't have permission to used this command ${message.author}`);
|
||||||
|
this.removeChannel(message);
|
||||||
|
}
|
||||||
|
|
||||||
// Login
|
// Login
|
||||||
if (command == 'login') {
|
if (command == 'login') {
|
||||||
if (message.channel.type=="text") return message.channel.send(`You must direct message me to use this command ${message.author}!`);
|
if (message.channel.type=="text") return message.channel.send(`You must direct message me to use this command ${message.author}!`);
|
||||||
@@ -550,6 +607,7 @@ class Bot {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
client.login(this.token);
|
client.login(this.token);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user