added djs command for sar
This commit is contained in:
parent
582beb2a42
commit
7f60b136d4
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.pythonPath": "/usr/bin/python3.6"
|
||||||
|
}
|
||||||
47
run.js
Normal file
47
run.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
const Discord = require("discord.js");
|
||||||
|
const client = new Discord.Client();
|
||||||
|
|
||||||
|
const config = require("./src/config/Config.json");
|
||||||
|
const prefix = config.prefix;
|
||||||
|
|
||||||
|
const aliases = require("./src/shared_libs/aliases.json");
|
||||||
|
const privateConfig = require("./src/config/PrivateConfig.json");
|
||||||
|
|
||||||
|
const fs = require("fs");
|
||||||
|
const commands = fs.readdirSync("./src/cogs").filter(function(e) {
|
||||||
|
return e.endsWith(".js");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
client.on("message", function(message) {
|
||||||
|
|
||||||
|
if (message.guild.id != "265828729970753537") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.content.startsWith(config.prefix) == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const msg = message.content.replace(prefix, "");
|
||||||
|
|
||||||
|
let command = msg.split(" ")[0];
|
||||||
|
const args = msg.split(" ").slice(1);
|
||||||
|
|
||||||
|
command = aliases[command];
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (commands.includes(`${command}.js`)) {
|
||||||
|
require(`./src/cogs/${command}.js`).run(client, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
|
||||||
|
// handling errors
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
client.login(privateConfig["bot-key"]);
|
||||||
3
run.py
3
run.py
@ -70,7 +70,8 @@ class SebiMachine(commands.Bot, LoadConfig):
|
|||||||
tb = ''.join(tb)
|
tb = ''.join(tb)
|
||||||
joke = random.choice(jokes)
|
joke = random.choice(jokes)
|
||||||
fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n```py\n{tb}\n```'
|
fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n```py\n{tb}\n```'
|
||||||
simple_fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n**`{error}`**'
|
# unused variable
|
||||||
|
# simple_fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n**`{error}`**'
|
||||||
await ctx.send(fmt)
|
await ctx.send(fmt)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
67
src/cogs/sar.js
Normal file
67
src/cogs/sar.js
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
const Discord = require("discord.js");
|
||||||
|
|
||||||
|
exports.run = async function(client, message, args) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
aliases: sar, selfrole, selfroles
|
||||||
|
|
||||||
|
examples:
|
||||||
|
- S!selfrole get 1 (adds async helper role)
|
||||||
|
- S!sar remove 4 (removes rewrite helper role)
|
||||||
|
- S!sar list (shows all roles)
|
||||||
|
*/
|
||||||
|
|
||||||
|
function roleFinder(query) {
|
||||||
|
return message.guild.roles.find(function(r) {
|
||||||
|
return r.name.includes(query)
|
||||||
|
}).id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const type = args[0]; // can be get, remove or list
|
||||||
|
|
||||||
|
if (type == "list") {
|
||||||
|
|
||||||
|
const embed = new Discord.RichEmbed()
|
||||||
|
.setTitle("List of Self Assigned Roles")
|
||||||
|
.setDescription("Usage: `S!sar [ get | remove | list ] [ number ]`")
|
||||||
|
.addField("1. Async Helper", "S!sar get 1", true)
|
||||||
|
.addField("2. Heroku Helper", "S!sar get 2", true)
|
||||||
|
.addField("3. JS Helper", "S!sar get 3", true)
|
||||||
|
.addField("4. Rewrite Helper", "S!sar get 4", true);
|
||||||
|
|
||||||
|
return message.channel.send({
|
||||||
|
embed: embed
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const roles = [roleFinder("Async"), roleFinder("Heroku"), roleFinder("JS"), roleFinder("Rewrite")];
|
||||||
|
|
||||||
|
let choice = args[1]; // can be 1, 2, 3 or 4
|
||||||
|
|
||||||
|
// if the choice is not 1, 2, 3 or 4
|
||||||
|
if (/^[1234]$/.test(choice) == false) {
|
||||||
|
return message.channel.send("Enter a valid role number!"); // returns error message
|
||||||
|
} else {
|
||||||
|
choice -= 1; // because array indexing starts from 0. when they choose 1 it should be roles[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
|
||||||
|
case "get":
|
||||||
|
message.member.addRole(roles[choice]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "remove":
|
||||||
|
message.member.removeRole(roles[choice]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return; // when it is neither get nor remove
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message.channel.send("Added the role you wanted!"); // confirmation message
|
||||||
|
|
||||||
|
}
|
||||||
6
src/shared_libs/aliases.json
Normal file
6
src/shared_libs/aliases.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"sar": "sar",
|
||||||
|
"selfrole": "sar",
|
||||||
|
"selfroles": "sar"
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user