Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Commit

Permalink
6.3
Browse files Browse the repository at this point in the history
minor rework to some commands
  • Loading branch information
mirko93s authored Dec 17, 2020
1 parent 70af7bb commit b06ecbf
Show file tree
Hide file tree
Showing 66 changed files with 320 additions and 195 deletions.
28 changes: 8 additions & 20 deletions chill.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const SQLite = require("better-sqlite3");
const sql = new SQLite('./xp_database/scores.sqlite');
const Enmap = require('enmap');
const talkedRecently = new Set();
const { xpAdd, setupCheck } = require("./functions.js");
const { xpAdd, setupCheck, dmOwnerOnJoin } = require("./functions.js");

client.commands = new Collection();
client.aliases = new Collection();
Expand Down Expand Up @@ -42,7 +42,8 @@ const defaultSettings = {
supportrole: "Support",
roleonjoin: "Member",
musicchannelonly: "false",
xpcooldown: 5
xpcooldown: 5,
autodeletecmds: "true"
}

client.on('warn', console.warn);
Expand Down Expand Up @@ -80,20 +81,7 @@ client.on('guildCreate', (guild) => {
client.settings.ensure(guild.id, defaultSettings);
console.log(`+ Guild: ${guild.name}`);
//msg guild owner with setup info
const dmonweronjoinEmbed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setAuthor(`Chill - Discord Bot`)
.setURL(`https://www.mirko93s.it/`)
.setThumbnail(client.user.avatarURL())
.setTitle(`Thanks for inviting my bot!`)
.setDescription(`⚠️ Follow these instructions to setup the Bot (Don't skip them!) ⚠️
\n1️⃣ Type **.showconfig** \n> You can check the default settings in there. \n> **Then you can set them as you prefer using .setconfig.
\n2️⃣ Type **.setup** \n> It will create required channels, roles, etc according to the config you just set.
\n3️⃣ Set your role hierarchy\n> **Chill** (bot) role must be just below the owner/admin role.\n> **Muted** role must be above any other role that your members will get.
\n4️⃣ Extra settings\n> Sometimes you might need to adjust channel permissions to avoid that "Muted" members can still send messages.
\n5️⃣ Music\n> Don't forget to give **DJ** role to your members to make sure they can use Music commands.\n> If you will use "Music Only Channel" a hidden text channel will only be shown to people who are connected to the Music Vocal Channel`)
.setFooter(`©️ 2019-2020 by mirko93s`,`https://cdn.discordapp.com/avatars/278380909588381698/029d0578df3fa298132b3d85dd06bf3c.png?size=128`)
guild.owner.send(dmonweronjoinEmbed);
dmOwnerOnJoin(client, guild);
});

