Skip to content

Commit

Permalink
Merge pull request #3 from Hab3925/master
Browse files Browse the repository at this point in the history
Move things over
  • Loading branch information
MelodicAlbuild authored Apr 9, 2021
2 parents 4be5e4f + ae9965c commit 97ca506
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 26 deletions.
5 changes: 4 additions & 1 deletion commands/enmap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports.run = async (client, message, args) => {
const {
inspect
} = require("util");
if (client[args[0]] instanceof Map) {
if (args[1] == "delete") {
try {
Expand All @@ -18,7 +21,7 @@ module.exports.run = async (client, message, args) => {
}
} else if (args[1] == "get") {
if (!args[2]) return message.channel.send("You have to say what variable you want to `get`")
message.channel.send(client[args[0]].get(args[2]))
message.channel.send(`\`\`\`` + inspect(client[args[0]].get(args[2])) + `\`\`\``)
} else {
message.channel.send("Invalid operation")
}
Expand Down
84 changes: 76 additions & 8 deletions commands/mute.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,91 @@
module.exports.run = async (client, message, args) => {
//if guild doesent have an entery in the enmap
if (!client.mute.has(message.guild.id)) {
client.mute.set(message.guild.id, {
role: undefined,
users: []
})
}


let obj = client.mute.get(message.guild.id)

// if there is no `Muted` role, send an error
if (!mutedRole)
return message.channel.send('There is no Muted role on this server, make a role and call it "Muted"');
if (!args[0]) return message.channel.send("You need to tell me who to mute!")

const target = message.mentions.members.first();
target.roles.add(mutedRole);
//if user mentions a role
if (args[0].match(/<@&\d{18}>/g)) {
if (obj.role != undefined) {
//if there already is a role, ask if user wants to replace it.
const newRole = await client.awaitReply(message, "You have already saved a muted role on this server, do you want to replace it?", 60000)
if (newRole.toLowerCase() == "y" || newRole.toLowerCase() == "yes") {
obj.role = args[0].replace(/<|@|&|>/g, "")
client.mute.set(message.guild.id, obj)
message.channel.send("Mute role set to " + args[0])
} else {
message.channel.send(`Mute role remains unchanged. (<@&${obj.role}>)`)
}
} else {
//If not, set the said role.
obj.role = args[0].replace(/<|@|&|>/g, "")
client.mute.set(message.guild.id, obj)
message.channel.send("Mute role set to " + args[0])
}
//if user mentioned a person
} else if (args[0].match(/<@!?\d{18}>/g)) {
const mutedRole = message.guild.roles.cache.get(obj.role);
if (!message.guild.roles.cache.has(obj.role)) return message.channel.send("The current mute role doesent exist! You need to set a new one.")

const target = message.mentions.members.first();
try {
target.roles.add(mutedRole);
} catch {
return message.channel.send("I dont have the permissions to mute people! Make sure i can edit roles and that my role is over the muted role!")
}

if (!args[1]) args[1] = ""

// if they provided a time
if (args[1].match(/\d+/g)) {
obj.users.push({
user: args[0].replace(/<|@|!|>/g, ""),
time: args[1] * 3600000 + new Date().getTime()
})
client.mute.set(message.guild.id, obj)
message.channel.send(`Muted ${args[0]} for ${args[1]} hours.`)
client.channels.cache.get(client.logchn.get(message.guild.id)).send(`<@${message.author.id}> muted ${args[0]} for ${args[1]} hours.`)

//wait for timer to expire
setTimeout(() => {
obj = client.mute.get(message.guild.id)

// remove user from database
obj.users.forEach((user, i) => {
if (user.user == args[0].replace(/<|@|!|>/g, "")) {
obj.users.splice(i, 1)
client.mute.set(message.guild.id, obj)
}
});
target.roles.remove(mutedRole)
}, args[1] * 3600000);
} else {
// if there is no time
obj.users.push({
user: args[0].replace(/<|@|!|>/g, ""),
time: undefined
})
client.mute.set(message.guild.id, obj)
message.channel.send(`Muted ${args[0]}`)
client.channels.cache.get(client.logchn.get(message.guild.id)).send(`<@${message.author.id}> muted ${args[0]}`)

}
}
}

exports.help = {
name: "mute",
desc: "Mute a user.",
aliases: [""],
aliases: [],
permLvl: 1,
hidden: false,
category: "admin",
usage: "mute [@user] (time)"
usage: "mute [@user] (hours)"
}
13 changes: 13 additions & 0 deletions commands/nolt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports.run = async (client, message, args) => {
message.channel.send(`You can leave a suggestion on nolt! (https://volcanoids.nolt.io/) \nMake sure someone didnt suggest what you want to suggest before you post!`)
}

exports.help = {
name: "nolt",
desc: "Make cap",
aliases: ["n"],
permLvl: 0,
hidden: true,
category: "volc",
usage: "nolt"
}
4 changes: 2 additions & 2 deletions commands/steam.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports.run = async (client, message, args) => {
message.channel.send(`You can get Volcanoids on Steam here: https://store.steampowered.com/app/951440/Volcanoids/`)
message.channel.send(`You can get Volcanoids on Steam here: https://store.steampowered.com/app/951440/Volcanoids?utm_source=discord&utm_medium=autoreply`)
}

exports.help = {
name: "steam",
desc: "Gives you Volcanoids\' [steam link](https://store.steampowered.com/app/951440/Volcanoids/)",
desc: "Gives you Volcanoids\' [steam link](https://store.steampowered.com/app/951440/Volcanoids?utm_source=discord&utm_medium=autoreply)",
aliases: ['staem', 'setam'],
permLvl: 0,
hidden: false,
Expand Down
43 changes: 29 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (!loginToken) {

//constants
const Discord = require("discord.js");
const client = new Discord.Client();
const client = new Discord.Client({ ws: { intents: ['GUILD_MEMBERS'] } });
const {
promisify
} = require("util");
Expand Down Expand Up @@ -61,6 +61,10 @@ client.mute = new Enmap({
name: "mute"
})

client.on('guildMemberAdd', member => {
console.log("test")
});

client.on("ready", async () => {
if (useDatabase) await client.connect(con);

Expand Down Expand Up @@ -90,6 +94,15 @@ client.on("ready", async () => {
result.forEach(server => {
client.prefixes.set(server.guildID, server.prefix);
client.disabledCmds.set(server.guildID, server.lockedChannels);
if (client.mute.has(server.guildID)) {
client.mute.get(server.guildID).users.forEach(async (user) => {
if (user.time) {
let now = new Date().getTime()
const target = await (await client.guilds.fetch(server.guildID)).members.fetch(user.user)
if (user.time < now) target.roles.remove(client.mute.get(server.guildID).role)
}
})
}
});
});
console.log("Loaded guildsettings");
Expand Down Expand Up @@ -122,6 +135,8 @@ require("./utility/functions.js")(client, useDatabase);
require("./utility/embeds.js")(client);
require("./utility/time.js")(client);



client.on("messageUpdate", async (oldMessage, newMessage) => {
if (!newMessage.guild) return;
if (newMessage.author.bot) return;
Expand All @@ -134,7 +149,6 @@ client.on("messageUpdate", async (oldMessage, newMessage) => {
.split(" ");
let command = args.shift().toLowerCase();


// Permissions
let permlvl = 0;
try {
Expand Down Expand Up @@ -229,12 +243,12 @@ client.on("guildMemberUpdate", (oldMember, newMember) => {

client.on("userUpdate", (oldUser, newUser) => {
if (oldUser.avatarURL({
format: 'png',
size: 2048
}) !== newUser.avatarURL({
format: 'png',
size: 2048
}))
format: 'png',
size: 2048
}) !== newUser.avatarURL({
format: 'png',
size: 2048
}))
if (useDatabase) con.query(
`UPDATE ${table} SET profilePic = '${newUser.avatarURL({ format: 'png', size: 2048 })}' WHERE UserID = '${newUser.id}'`
);
Expand All @@ -243,12 +257,12 @@ client.on("userUpdate", (oldUser, newUser) => {
client.on("guildUpdate", (oldGuild, newGuild) => {
newGuild.name.replace(/'/g, `\\'`).replace(/"/g, `\\"`);
if (oldGuild.iconURL({
format: 'png',
size: 2048
}) !== newGuild.iconURL({
format: 'png',
size: 2048
}))
format: 'png',
size: 2048
}) !== newGuild.iconURL({
format: 'png',
size: 2048
}))
if (useDatabase) con.query(
`UPDATE ${GSTable} SET guildIcon = '${newGuild.iconURL({ format: 'png', size: 2048 })}' WHERE guildID = '${newGuild.id}'`
);
Expand All @@ -258,5 +272,6 @@ client.on("guildUpdate", (oldGuild, newGuild) => {
);
});


client.on("error", console.error);
client.login(loginToken);
2 changes: 1 addition & 1 deletion messageEvents/autoreply.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports.run = async (client, message, isTesting) => {
CreateAutoReply(message.channel, `**Volcanoids**? On **consoles**? Yes sir! But so far the main priority is adding more content before they dive into all the console shenanigans. That Rich guy will keep you updated!`, true /* Include check FAQ text. */);
}
if (steamAutoreplyRegex.exec(message.content)) {
CreateAutoReply(message.channel, `You can get Volcanoids on Steam here: https://store.steampowered.com/app/951440/Volcanoids/`, true /* Include check FAQ text. */);
CreateAutoReply(message.channel, `You can get Volcanoids on Steam here: https://store.steampowered.com/app/951440/Volcanoids?utm_source=discord&utm_medium=autoreply`, true /* Include check FAQ text. */);
}
}

Expand Down

0 comments on commit 97ca506

Please sign in to comment.