From f6c4a5a570a2a382e80c2ae5dfe5d7f7ef300834 Mon Sep 17 00:00:00 2001 From: nya~ <40436815+neko404notfound@users.noreply.github.com> Date: Thu, 21 Jun 2018 09:20:10 +0100 Subject: [PATCH] Update (#1) * Update sebi_machine_launcher.sh * Update sebi_machine_launcher.sh * Update requirements.txt * removed numpy import * Fixed a stupid typo. * Fixed broken import someone didn't check. * Updated bot_management.py * Updated bot_management.py * Update bot_management.py * Update bot_management.py * Update bot_management.py * Added ban command And changed the response because if you were talking without commas you would need to breathe heavily and and and and *huff* * Update bot_management.py * Aaa wrong word lmao * Update bot_management.py --- requirements.txt | 1 - sebi_machine_launcher.sh | 4 ++ src/cogs/bot_management.py | 84 ++++++++------------------------------ src/cogs/moderation.py | 25 +++++++++++- src/cogs/music.py | 2 +- src/shared_libs/utils.py | 1 - 6 files changed, 45 insertions(+), 72 deletions(-) diff --git a/requirements.txt b/requirements.txt index 18d6d6f..0b2f1e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ yarl<1.2 -numpy==1.14.0 aiofiles # aiomultiprocess # aiosqlite diff --git a/sebi_machine_launcher.sh b/sebi_machine_launcher.sh index 423d874..ceb3395 100644 --- a/sebi_machine_launcher.sh +++ b/sebi_machine_launcher.sh @@ -5,6 +5,10 @@ # the interrupt signal. This is really annoying over SSH when I have # a 1-second lag anyway. trap "echo 'Received interrupt. Exiting.'; exit 0" SIGINT + +# Also loads the venv if it is present. +[ -d .venv/bin ] && source .venv/bin/activate && echo "Entered venv." || echo "No venv detected." + until python -m src; do # Added colouring to ensure the date of shutdown and the exit code stands # out from the other clutter in the traceback that might have been output. diff --git a/src/cogs/bot_management.py b/src/cogs/bot_management.py index 2eab39c..5e168ec 100644 --- a/src/cogs/bot_management.py +++ b/src/cogs/bot_management.py @@ -12,14 +12,24 @@ class BotManager: return else: # The member is a bot - # Add role testing bot - await member.add_roles(discord.utils.get(member.guild.roles, name='Bot to test')) - await self.bot.db_con.fetch('select prefix from bots where id = $1', member.id) - await member.nick('[' + await self.bot.db_con.fetch('select prefix from bots where id = $1', member.id) - + ']' + member.name) + await member.add_roles(discord.utils.get(member.guild.roles, name='Bots')) + try: + await member.edit(nick='[' + await self.bot.db_con.fetch('select prefix from bots where id = $1', member.id) + + '] ' + member.name) + except: + pass + + async def on_member_remove(self, member): + # If the member is not a bot + if member.bot is False: + return + else: + # The member is a bot + await self.bot.db_con.execute('DELETE FROM bots WHERE id = $1', member.id) @commands.command() - async def invite(self, ctx, bot: discord.User=None, prefix=None): + async def invite(self, ctx, bot=None, prefix=None): + bot = await ctx.bot.get_user_info(bot) if not bot: raise Warning('You must include the id of the bot you are trying to invite... Be exact.') if not bot.bot: @@ -42,7 +52,6 @@ class BotManager: await ctx.send(embed=em) em = discord.Embed(title="Bot invite", colour=discord.Color(0x363941)) - em.description = "To start to test the bot, use `ds!start ` and to finish testing it use `ds!finish`" em.set_thumbnail(url=bot.avatar_url) em.add_field(name="Bot name", value=bot.name) em.add_field(name="Bot id", value="`" + str(bot.id) + "`") @@ -50,67 +59,6 @@ class BotManager: em.add_field(name="Bot prefix", value="`" + prefix + "`") await ctx.bot.get_channel(448803675574370304).send(embed=em) - @commands.command() - async def start(self, ctx, bot: discord.Member = None): - if not ctx.author.guild_permissions.manage_roles: - raise Warning('You are not allowed to execute this command') - if not bot: - raise Warning('You must include the id of the bot you are going to test... Be exact.') - - if await self.bot.db_con.fetchrow('select * from bots where id = $1', bot.id): - if discord.utils.get(ctx.guild.roles, name='Bot to test') in bot.roles: - raise Warning('The bot is already being tested') - - await bot.remove_roles(discord.utils.get(ctx.guild.roles, name='Bot to test')) - await bot.add_roles(discord.utils.get(ctx.guild.roles, name='Bot testing')) - - user = await self.bot.db_con.fetch('select owner from bots where id = $1', bot.id) - await ctx.get_user(user).send('Your bot is being tested by ' + str(ctx.author)) - await ctx.send('The owner has been warned') - else: - raise Warning('The bot id that you provided could not be found on the database') - - @commands.group() - async def finish(self, ctx): - if ctx.invoked_subcommand is not None: - await ctx.send("Do `ds!help finish` for more info") - - @finish.command() - async def approve(self, ctx, bot: discord.Member = None): - if not ctx.author.guild_permissions.manage_roles: - raise Warning('You are not allowed to execute this command') - if not bot: - raise Warning('You must include the id of the bot you have finished testing... Be exact.') - - if await self.bot.db_con.fetchrow('select * from bots where id = $1', bot.id): - user = await self.bot.db_con.fetch('select owner from bots where id = $1', bot.id) - - await bot.remove_roles(discord.utils.get(ctx.guild.roles, name='Bot testing')) - await bot.add_roles(discord.utils.get(ctx.guild.roles, name='Bot')) - - await ctx.get_user(user).send('Your bot has been tested by ' + str(ctx.author) + '\n**Result:** Approved') - await ctx.send('The owner has been warned') - else: - raise Warning('The bot id that you provided could not be found on the database') - - @finish.command() - async def decline(self, ctx, bot: discord.Member = None, reason=None): - if not ctx.author.guild_permissions.manage_roles: - raise Warning('You are not allowed to execute this command') - if not bot: - raise Warning('You must include the id of the bot you have finished testing... Be exact.') - if not reason: - raise Warning('You must include the reason for declining the bot... Be exact.') - - if await self.bot.db_con.fetchrow('select * from bots where id = $1', bot.id): - user = await self.bot.db_con.fetch('select owner from bots where id = $1', bot.id) - await bot.kick() - await ctx.get_user(user).send('Your bot has been tested by ' + str(ctx.author) + - '\n**Result:** Declined\n**Reason:** ' + reason) - await ctx.send('The owner has been warned') - else: - raise Warning('The bot id that you provided could not be found on the database') - @commands.command(name='claim', aliases=['makemine', 'gimme']) @commands.cooldown(1, 5, commands.BucketType.user) async def _claim_bot(self, ctx, bot: discord.Member = None, prefix: str = None, owner: discord.Member = None): diff --git a/src/cogs/moderation.py b/src/cogs/moderation.py index 8032a35..ee7e773 100644 --- a/src/cogs/moderation.py +++ b/src/cogs/moderation.py @@ -32,7 +32,30 @@ class Moderation: 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}`**' + await ctx.send('You may not use this command, as you do not have permission to do so:\n\n**`{ctx.guild.name}`**' + f'\n\n```py\n{e}\n```') + @commands.command() + async def ban(self, ctx, member: discord.Member = None): + """ + Ban a discord member from your server. + Only contributors can use this command. + + Usage: + - ban + + """ + 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.ban() + await ctx.send(f'You banned **`{member.name}`** from **`{ctx.guild.name}`**') + + except Exception as e: + await ctx.send('You may not use this command, as you do not have permission to do so:\n\n**`{ctx.guild.name}`**' f'\n\n```py\n{e}\n```') def setup(bot): diff --git a/src/cogs/music.py b/src/cogs/music.py index 9a2f546..54eb3a9 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -11,7 +11,7 @@ from discord.ext import commands import youtube_dl # noinspection PyUnresolvedReferences,PyUnresolvedReferences,PyPackageRequirements -from utils import noblock +from . utils import noblock YT_DL_OPTS = { diff --git a/src/shared_libs/utils.py b/src/shared_libs/utils.py index 9ba5998..fbd2827 100644 --- a/src/shared_libs/utils.py +++ b/src/shared_libs/utils.py @@ -32,7 +32,6 @@ import sys import asyncio import discord from discord.ext.commands.formatter import Paginator -import numpy as np class Capturing(list):