Merge pull request #7 from cheeze2000/development

added sar command
This commit is contained in:
Annihilator708 2018-05-22 12:39:48 +02:00 committed by GitHub
commit c87c34d5b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 140 additions and 3 deletions

1
.gitignore vendored
View File

@ -106,3 +106,4 @@ venv.bak/
/src/config/Config.json /src/config/Config.json
/src/config/PrivateConfig.json /src/config/PrivateConfig.json
.idea/ .idea/
.vscode/

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"python.pythonPath": "/usr/bin/python3.6"
}

View File

@ -12,8 +12,12 @@ RUN add-apt-repository ppa:deadsnakes/ppa && \
apt-get update && apt-get install python3.6 && \ apt-get update && apt-get install python3.6 && \
apt-get install python3-pip -y apt-get install python3-pip -y
RUN apt install git -y RUN apt install git -y
RUN apt install curl -y
RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - && \
apt install nodejs -y
RUN npm install discord.js
RUN python3.6 -m pip install --upgrade pip && \ RUN python3.6 -m pip install --upgrade pip && \
python3.6 -m pip install -r requirements.txt && \ python3.6 -m pip install -r requirements.txt && \
python3.6 -m pip install -U git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py[voice] python3.6 -m pip install -U git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py[voice]
cmd ["python3.6","run.py"] cmd ['bash', '-c', 'entrypoint.sh']

8
entrypoint.sh Normal file
View File

@ -0,0 +1,8 @@
#!/bin/bash
python3.6 bot.py > bot-log.txt 2>&1 &
nodejs foobar.js > node-log.txt 2>&1 &
for job in $(jobs -p); do
echo Waiting for ${job} to terminate.
wait ${job}
done

47
run.js Normal file
View 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
View File

@ -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
View 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
}

View File

@ -0,0 +1,6 @@
{
"sar": "sar",
"selfrole": "sar",
"selfroles": "sar"
}