Rebase project v0.1

This commit is contained in:
annihilator708 2018-05-22 22:35:12 +02:00
parent 5f9368e037
commit b8f5f0da0c
17 changed files with 519 additions and 631 deletions

3
.gitignore vendored
View File

@ -103,7 +103,4 @@ venv.bak/
# mypy # mypy
.mypy_cache/ .mypy_cache/
/src/config/Config.json
/src/config/PrivateConfig.json
.idea/ .idea/
.vscode/

View File

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

View File

@ -40,13 +40,24 @@ self.embed_color can be used to use the default color of out embed theme.
discord.Embed(title='Foo', description='bar', color=self.bot.embed_color) discord.Embed(title='Foo', description='bar', color=self.bot.embed_color)
``` ```
## Docker environment
This bot is heavly based on docker. This means it will run in a container. Other words. The code will run in a jail. Dont be afraid for bugs that cause harm. or commands that could potential restarts the server. Its safe.
There are a couple of things to know about docker within this project.
1. Please read the docs of docker first before editing the docker files
2. If you need a pip package, place the name into requirements.txt, docker handles the rest.
3. Everything in project folder is the workfolder of the docker container
4. Initialize cogs by adding them into cogs.txt. one line is one cogfile
## Initialize a cog ## Initialize a cog
Cogs can be placed in `./src/cogs`. Overall the `src` folder is the place to put code in. Put your cog in `src/cogs` and edit the `cogs.txt` file. Add the filename of your cog into `cogs.txt`. No absolute path, just the name.
Make sure to update the `requirements.txt` and it is important to add the name of your cog file into the `cogs.txt` list. Otherwise it may turn out that your cog wont load.
## Update source code ## Update source code
There is a git command available provided by Dusty. `S!git pull` should pull the latest commits into the docker container. Make sure afterwards to reload the cog. There is a git command available provided by Dusty. `S!git pull` should pull the latest commits into the docker container. Make sure afterwards to reload the cog.
If you are stuck in any way shape or form you can always contact anyone who works on this project. Dont forget to check `S!help`. If you are stuck in any way shape or form you can always contact anyone who works on this project. Dont forget to check `S!help`.
## Trello ## Project links:
We do make use of Trello which can be found here: https://trello.com/b/x02goBbW/sebis-bot-tutorial-roadmap - http://discord.gg/GWdhBSp
- http://chillout.ueuo.com
- http://trello.com/b/x02goBbW/sebis-bot-tutorial-roadmap

View File

@ -12,12 +12,8 @@ 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 ['bash', '-c', 'entrypoint.sh'] cmd ["python3.6","run.py"]

View File

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

47
run.js
View File

@ -1,47 +0,0 @@
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,8 +70,7 @@ 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```'
# unused variable simple_fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n**`{error}`**'
# simple_fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n**`{error}`**'
await ctx.send(fmt) await ctx.send(fmt)

View File

@ -1,67 +0,0 @@
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
}

7
src/config/Config.json Normal file
View File

@ -0,0 +1,7 @@
{
"version": 0.1,
"display_name" : "[S!] Sebi-Machine",
"maintenance": "True",
"ownerlist": [],
"prefix": "S!"
}

View File

@ -0,0 +1,3 @@
{
"bot-key": ""
}