From c357c8f8f59ba262d84a3cb734ab11f23c24abbe Mon Sep 17 00:00:00 2001 From: Nicholas Date: Thu, 24 May 2018 15:40:12 +0800 Subject: [PATCH 01/22] moved some files and fixed package.json --- .gitignore | 5 +++- package-lock.json | 59 ++++++++++++++++++++++++++++++++++++++++++ package.json | 22 ++++++++++++++++ src/cogs/sar.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++ src/run.js | 47 +++++++++++++++++++++++++++++++++ 5 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/cogs/sar.js create mode 100644 src/run.js diff --git a/.gitignore b/.gitignore index cfd538a..9b51d74 100644 --- a/.gitignore +++ b/.gitignore @@ -112,4 +112,7 @@ src/config/Config.json PrivateConfig.json # Ignore dockerfiles -docker-compose.yml \ No newline at end of file +docker-compose.yml + +.vscode/ +node_modules/ \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..95f5a1e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,59 @@ +{ + "name": "sebi-machine", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "async-limiter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", + "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" + }, + "discord.js": { + "version": "11.3.2", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-11.3.2.tgz", + "integrity": "sha512-Abw9CTMX3Jb47IeRffqx2VNSnXl/OsTdQzhvbw/JnqCyqc2imAocc7pX2HoRmgKd8CgSqsjBFBneusz/E16e6A==", + "requires": { + "long": "^4.0.0", + "prism-media": "^0.0.2", + "snekfetch": "^3.6.4", + "tweetnacl": "^1.0.0", + "ws": "^4.0.0" + } + }, + "long": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", + "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" + }, + "prism-media": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.0.2.tgz", + "integrity": "sha512-L6yc8P5NVG35ivzvfI7bcTYzqFV+K8gTfX9YaJbmIFfMXTs71RMnAupvTQPTCteGsiOy9QcNLkQyWjAafY/hCQ==" + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "snekfetch": { + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz", + "integrity": "sha512-NjxjITIj04Ffqid5lqr7XdgwM7X61c/Dns073Ly170bPQHLm6jkmelye/eglS++1nfTWktpP6Y2bFXjdPlQqdw==" + }, + "tweetnacl": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.0.tgz", + "integrity": "sha1-cT2LgY2kIGh0C/aDhtBHnmb8ins=" + }, + "ws": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz", + "integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==", + "requires": { + "async-limiter": "~1.0.0", + "safe-buffer": "~5.1.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..a286aaa --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "sebi-machine", + "version": "1.0.0", + "description": "Dedicated Discord bot for [Sebi's bot tutorial](http://discord.gg/GWdhBSp).", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/dustinpianalto/Sebi-Machine.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/dustinpianalto/Sebi-Machine/issues" + }, + "homepage": "https://github.com/dustinpianalto/Sebi-Machine#readme", + "dependencies": { + "discord.js": "^11.3.2" + } +} diff --git a/src/cogs/sar.js b/src/cogs/sar.js new file mode 100644 index 0000000..4d158cb --- /dev/null +++ b/src/cogs/sar.js @@ -0,0 +1,66 @@ +const Discord = require("discord.js"); + +exports.run = async function(client, message, args) { + + /* + aliases: sar, selfrole, selfroles + + examples: + - S!selfrole get 1 (adds heroku helper role) + - S!sar remove 3 (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. Heroku Helper", "S!sar get 2", true) + .addField("2. JS Helper", "S!sar get 3", true) + .addField("3. Rewrite Helper", "S!sar get 4", true); + + return message.channel.send({ + embed: embed + }); + + } + + const roles = [roleFinder("Heroku"), roleFinder("JS"), roleFinder("Rewrite")]; + + let choice = args[1]; // can be 1, 2 or 3 + + // if the choice is not 1, 2 or 3 + if (/^[123]$/.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 + +} \ No newline at end of file diff --git a/src/run.js b/src/run.js new file mode 100644 index 0000000..d949397 --- /dev/null +++ b/src/run.js @@ -0,0 +1,47 @@ +const Discord = require("discord.js"); +const client = new Discord.Client(); + +const config = require("./config/Config.json"); +const prefix = config.prefix; + +const aliases = require("./shared_libs/aliases.json"); +const privateConfig = require("./config/PrivateConfig.json"); + +const fs = require("fs"); +const commands = fs.readdirSync("./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(`./cogs/${command}.js`).run(client, message, args); + } + + } catch (err) { + + // handling errors + + } + +}); + +client.login(privateConfig["bot-key"]); \ No newline at end of file From d57129b33b5d8b4a7f07f5077dbdf66ab7c91b68 Mon Sep 17 00:00:00 2001 From: "Dusty.P" Date: Thu, 24 May 2018 21:20:57 -0800 Subject: [PATCH 02/22] Fixed gitignore --- .gitignore | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9b51d74..ab6f062 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +/Config.json +/PrivateConfig.json + # Byte-compiled / optimized / DLL files # Recurse @@ -108,8 +111,7 @@ venv.bak/ # mypy .mypy_cache/ -src/config/Config.json -PrivateConfig.json + # Ignore dockerfiles docker-compose.yml From 40487480803d342ec682b63a6e5e101f68401fe5 Mon Sep 17 00:00:00 2001 From: "Dusty.P" Date: Thu, 24 May 2018 21:28:08 -0800 Subject: [PATCH 03/22] deleted ignored files from repo so they are no longer tracked --- src/config/Config.json | 8 -------- src/config/PrivateConfig.json | 3 --- 2 files changed, 11 deletions(-) delete mode 100644 src/config/Config.json delete mode 100644 src/config/PrivateConfig.json diff --git a/src/config/Config.json b/src/config/Config.json deleted file mode 100644 index a301982..0000000 --- a/src/config/Config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 0.1, - "display_name" : "[ds!] Dev-Sebi", - "maintenance": "True", - "ownerlist": [387871282756190208, 275280442884751360, 351794468870946827, 140652945032216576], - "prefix": "ds!", - "dbconnect": "" -} diff --git a/src/config/PrivateConfig.json b/src/config/PrivateConfig.json deleted file mode 100644 index 9fa108b..0000000 --- a/src/config/PrivateConfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "bot-key": "" -} \ No newline at end of file From d16087139f0ee428cd2cdd006192228fe8d7d72e Mon Sep 17 00:00:00 2001 From: "Dusty.P" Date: Thu, 24 May 2018 21:31:44 -0800 Subject: [PATCH 04/22] fixed .gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ab6f062..6108169 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -/Config.json -/PrivateConfig.json +Config.json +PrivateConfig.json # Byte-compiled / optimized / DLL files From 6d03a04853014b1e30549098f7305aff9f8f9906 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Fri, 25 May 2018 13:50:26 +0800 Subject: [PATCH 05/22] added moderation and fixed sar --- src/cogs.txt | 1 + src/cogs/contributors.py | 24 ---------------------- src/cogs/moderation.py | 44 ++++++++++++++++++++++++++++++++++++++++ src/cogs/sar.js | 7 ++++--- 4 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 src/cogs/moderation.py diff --git a/src/cogs.txt b/src/cogs.txt index cbb47e8..ee91265 100644 --- a/src/cogs.txt +++ b/src/cogs.txt @@ -3,3 +3,4 @@ contributors code git fun +moderation diff --git a/src/cogs/contributors.py b/src/cogs/contributors.py index 4a888a6..bba7230 100644 --- a/src/cogs/contributors.py +++ b/src/cogs/contributors.py @@ -81,29 +81,5 @@ class Upload: else: await ctx.send(f'Loaded `{extension}`.') - @commands.command() - async def kick(self, ctx, member: discord.Member = None): - """ - Kick a discord member from your server. - Only contributors can use this command - - Usage: - - kick - - """ - await ctx.trigger_typing() - if ctx.author.id not in self.bot.ownerlist: - return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10) - - if member is None: - await ctx.send('Are you sure you are capable of this command?') - try: - await member.kick() - await ctx.send(f'You kicked **`{member.name}`** from **`{ctx.guild.name}`**') - - except Exception as e: - await ctx.send('You may not use this command you do not have permission in server:\n\n**`{ctx.guild.name}`**' - f'\n\n```py\n{e}\n```') - def setup(bot): bot.add_cog(Upload(bot)) \ No newline at end of file diff --git a/src/cogs/moderation.py b/src/cogs/moderation.py new file mode 100644 index 0000000..4a3af64 --- /dev/null +++ b/src/cogs/moderation.py @@ -0,0 +1,44 @@ +#!/usr/bin/python +# -*- coding: -*- + +from discord.ext import commands +import discord + +class Moderation: + """ + Moderation Commands + """ + def __init__(self, bot): + self.bot = bot + + @commands.command() + async def sar(self, ctx): + """Assign or remove self assigned roles""" + pass + + @commands.command() + async def kick(self, ctx, member: discord.Member = None): + """ + Kick a discord member from your server. + Only contributors can use this command + + Usage: + - kick + + """ + await ctx.trigger_typing() + if ctx.author.id not in self.bot.ownerlist: + return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10) + + if member is None: + await ctx.send('Are you sure you are capable of this command?') + try: + await member.kick() + await ctx.send(f'You kicked **`{member.name}`** from **`{ctx.guild.name}`**') + + except Exception as e: + await ctx.send('You may not use this command you do not have permission in server:\n\n**`{ctx.guild.name}`**' + f'\n\n```py\n{e}\n```') + +def setup(bot): + bot.add_cog(Moderation(bot)) diff --git a/src/cogs/sar.js b/src/cogs/sar.js index 4d158cb..6d697c1 100644 --- a/src/cogs/sar.js +++ b/src/cogs/sar.js @@ -26,7 +26,8 @@ exports.run = async function(client, message, args) { .setDescription("Usage: `S!sar [ get | remove | list ] [ number ]`") .addField("1. Heroku Helper", "S!sar get 2", true) .addField("2. JS Helper", "S!sar get 3", true) - .addField("3. Rewrite Helper", "S!sar get 4", true); + .addField("3. Rewrite Helper", "S!sar get 4", true) + .setColor("AQUA"); return message.channel.send({ embed: embed @@ -49,10 +50,12 @@ exports.run = async function(client, message, args) { case "get": message.member.addRole(roles[choice]); + message.channel.send("Added the role you specified!"); // confirmation message break; case "remove": message.member.removeRole(roles[choice]); + message.channel.send("Removed the role you specified!"); // confirmation message break; default: @@ -61,6 +64,4 @@ exports.run = async function(client, message, args) { } - message.channel.send("Added the role you wanted!"); // confirmation message - } \ No newline at end of file From 22be527f5709f299858e85a615f34a13251ec822 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Fri, 25 May 2018 14:03:52 +0800 Subject: [PATCH 06/22] fixed embed fields --- src/cogs/sar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cogs/sar.js b/src/cogs/sar.js index 6d697c1..1a5f7c7 100644 --- a/src/cogs/sar.js +++ b/src/cogs/sar.js @@ -24,9 +24,9 @@ exports.run = async function(client, message, args) { const embed = new Discord.RichEmbed() .setTitle("List of Self Assigned Roles") .setDescription("Usage: `S!sar [ get | remove | list ] [ number ]`") - .addField("1. Heroku Helper", "S!sar get 2", true) - .addField("2. JS Helper", "S!sar get 3", true) - .addField("3. Rewrite Helper", "S!sar get 4", true) + .addField("1. Heroku Helper", "S!sar get 1", true) + .addField("2. JS Helper", "S!sar get 2", true) + .addField("3. Rewrite Helper", "S!sar get 3", true) .setColor("AQUA"); return message.channel.send({ From c08dae28df10f05cf946045e2467a13f4fa8dca2 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Fri, 25 May 2018 14:06:20 +0800 Subject: [PATCH 07/22] changed encoding to utf-8 --- src/cogs/contributors.py | 2 +- src/cogs/example.py | 2 +- src/cogs/fun.py | 2 +- src/cogs/moderation.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cogs/contributors.py b/src/cogs/contributors.py index bba7230..69aca0a 100644 --- a/src/cogs/contributors.py +++ b/src/cogs/contributors.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: -*- +# -*- coding: utf-8 -*- from discord.ext import commands import discord diff --git a/src/cogs/example.py b/src/cogs/example.py index 4a73cbc..0376923 100644 --- a/src/cogs/example.py +++ b/src/cogs/example.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: -*- +# -*- coding: utf-8 -*- from discord.ext import commands import discord diff --git a/src/cogs/fun.py b/src/cogs/fun.py index d066435..ec56b83 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: -*- +# -*- coding: utf-8 -*- from discord.ext import commands import discord diff --git a/src/cogs/moderation.py b/src/cogs/moderation.py index 4a3af64..d19b8ae 100644 --- a/src/cogs/moderation.py +++ b/src/cogs/moderation.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: -*- +# -*- coding: utf-8 -*- from discord.ext import commands import discord From 2d93458b70b67d03270e82c477270ca1cc4eb621 Mon Sep 17 00:00:00 2001 From: PuffDip Date: Fri, 25 May 2018 12:41:49 +0200 Subject: [PATCH 08/22] Updated requirements --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 0927ad0..9b3af73 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ yarl<1.2 numpy==1.14.0 -uvloop +uvloop==0.9.1 +aiohttp==3.2.1 \ No newline at end of file From 92e312fec3f567d47df9e676ea1bcf816f457b4d Mon Sep 17 00:00:00 2001 From: PuffDip Date: Fri, 25 May 2018 12:47:57 +0200 Subject: [PATCH 09/22] Each hour send a request to the free hosting service for Agg --- src/__main__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/__main__.py b/src/__main__.py index 824e5ec..284eddc 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -12,6 +12,7 @@ import random import traceback import os import sys +import aiohttp import discord from discord.ext import commands @@ -63,10 +64,28 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable): cog = cog.replace('\n', '') self.load_extension(f'src.cogs.{cog}') self.logger.info(f'Loaded: {cog}') + + async def keep_website_alive(self): + """ + Agg provided us with a personal website. + This is a free host and this free host provided us with a couple of rules + we have to adjust to. One of those rules is that each month atleast one request + have to be made with this website. Rule number 10 can be found here: + https://www.freewebhostingarea.com/agreement.html. + If anyone has a better solution feel free to edit this function. + """ + # Create client session + async with aiohttp.ClientSession() as session: + # Request url + async with session.get('http://chillout.ueuo.com/') as request: + # print the response status + print(f'http://chillout.ueuo.com/ status : {request.status}') + await asyncio.sleep(3600) # sleep for one hour async def on_ready(self): """On ready function""" self.maintenance and self.logger.warning('MAINTENANCE ACTIVE') + await self.keep_website_alive() async def on_command_error(self, ctx, error): """ From c96c88d76b3ab4563fcfd305ca1807c71b6afea4 Mon Sep 17 00:00:00 2001 From: PuffDip Date: Fri, 25 May 2018 12:50:49 +0200 Subject: [PATCH 10/22] Change call for new function --- src/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__main__.py b/src/__main__.py index 284eddc..872c286 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -85,7 +85,7 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable): async def on_ready(self): """On ready function""" self.maintenance and self.logger.warning('MAINTENANCE ACTIVE') - await self.keep_website_alive() + await asyncio.get_event_loop().create_task(self.keep_website_alive()) async def on_command_error(self, ctx, error): """ From feab37f4965252888e59f6bdbe5fb3ff218bb329 Mon Sep 17 00:00:00 2001 From: PuffDip Date: Fri, 25 May 2018 13:02:35 +0200 Subject: [PATCH 11/22] Change print in debug statement --- src/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__main__.py b/src/__main__.py index 872c286..1527442 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -79,7 +79,7 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable): # Request url async with session.get('http://chillout.ueuo.com/') as request: # print the response status - print(f'http://chillout.ueuo.com/ status : {request.status}') + self.logger.debug(f'http://chillout.ueuo.com/ status : {request.status}') await asyncio.sleep(3600) # sleep for one hour async def on_ready(self): From bffce08c93e87b3dafe017266886bdc8ed5c7440 Mon Sep 17 00:00:00 2001 From: PuffDip Date: Fri, 25 May 2018 13:13:25 +0200 Subject: [PATCH 12/22] Made status check readable in terminal to check if its working --- src/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__main__.py b/src/__main__.py index 1527442..4860c8a 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -79,7 +79,7 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable): # Request url async with session.get('http://chillout.ueuo.com/') as request: # print the response status - self.logger.debug(f'http://chillout.ueuo.com/ status : {request.status}') + self.logger.info(f'http://chillout.ueuo.com/ status : {request.status}') await asyncio.sleep(3600) # sleep for one hour async def on_ready(self): From ec7cfc34271a2da0c84e17681d7f24c7d8da3e95 Mon Sep 17 00:00:00 2001 From: PuffDip Date: Fri, 25 May 2018 13:43:02 +0200 Subject: [PATCH 13/22] remove junk --- src/__main__.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index 4860c8a..d418558 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -12,7 +12,6 @@ import random import traceback import os import sys -import aiohttp import discord from discord.ext import commands @@ -65,27 +64,9 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable): self.load_extension(f'src.cogs.{cog}') self.logger.info(f'Loaded: {cog}') - async def keep_website_alive(self): - """ - Agg provided us with a personal website. - This is a free host and this free host provided us with a couple of rules - we have to adjust to. One of those rules is that each month atleast one request - have to be made with this website. Rule number 10 can be found here: - https://www.freewebhostingarea.com/agreement.html. - If anyone has a better solution feel free to edit this function. - """ - # Create client session - async with aiohttp.ClientSession() as session: - # Request url - async with session.get('http://chillout.ueuo.com/') as request: - # print the response status - self.logger.info(f'http://chillout.ueuo.com/ status : {request.status}') - await asyncio.sleep(3600) # sleep for one hour - async def on_ready(self): """On ready function""" self.maintenance and self.logger.warning('MAINTENANCE ACTIVE') - await asyncio.get_event_loop().create_task(self.keep_website_alive()) async def on_command_error(self, ctx, error): """ From 54ba203b90d89999fc0191ec4415611d2d4f7b69 Mon Sep 17 00:00:00 2001 From: Espy | Neko | 404 <34942042+neko404notfound@users.noreply.github.com> Date: Fri, 25 May 2018 20:39:43 +0100 Subject: [PATCH 14/22] Update requirements.txt (#28) --- requirements.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/requirements.txt b/requirements.txt index 9b3af73..501e963 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,10 @@ yarl<1.2 numpy==1.14.0 +aiofiles +# aiomultiprocess +# aiosqlite +# asyncpg +# dataclasses +# cached_property uvloop==0.9.1 aiohttp==3.2.1 \ No newline at end of file From 9fff91d2b58caddb17ce511e255fe08383a79a20 Mon Sep 17 00:00:00 2001 From: Nicholas Tanvis Date: Sun, 27 May 2018 10:04:34 +0800 Subject: [PATCH 15/22] fixed more stuff --- src/cogs/git.py | 2 +- src/cogs/moderation.py | 4 ++-- src/cogs/sar.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cogs/git.py b/src/cogs/git.py index 06645f6..2be5354 100644 --- a/src/cogs/git.py +++ b/src/cogs/git.py @@ -41,7 +41,7 @@ class Git(Loggable): @commands.group(case_insensitive=True, invoke_without_command=True) async def git(self, ctx): """Run help git for more info""" - await ctx.send('https://github.com/Annihilator708/Sebi-Machine/') + await ctx.send('https://github.com/dustinpianalto/Sebi-Machine/') @commands.command(case_insensitive=True, brief='Gets the Trello link.') async def trello(self, ctx): diff --git a/src/cogs/moderation.py b/src/cogs/moderation.py index d19b8ae..df0fb22 100644 --- a/src/cogs/moderation.py +++ b/src/cogs/moderation.py @@ -13,14 +13,14 @@ class Moderation: @commands.command() async def sar(self, ctx): - """Assign or remove self assigned roles""" + """Assign or remove self assigned roles.""" pass @commands.command() async def kick(self, ctx, member: discord.Member = None): """ Kick a discord member from your server. - Only contributors can use this command + Only contributors can use this command. Usage: - kick diff --git a/src/cogs/sar.js b/src/cogs/sar.js index 1a5f7c7..7cc25d4 100644 --- a/src/cogs/sar.js +++ b/src/cogs/sar.js @@ -19,7 +19,7 @@ exports.run = async function(client, message, args) { const type = args[0]; // can be get, remove or list - if (type == "list") { + if (type == "list" || type == undefined) { const embed = new Discord.RichEmbed() .setTitle("List of Self Assigned Roles") From 3772f04b5c10169f10664688bbc4cb82d1214059 Mon Sep 17 00:00:00 2001 From: davfsa Date: Sun, 27 May 2018 11:13:25 +0200 Subject: [PATCH 16/22] Added tag.py --- cogs.txt | 1 + src/cogs/tag.py | 97 +++++++++++++++++++++++++++++++++++++++++ src/resources/tags.json | 1 + 3 files changed, 99 insertions(+) create mode 100644 src/cogs/tag.py create mode 100644 src/resources/tags.json diff --git a/cogs.txt b/cogs.txt index 9529ab0..3fd3b1f 100644 --- a/cogs.txt +++ b/cogs.txt @@ -1,5 +1,6 @@ example contributors +tag code git fun \ No newline at end of file diff --git a/src/cogs/tag.py b/src/cogs/tag.py new file mode 100644 index 0000000..84c6f2a --- /dev/null +++ b/src/cogs/tag.py @@ -0,0 +1,97 @@ +import discord +from discord.ext import commands +import json +import aiofiles +import asyncio + +class Tag: + def __init__(self, bot): + self.bot = bot + with open("src/resources/tags.json", "r") as fp: + json_data = fp.read() + global tags + tags = json.loads(json_data) + + @commands.group(case_insensitive=True, invoke_without_command=True) + async def tag(self, ctx, tag=None): + """Gets a tag""" + await ctx.trigger_typing() + if tag is None: + return await ctx.send('Please provide a argument. Do `help tag` for more info') + + found = tags.get(tag, None) + + if found is None: + return await ctx.send('Tag not found') + + await ctx.send(found) + + @tag.command(case_insensitive=True) + async def list(self, ctx): + """Lists available tags""" + await ctx.trigger_typing() + desc = "" + for i in tags: + desc = desc + i + "\n" + + if desc == "": + desc = "None" + + em = discord.Embed(title='Available tags:', description=desc ,colour=discord.Colour(0x00FFFF)) + + await ctx.send(embed=em) + + @tag.command(case_insensitive=True) + async def add(self, ctx, tag_name=None, *, tag_info=None): + """Adds a new tag""" + await ctx.trigger_typing() + if not ctx.author.guild_permissions.manage_guild: + return await ctx.send("You are not allowed to do this") + + if tag_name is None or tag_info is None: + return await ctx.send("Please provide a tag name and the tag info. Do `help tag` for more info") + + exists = False + for i in tags: + if i == tag_name: + exists = True + + if not exists: + tags.update({tag_name : tag_info}) + + async with aiofiles.open("src/resources/tags.json", "w") as fp: + json_data = json.dumps(tags) + await fp.write(json_data) + + return await ctx.send("The tag has been added") + + await ctx.send("The tag already exists") + + @tag.command(case_insensitive=True) + async def remove(self, ctx, tag=None): + """Remove a existing tag""" + await ctx.trigger_typing() + if not ctx.author.guild_permissions.manage_guild: + return await ctx.send("You are not allowed to do this") + + if tag is None: + return await ctx.send("Please provide a tag name and the tag info. Do `help tag` for more info") + + found = None + for i in tags: + if i == tag: + found = i + + if found is not None: + del tags[found] + async with aiofiles.open("src/resources/tags.json", "w") as fp: + json_data = json.dumps(tags) + await fp.write(json_data) + + return await ctx.send("The tag has been removed") + + await ctx.send("The tag has not been found") + + +def setup(bot): + bot.add_cog(Tag(bot)) diff --git a/src/resources/tags.json b/src/resources/tags.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/src/resources/tags.json @@ -0,0 +1 @@ +{} \ No newline at end of file From daf320a0764178d2a98e6a48a60fd9b1b8772cde Mon Sep 17 00:00:00 2001 From: davfsa Date: Sun, 27 May 2018 11:27:24 +0200 Subject: [PATCH 17/22] Updated tag.py --- src/cogs/tag.py | 6 +++--- src/{resources => shared_libs}/tags.json | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename src/{resources => shared_libs}/tags.json (100%) diff --git a/src/cogs/tag.py b/src/cogs/tag.py index 84c6f2a..3bae890 100644 --- a/src/cogs/tag.py +++ b/src/cogs/tag.py @@ -7,7 +7,7 @@ import asyncio class Tag: def __init__(self, bot): self.bot = bot - with open("src/resources/tags.json", "r") as fp: + with open("src/shared_libs/tags.json", "r") as fp: json_data = fp.read() global tags tags = json.loads(json_data) @@ -59,7 +59,7 @@ class Tag: if not exists: tags.update({tag_name : tag_info}) - async with aiofiles.open("src/resources/tags.json", "w") as fp: + async with aiofiles.open("src/shared_libs/tags.json", "w") as fp: json_data = json.dumps(tags) await fp.write(json_data) @@ -84,7 +84,7 @@ class Tag: if found is not None: del tags[found] - async with aiofiles.open("src/resources/tags.json", "w") as fp: + async with aiofiles.open("src/shared_libs/tags.json", "w") as fp: json_data = json.dumps(tags) await fp.write(json_data) diff --git a/src/resources/tags.json b/src/shared_libs/tags.json similarity index 100% rename from src/resources/tags.json rename to src/shared_libs/tags.json From 5dfe9cbd8e1ed66a2131e3aee72c9ac50a9aee00 Mon Sep 17 00:00:00 2001 From: davfsa Date: Wed, 30 May 2018 19:15:14 +0200 Subject: [PATCH 18/22] Added permunload (#35) * Update contributors.py * Update contributors.py * Added myself as a contributor * Rename cogs.txt to extensions.txt * Update contributors.py --- src/__init__.py | 2 +- src/cogs/contributors.py | 36 +++++++++++++++++++++++++++++++- src/{cogs.txt => extensions.txt} | 0 3 files changed, 36 insertions(+), 2 deletions(-) rename src/{cogs.txt => extensions.txt} (100%) diff --git a/src/__init__.py b/src/__init__.py index dd592fd..693286b 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -6,7 +6,7 @@ Sebi-Machine. __author__ = 'Annihilator708' # TODO: add yourselves here. I can't remember everyones handles. -__contributors__ = (__author__, 'Neko404NotFound', 'Dusty.P') +__contributors__ = (__author__, 'Neko404NotFound', 'Dusty.P', 'davfsa') __license__ = 'MIT' __title__ = 'Sebi-Machine' __version__ = 'tbd' diff --git a/src/cogs/contributors.py b/src/cogs/contributors.py index 69aca0a..3e66d09 100644 --- a/src/cogs/contributors.py +++ b/src/cogs/contributors.py @@ -4,6 +4,7 @@ from discord.ext import commands import discord import traceback +import aiofiles class Upload: """ @@ -80,6 +81,39 @@ class Upload: await ctx.send(f'Could not unload `{extension}` -> `{e}`') else: await ctx.send(f'Loaded `{extension}`.') + + @commands.command() + async def permunload(self, ctx, extension=None): + """Disables permanently a cog.""" + await ctx.trigger_typing() + if ctx.author.id not in self.bot.ownerlist: + return await ctx.send('Only my contributors can use me like this :blush:', delete_after=10) + + if cog is None: + return await ctx.send("Please provide a extension. Do `help permunload` for more info") + + extension = extension.lower() + + async with aiofiles.open("extension.txt") as fp: + lines=fp.readlines() + + removed = False + async with aiofiles.open("extension.txt", "w") as fp: + for i in lines: + if i.replace("\n", "") != extension: + fp.write(i) + else: + removed = True + break + + if removed is True: + try: + self.bot.unload_extension(extension) + except: + pass + return await ctx.send("Extension removed successfully") + + await ctx.send("Extension not found") def setup(bot): - bot.add_cog(Upload(bot)) \ No newline at end of file + bot.add_cog(Upload(bot)) diff --git a/src/cogs.txt b/src/extensions.txt similarity index 100% rename from src/cogs.txt rename to src/extensions.txt From bbb1dd3e0d869f2a0e5b4eaa4095a5cce02f581b Mon Sep 17 00:00:00 2001 From: davfsa Date: Wed, 30 May 2018 19:28:57 +0200 Subject: [PATCH 19/22] Fixed __main__.py --- src/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__main__.py b/src/__main__.py index d418558..a883bd2 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -55,7 +55,7 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable): # Load plugins # Add your cog file name in this list - with open(in_here('cogs.txt')) as cog_file: + with open(in_here('extensions.txt')) as cog_file: cogs = cog_file.readlines() for cog in cogs: From a38c24b618944d138aaa61f413ca52cb7552ecba Mon Sep 17 00:00:00 2001 From: YashKandalkar Date: Wed, 6 Jun 2018 21:07:25 +0530 Subject: [PATCH 20/22] Commiting to development branch, added 'start' command --- src/cogs/BasicCommands.py | 44 +++++++++++++++++++++++++++++++++++++++ src/extensions.txt | 1 + 2 files changed, 45 insertions(+) create mode 100644 src/cogs/BasicCommands.py diff --git a/src/cogs/BasicCommands.py b/src/cogs/BasicCommands.py new file mode 100644 index 0000000..bcb27d0 --- /dev/null +++ b/src/cogs/BasicCommands.py @@ -0,0 +1,44 @@ +#!/usr/bin/python +# -*- coding: -*- + +from discord.ext import commands +import discord + +class BasicCommands: + def __init__(self, bot): + self.bot = bot + + @commands.command() + async def start(self, ctx): + await ctx.send(f"Hello, {ctx.author.display_name}. Welcome to Sebi's Bot Tutorials. \nFirst off, would you like a quick walkthrough on the server channels?") + + #We can edit this later if the name of any channel changes. + channel_list = {'channel-1' : "#making-the-bot", + 'd.py-rewrite-start' : "#introduction-rw", + 'js-klasa-start' : "#introduction-js", + 'd.js' : "#introduction-discordjs"} + bots_channels = ("#bot-spam", "#bot-testing") + help_channels = ("#py-help", "#js-help", "#other-help") + + def check(m): + return True if m.author.id == ctx.author.id else False + + msg = await self.bot.wait_for('message', check = check, timeout = 15) + agree = ("yes", "yep", "yesn't", "ya") + + if msg is None: + await ctx.send("Sorry, {ctx.author.mention}, you didn't reply on time. You can run the command again when you're free :)") + else: + if msg.content.lower() in agree: + async with ctx.typing(): + await ctx.send("Alrighty-Roo...") + await ctx.send(f"To start making your bot from scratch, you first need to head over to {channel_list['channel-1']} (Regardless of the language you're gonna use.") + await ctx.send(f"After you have a bot account, you can either continue with {channel_list['d.py-rewrite-start']} if you want to make a bot in discord.py rewrite __or__ go to {channel_list['js-klasa-start']} or {channel_list['d.js']} for making a bot in JavaScript") + await ctx.send("...Read all the tutorials and still need help? You have two ways to get help.") + await ctx.send(f"**Method-1**\nThis is the best method of getting help. You help yourself.\nTo do so, head over to a bots dedicated channel (either {bots_channels[0]} or {bots_channels[1]}) and type `?rtfm rewrite thing_you_want_help_with`.\nThis will trigger the bot R.Danny Bot and will give you links on your query on the official discord.py rewrite docs. *PS: Let the page completely load*") + await ctx.send(f"**Method-2**\nIf you haven't found anything useful with Method-1, feel free to ask your question in any of the related help channels. ({', '.join(help_channels)})\nMay the force be with you!!") + else: + return await ctx.send("Session terminated. You can run this command again whenever you want.") + +def setup(bot): + bot.add_cog(BasicCommands(bot)) \ No newline at end of file diff --git a/src/extensions.txt b/src/extensions.txt index 4945aed..a47049f 100644 --- a/src/extensions.txt +++ b/src/extensions.txt @@ -5,3 +5,4 @@ code git fun moderation +BasicCommands From d2a93aaf2f524b04b6a77518434c6218f3d71ab8 Mon Sep 17 00:00:00 2001 From: "YashKandalkaril.com" Date: Thu, 7 Jun 2018 18:32:01 +0530 Subject: [PATCH 21/22] Changed channel names to channel IDs and added multiline strings --- src/cogs/BasicCommands.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/cogs/BasicCommands.py b/src/cogs/BasicCommands.py index bcb27d0..b69c5c5 100644 --- a/src/cogs/BasicCommands.py +++ b/src/cogs/BasicCommands.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: -*- +# -*- coding: utf-8 -*- from discord.ext import commands import discord @@ -12,18 +12,23 @@ class BasicCommands: async def start(self, ctx): await ctx.send(f"Hello, {ctx.author.display_name}. Welcome to Sebi's Bot Tutorials. \nFirst off, would you like a quick walkthrough on the server channels?") - #We can edit this later if the name of any channel changes. - channel_list = {'channel-1' : "#making-the-bot", - 'd.py-rewrite-start' : "#introduction-rw", - 'js-klasa-start' : "#introduction-js", - 'd.js' : "#introduction-discordjs"} - bots_channels = ("#bot-spam", "#bot-testing") - help_channels = ("#py-help", "#js-help", "#other-help") + channel_list = {'channel-1' : self.bot.get_channel(333149949883842561).mention, + 'd.py-rewrite-start' : self.bot.get_channel(386419285439938560).mention, + 'js-klasa-start' : self.bot.get_channel(341816240186064897).mention, + 'd.js' : self.bot.get_channel(436771798303113217).mention} + + bots_channels = (self.bot.get_channel(339112602867204097).mention, + self.bot.get_channel(411586546551095296).mention) + + help_channels = (self.bot.get_channel(425315253153300488).mention, + self.bot.get_channel(392215236612194305).mention, + self.bot.get_channel(351034776985141250).mention) def check(m): - return True if m.author.id == ctx.author.id else False + return True if m.author.id == ctx.author.id and m.channel.id == ctx.channel.id else False msg = await self.bot.wait_for('message', check = check, timeout = 15) + agree = ("yes", "yep", "yesn't", "ya") if msg is None: @@ -32,11 +37,18 @@ class BasicCommands: if msg.content.lower() in agree: async with ctx.typing(): await ctx.send("Alrighty-Roo...") - await ctx.send(f"To start making your bot from scratch, you first need to head over to {channel_list['channel-1']} (Regardless of the language you're gonna use.") - await ctx.send(f"After you have a bot account, you can either continue with {channel_list['d.py-rewrite-start']} if you want to make a bot in discord.py rewrite __or__ go to {channel_list['js-klasa-start']} or {channel_list['d.js']} for making a bot in JavaScript") + await ctx.send(f"""To start making your bot from scratch, you first need to head over to {channel_list['channel-1']} + (Regardless of the language you're gonna use).""") + await ctx.send(f"""After you have a bot account, you can either continue with {channel_list['d.py-rewrite-start']} + if you want to make a bot in discord.py rewrite __or__ go to {channel_list['js-klasa-start']} or + {channel_list['d.js']} for making a bot in JavaScript""") await ctx.send("...Read all the tutorials and still need help? You have two ways to get help.") - await ctx.send(f"**Method-1**\nThis is the best method of getting help. You help yourself.\nTo do so, head over to a bots dedicated channel (either {bots_channels[0]} or {bots_channels[1]}) and type `?rtfm rewrite thing_you_want_help_with`.\nThis will trigger the bot R.Danny Bot and will give you links on your query on the official discord.py rewrite docs. *PS: Let the page completely load*") - await ctx.send(f"**Method-2**\nIf you haven't found anything useful with Method-1, feel free to ask your question in any of the related help channels. ({', '.join(help_channels)})\nMay the force be with you!!") + await ctx.send(f"""**Method-1**\nThis is the best method of getting help. You help yourself.\n + To do so, head over to a bots dedicated channel (either {bots_channels[0]} or {bots_channels[1]}) + and type `?rtfm rewrite thing_you_want_help_with`.\nThis will trigger the bot R.Danny Bot and will + give you links on your query on the official discord.py rewrite docs. *PS: Let the page completely load*""") + await ctx.send(f"""**Method-2**\nIf you haven't found anything useful with Method-1, feel free to ask your question + in any of the related help channels. ({', '.join(help_channels)})\nMay the force be with you!!""") else: return await ctx.send("Session terminated. You can run this command again whenever you want.") From d8e8984af8c72ca2672d3b94e7ff23a957211a62 Mon Sep 17 00:00:00 2001 From: "YashKandalkaril.com" Date: Thu, 7 Jun 2018 18:39:32 +0530 Subject: [PATCH 22/22] added my name in __init__.py --- src/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__init__.py b/src/__init__.py index 693286b..e751564 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -6,7 +6,7 @@ Sebi-Machine. __author__ = 'Annihilator708' # TODO: add yourselves here. I can't remember everyones handles. -__contributors__ = (__author__, 'Neko404NotFound', 'Dusty.P', 'davfsa') +__contributors__ = (__author__, 'Neko404NotFound', 'Dusty.P', 'davfsa', 'YashKandalkar') __license__ = 'MIT' __title__ = 'Sebi-Machine' __version__ = 'tbd'