Refactor to conform to PEP 8 styling
This commit is contained in:
+20
-9
@@ -1,50 +1,60 @@
|
||||
import discord, json, asyncio
|
||||
import discord
|
||||
import json
|
||||
from . import utils
|
||||
|
||||
owner_id = 351794468870946827
|
||||
|
||||
|
||||
|
||||
def check_admin_role(bot, ctx, member):
|
||||
admin_roles = json.loads(bot.con.one(f"select admin_roles from guild_config where guild_id = {ctx.guild.id}"))
|
||||
admin_roles = json.loads(bot.con.one(f"select admin_roles from guild_config where guild_id = %(id)s",
|
||||
{'id': ctx.guild.id}))
|
||||
for role in admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=admin_roles[role]) in member.roles:
|
||||
return True
|
||||
return member.id == ctx.guild.owner.id or member.id == owner_id
|
||||
|
||||
|
||||
def check_rcon_role(bot, ctx, member):
|
||||
rcon_admin_roles = json.loads(bot.con.one(f"select rcon_admin_roles from guild_config where guild_id = {ctx.guild.id}"))
|
||||
rcon_admin_roles = json.loads(bot.con.one("select rcon_admin_roles from guild_config where guild_id = %(id)s",
|
||||
{'id': ctx.guild.id}))
|
||||
for role in rcon_admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=rcon_admin_roles[role]) in member.roles:
|
||||
return True
|
||||
return member.id == ctx.guild.owner.id or member.id == owner_id
|
||||
|
||||
|
||||
def is_admin(bot, ctx):
|
||||
admin_roles = json.loads(bot.con.one(f"select admin_roles from guild_config where guild_id = {ctx.guild.id}"))
|
||||
admin_roles = json.loads(bot.con.one("select admin_roles from guild_config where guild_id = %(id)s",
|
||||
{'id': ctx.guild.id}))
|
||||
for role in admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=admin_roles[role]) in ctx.message.author.roles:
|
||||
return True
|
||||
return ctx.message.author.id == ctx.guild.owner.id or ctx.message.author.id == owner_id
|
||||
|
||||
|
||||
def is_guild_owner(ctx):
|
||||
if ctx.guild:
|
||||
return ctx.message.author.id == ctx.guild.owner.id or ctx.message.author.id == owner_id
|
||||
return False
|
||||
|
||||
|
||||
def is_rcon_admin(bot, ctx):
|
||||
rcon_admin_roles = json.loads(bot.con.one(f"select rcon_admin_roles from guild_config where guild_id = {ctx.guild.id}"))
|
||||
rcon_admin_roles = json.loads(bot.con.one("select rcon_admin_roles from guild_config where guild_id = %(id)s",
|
||||
{'id': ctx.guild.id}))
|
||||
for role in rcon_admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=rcon_admin_roles[role]) in ctx.message.author.roles:
|
||||
return True
|
||||
return ctx.message.author.id == ctx.guild.owner.id or ctx.message.author.id == owner_id
|
||||
|
||||
|
||||
def is_restricted_chan(ctx):
|
||||
if ctx.guild:
|
||||
if ctx.channel.overwrites_for(ctx.guild.default_role).read_messages == False:
|
||||
if ctx.channel.overwrites_for(ctx.guild.default_role).read_messages is False:
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
async def is_spam(bot, ctx):
|
||||
max_rep = 5
|
||||
rep_time = 20
|
||||
@@ -56,9 +66,10 @@ async def is_spam(bot, ctx):
|
||||
if msg['author'] == ctx.author:
|
||||
if msg['time'] > ctx.message.created_at.timestamp() - spam_time:
|
||||
spam_check += 1
|
||||
if msg['content'].lower() == ctx.content.lower() and msg['time'] > ctx.message.created_at.timestamp() - rep_time:
|
||||
if msg['content'].lower() == ctx.content.lower() \
|
||||
and msg['time'] > ctx.message.created_at.timestamp() - rep_time:
|
||||
msg_check += 1
|
||||
if spam_check == spam_rep - 1 or msg_check == max_rep - 1:
|
||||
await utils.mute(bot, ctx, admin=1, member=ctx.author.id)
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
|
||||
+14
-8
@@ -1,5 +1,7 @@
|
||||
from io import StringIO
|
||||
import sys, asyncio
|
||||
import sys
|
||||
import asyncio
|
||||
import discord
|
||||
from discord.ext.commands.formatter import Paginator
|
||||
from . import checks
|
||||
|
||||
@@ -9,20 +11,23 @@ class Capturing(list):
|
||||
self._stdout = sys.stdout
|
||||
sys.stdout = self._stringio = StringIO()
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.extend(self._stringio.getvalue().splitlines())
|
||||
del self._stringio # free up some memory
|
||||
sys.stdout = self._stdout
|
||||
|
||||
|
||||
async def mute(bot, ctx, admin=0, member_id=None):
|
||||
mute_role = self.bot.con.one(f'select muted_role from guild_config where guild_id = {ctx.guild.id}')
|
||||
if muted_role:
|
||||
mute_role = bot.con.one(f'select muted_role from guild_config where guild_id = {ctx.guild.id}')
|
||||
if mute_role:
|
||||
if admin or checks.is_admin(bot, ctx):
|
||||
if ctx.guild.me.guild_permissions.manage_roles:
|
||||
if member:
|
||||
if member_id:
|
||||
ctx.guild.get_member(member_id).edit(roles=[discord.utils.get(ctx.guild.roles, id=mute_role)])
|
||||
|
||||
def to_list_of_str(items, out:list=[], level=1, recurse=0):
|
||||
|
||||
def to_list_of_str(items, out: list=list(), level=1, recurse=0):
|
||||
def rec_loop(item, key, out, level):
|
||||
quote = '"'
|
||||
if type(item) == list:
|
||||
@@ -40,7 +45,7 @@ def to_list_of_str(items, out:list=[], level=1, recurse=0):
|
||||
|
||||
if type(items) == list:
|
||||
if not recurse:
|
||||
out = []
|
||||
out = list()
|
||||
out.append('[')
|
||||
for item in items:
|
||||
rec_loop(item, None, out, level)
|
||||
@@ -48,7 +53,7 @@ def to_list_of_str(items, out:list=[], level=1, recurse=0):
|
||||
out.append(']')
|
||||
elif type(items) == dict:
|
||||
if not recurse:
|
||||
out = []
|
||||
out = list()
|
||||
out.append('{')
|
||||
for key in items:
|
||||
rec_loop(items[key], key, out, level)
|
||||
@@ -57,8 +62,8 @@ def to_list_of_str(items, out:list=[], level=1, recurse=0):
|
||||
|
||||
return out
|
||||
|
||||
|
||||
def paginate(text, maxlen=1990):
|
||||
data = []
|
||||
paginator = Paginator(prefix='```py', max_size=maxlen+10)
|
||||
if type(text) == list:
|
||||
data = to_list_of_str(text)
|
||||
@@ -75,6 +80,7 @@ def paginate(text, maxlen=1990):
|
||||
paginator.add_line(line)
|
||||
return paginator.pages
|
||||
|
||||
|
||||
async def run_command(args):
|
||||
# Create subprocess
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
|
||||
Reference in New Issue
Block a user