client.on("guildDelete", guild => {
Expand All @@ -107,7 +95,7 @@ client.on("guildMemberAdd", member => {

const welcomeEmbed = new Discord.MessageEmbed()
.setColor('GREEN')
.setTitle(`${member.user.username} joined...`)
.setDescription(`${member.user} joined...`)

const welcomechannel = member.guild.channels.cache.find(welcomechannel => welcomechannel.name === (client.settings.get(member.guild.id, "welcomechannel")));
if (!welcomechannel) return;
Expand Down Expand Up @@ -148,14 +136,14 @@ client.on("message", async msg => {
//music-text-channel doesn't need .play command
if (msg.channel.name === client.settings.get(msg.guild.id, "musictextchannel") && !msg.content.startsWith(prefix)) {
var MTC_state = true;
let commandh = client.commands.get("play");
commandh.run(client, msg, MTC_state);
let cmdplay = client.commands.get("play");
return cmdplay.run(client, msg, MTC_state);
}
//commands stuff
const arg = msg.content.slice(prefix.length).trim().split(/ +/g);
const cmd = arg.shift().toLowerCase();
//command handler
if (cmd.length === 0) return;
if (cmd.length === 0) return;
let commandh = client.commands.get(cmd);
if (!commandh) commandh = client.commands.get(client.aliases.get(cmd));
if (commandh) commandh.run(client, msg, arg);
Expand Down
3 changes: 2 additions & 1 deletion commands/Admin/addchannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = {
usage: "addchannel <text | voice> <name>\n**e.g.**\n\`addchannel text textchannelname\`\n> will create a text channel named \"textchannelname\"\n\`addchannel voice voicechannelname\`\n> will create a voice channel named voicechannelname ",
permission: "MANAGE_CHANNELS",
run: async (client, msg, arg) => {
msg.delete();
if (client.settings.get(msg.guild.id, "autodeletecmds") === "true") msg.delete();

const nopermEmbed = new Discord.MessageEmbed()
.setColor(`RED`)
.setTitle(`⛔ You don't have permission to use this!`)
Expand Down
2 changes: 1 addition & 1 deletion commands/Admin/broadcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
usage: "broadcast\n**e.g.**\n\`broadcast\`\n> Follow the instructions\n> Bot will ask you a title and a description/message\n> Title can be max 256 char long, Description can be max 2048 char long",
permission: "ADMINISTRATOR",
run: async (client, msg, arg) => {
msg.delete();
if (client.settings.get(msg.guild.id, "autodeletecmds") === "true") msg.delete();

let author = msg.author

Expand Down
118 changes: 61 additions & 57 deletions commands/Admin/giveaway.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Discord = require("discord.js");
const ms = require('ms');

module.exports = {
name: "giveaway",
Expand All @@ -8,8 +9,8 @@ module.exports = {
usage: "giveaway\n**e.g.**\n\`giveaway\`\n> Follow the instructions\n> Bot will ask you to enter a time and a prize",
permission: "MANAGE_GUILD",
run: async (client, msg, arg) => {

const ms = require('ms');
if (client.settings.get(msg.guild.id, "autodeletecmds") === "true") msg.delete();

var duration;
var prize;
var filter = m => m.author.id === msg.author.id;
Expand All @@ -35,73 +36,76 @@ module.exports = {
.setColor(`RANDOM`)
.setTitle(`🎉 Giveaway setup`)
.setDescription(`**Now send the prize**`)
const outoftimeEmbed = new Discord.MessageEmbed()
.setColor(`RED`)
.setTitle(`⛔ No answer after 30 seconds, operation canceled.`)

if(!msg.guild.member(msg.author).hasPermission('MANAGE_GUILD')) return msg.channel.send(nopermEmbed).then(msg => msg.delete({ timeout: 5000 }));
let gachannel = msg.guild.channels.cache.find(gachannel => gachannel.name === (client.settings.get(msg.guild.id, "gachannel")));
if(!gachannel) return msg.reply(nochannelEmbed).then(msg => msg.delete({ timeout: 5000 }));
msg.channel.send(sendtimeEmbed).then(msg => {//collect duration
msg.channel.awaitMessages(filter, {max: 1,time: 20000,errors: ['time']}).then(collected => {
msg.channel.awaitMessages(filter, {max: 1,time: 30000,errors: ['time']}).then(collected => {
if(!collected.first().content.match(/[1-60][s,m,h,d,w]/g)) return msg.channel.send(invalidtimeEmbed).then(msg => msg.delete({ timeout: 5000 }));
duration = collected.first().content
collected.first().delete();
msg.edit(sendprizeEmbed).then(msg => {//collect prize
msg.channel.awaitMessages(filter, {max: 1,time: 20000,errors: ['time']}).then(collected => {
prize = collected.first().content;
collected.first().delete();
msg.delete();
try {
let startEmbed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle(`🎉Giveaway Started`)
.setDescription(`*React With 🎉 To Enter!*`)
.addField(`Prize: **${prize}**`, `Time Left: **${duration}**`)
.setFooter("Created at:")
.setTimestamp()
gachannel.send(startEmbed).then(m => {
let re = m.react('🎉');
//update time left
let live = ms(duration);
var livetest = setInterval (liveupdate, 5000);
function liveupdate() {
live -= 5000;
if (live > 0) {
let liveEmbed = new Discord.MessageEmbed()
msg.channel.awaitMessages(filter, {max: 1,time: 30000,errors: ['time']}).then(collected => {
prize = collected.first().content;
collected.first().delete();
msg.delete();
try {
let startEmbed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle(`🎉Giveaway Started`)
.setDescription(`*React With 🎉 To Enter!*`)
.addField(`Prize: **${prize}**`, `Time Left: **${duration}**`)
.setFooter("Created at:")
.setTimestamp()
gachannel.send(startEmbed).then(m => {
let re = m.react('🎉');
//update time left
let live = ms(duration);
var livetest = setInterval (liveupdate, 5000);
function liveupdate() {
live -= 5000;
if (live > 0) {
let liveEmbed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle(`🎉Giveaway Started`)
.setDescription(`*React With 🎉 To Enter!*`)
.addField(`Prize: **${prize}**`, `Time Left: **${ms(live)}**`)
.setFooter("Created at:")
.setTimestamp()
m.edit({embed: liveEmbed});
} else {
clearInterval(livetest);
return;
}
}
//set timeout
setTimeout(() => {
let users = m.reactions.cache.get("🎉").users
let list = users.cache.array().filter(u => u.id !== client.user.id); //create array of people who reacted and filter bot reaction
let winner = list[Math.floor(Math.random() * list.length)]
if (!winner) winner = ("*No Participants*");
let endEmbed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle(`🎉Giveaway Started`)
.setDescription(`*React With 🎉 To Enter!*`)
.addField(`Prize: **${prize}**`, `Time Left: **${ms(live)}**`)
.setFooter("Created at:")
.setTitle(`🎉Giveaway Ended`)
.addField(`**Prize:** ${prize}`,`**Winner:** ${winner}`)
.setFooter("Ended at:")
.setTimestamp()
m.edit({embed: liveEmbed});
} else {
clearInterval(livetest);
return;
}
m.edit({embed: endEmbed});
if(list == 0) return undefined;
gachannel.send(`**Congratulations ${winner}!\nYou won: \`${prize}\`**`)
}, ms(duration));
});
} catch(e) {
msg.channel.send(nobotpermEmbed);
console.log(e);
}
//set timeout
setTimeout(() => {
let users = m.reactions.cache.get("🎉").users
let list = users.cache.array().filter(u => u.id !== client.user.id); //create array of people who reacted and filter bot reaction
let winner = list[Math.floor(Math.random() * list.length)]
if (!winner) winner = ("*No Participants*");
let endEmbed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle(`🎉Giveaway Ended`)
.addField(`**Prize:** ${prize}`,`**Winner:** ${winner}`)
.setFooter("Ended at:")
.setTimestamp()
m.edit({embed: endEmbed});
if(list == 0) return undefined;
gachannel.send(`**Congratulations ${winner}!\nYou won: \`${prize}\`**`)
}, ms(duration));
});
} catch(e) {
msg.channel.send(nobotpermEmbed);
console.log(e);
}
});
}).catch(() => {return msg.edit(outoftimeEmbed).then(msg => msg.delete({ timeout: 5000 }));});
});
});
});
}).catch(() => {return msg.edit(outoftimeEmbed).then(msg => msg.delete({ timeout: 5000 }));});
});
}
}
71 changes: 56 additions & 15 deletions commands/Admin/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,78 @@ const Discord = require("discord.js");
module.exports = {
name: "poll",
category: "Admin",
description: "Start a poll in the preset channel",
usage: "poll <question>\n**e.g.**\n\`poll is this a question?\`\n> It will create a poll in the \"poll-channel\" with the question \"is this a question ?\"\n> Then people can choose between 3 reactions",
description: "Start a multiple choice poll in the preset channel",
usage: "poll <question>\n**e.g.**\n\`poll What is your favourite fruit?\`\n> Then input the choices, separated by commas \`,\`\n> It will create a multiple choice poll in the \"poll-channel\" with the question \"What is your favourite food ?\"\n> Then people can vote 1 or more of your inputted choices",
permission: "MANAGE_GUILD",
run: async (client, msg, arg) => {
msg.delete();
if (client.settings.get(msg.guild.id, "autodeletecmds") === "true") msg.delete();

const nopermEmbed = new Discord.MessageEmbed()
.setColor(`RED`)
.setTitle(`⛔ You don't have permission to use this!`)
const nochannelEmbed = new Discord.MessageEmbed()
.setColor(`RED`)
.setTitle(`⛔ Poll channel not found`)
const wrongchoicesEmbed = new Discord.MessageEmbed()
.setColor(`RED`)
.setTitle(`⛔ Please provide at least 2 choices to start a poll`)
.setFooter(`max 10 choices, use commas to separate choices`)
const noquestionEmbed = new Discord.MessageEmbed()
.setColor(`RED`)
.setTitle(`⛔ Please provide a question to start a poll`)
.setFooter(`Question must be longer than 10 characters`)
const askchoicesEmbed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle(`Poll setup`)
.setDescription(`**Input the choices separated by commas**`)
const outoftimeEmbed = new Discord.MessageEmbed()
.setColor(`RED`)
.setTitle(`⛔ No answer after 30 seconds, operation canceled.`)

var filter = m => m.author.id === msg.author.id;
var choices;
var emoji = ['🍏','🍎','🍐','🍊','🍋','🍌','🍉','🍇','🫐','🍓','🍈','🍒','🍑','🥭','🍍','🥥','🥝','🍅','🥑','🥒']
var choicemsg = "";

if(!msg.guild.member(msg.author).hasPermission('MANAGE_GUILD')) return msg.channel.send(nopermEmbed).then(msg => msg.delete({ timeout: 5000 }));
let pollchannel = msg.guild.channels.cache.find(pollchannel => pollchannel.name === (client.settings.get(msg.guild.id, "pollchannel")));
if(!pollchannel) return msg.channel.send(nochannelEmbed).then(msg => msg.delete({ timeout: 5000 }));
let question = arg.join(' ');
if(!question || question < 10) return msg.channel.send(noquestionEmbed).then(msg => msg.delete({ timeout: 5000 }));
let pollEmbed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle(`**${question}**`)
.setDescription(`*React to vote*`)
.setTimestamp()
pollchannel.send(pollEmbed).then(sentEmbed => {
sentEmbed.react("👍")
.then (() => sentEmbed.react("❔"))
.then (() => sentEmbed.react("👎"))
})

let question = arg.join(" ");
if (!question) return msg.channel.send(noquestionEmbed).then(msg => msg.delete({ timeout: 5000 }));

msg.channel.send(askchoicesEmbed).then(msg => {
msg.channel.awaitMessages(filter, {max: 1,time: 30000,errors: ['time']}).then(collected => {
choices = collected.first().content;
collected.first().delete()
msg.delete();
if (choices.endsWith(",") === true) choices = choices.slice(0,(choices.length-1)); //remove last "," from choices string
choices = choices.split(","); //convert choices to an array
if (choices.length > 10 || choices.length < 2) return msg.channel.send(wrongchoicesEmbed).then(msg => msg.delete({ timeout: 5000 })); //choices can't be > 10

for (var i = emoji.length - 1; i > 0; i--) { //scramble emoji array
var j = Math.floor(Math.random() * (i + 1));
var temp = emoji[i];
emoji[i] = emoji[j];
emoji[j] = temp;
}

for (var i=0; i<choices.length; i++) { //prepare choice msg
choicemsg += `${emoji[i]} ${choices[i]}\n`;
}

let pollEmbed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle(`${question}`)
.setDescription(`**React to vote**\n`+choicemsg)
.setTimestamp()

pollchannel.send(pollEmbed).then(msg => {
for (var i = 0; i < choices.length; i++) {
msg.react(emoji[i]);
}
});
}).catch(() => {return msg.edit(outoftimeEmbed).then(msg => msg.delete({ timeout: 5000 }));});
});
}
}
2 changes: 1 addition & 1 deletion commands/Admin/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
usage: "setup\n**e.g.**\n> \`setup\`\n> It will create preset channels, roles, channel categories, etc...",
permission: "ADMINISTRATOR",
run: async (client, msg, arg) => {
msg.delete();
if (client.settings.get(msg.guild.id, "autodeletecmds") === "true") msg.delete();

const nopermEmbed = new Discord.MessageEmbed()
.setColor(`RED`)
Expand Down
Loading

0 comments on commit b06ecbf

Please sign in to comment.