Compare commits

..

No commits in common. "946590a3a14461ff73fee015feb183a1d3361f14" and "1ddf76707456e92c3693a7a577b167bd9d266563" have entirely different histories.

4 changed files with 34 additions and 32 deletions

View File

@ -26,8 +26,6 @@ from .shared_libs.loggable import Loggable
# Init logging to output on INFO level to stderr.
logging.basicConfig(level="INFO")
REBOOT_FILE = "sebimachine/config/reboot"
# If uvloop is installed, change to that eventloop policy as it
# is more efficient
@ -77,31 +75,32 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable):
# Load plugins
# Add your cog file name in this list
with open(in_here("extensions.txt")) as cog_file:
cogs = {f'sebimachine.cogs.{c.strip()}' for c in cog_file.readlines()}
cogs = cog_file.readlines()
for cog in cogs:
# Could this just be replaced with `strip()`?
try:
self.load_extension(cog)
cog = cog.replace("\n", "")
self.load_extension(f"src.cogs.{cog}")
self.logger.info(f"Loaded: {cog}")
except (ModuleNotFoundError, ImportError) as ex:
logging.exception(f'Could not load {cog}', exc_info=(type(ex), ex, ex.__traceback__))
self.failed_cogs_on_startup[cog] = ex
async def on_ready(self):
async def on_ready(self):
"""On ready function"""
self.maintenance and self.logger.warning("MAINTENANCE ACTIVE")
if os.path.exists(REBOOT_FILE):
with open(REBOOT_FILE, "r") as f:
reboot = f.readlines()
if int(reboot[0]) == 1:
await self.get_channel(int(reboot[1])).send("Restart Finished.")
for cog, ex in self.failed_cogs_on_startup.items():
tb = ''.join(traceback.format_exception(type(ex), ex, ex.__traceback__))[-1500:]
await ctx.send(
f'FAILED TO LOAD {cog} BECAUSE OF {type(ex).__name__}: {ex}\n'
f'{tb}'
)
with open(REBOOT_FILE, "w") as f:
with open(f"src/config/reboot", "r") as f:
reboot = f.readlines()
if int(reboot[0]) == 1:
await self.get_channel(int(reboot[1])).send("Restart Finished.")
for cog, ex in self.failed_cogs_on_startup.items():
tb = ''.join(traceback.format_exception(type(ex), ex, ex.__traceback__))[-1500:]
await ctx.send(
f'FAILED TO LOAD {cog} BECAUSE OF {type(ex).__name__}: {ex}\n'
f'{tb}'
)
with open(f"src/config/reboot", "w") as f:
f.write(f"0")
async def on_command_error(self, ctx, error):

View File

@ -11,9 +11,9 @@ class BotManager:
return
else:
# The member is a bot
bot_owner = member.guild.get_member(await self.bot.db_con.fetchval('select owner from bots where id = $1', member.id))
bot_owner = member.guild.get_member((await self.bot.db_con.fetchval('select owner from bots where id = $1', member.id))
await bot_owner.add_roles(discord.utils.get(member.guild.roles, name='Bot Developers'))
await member.add_roles(discord.utils.get(member.guild.roles, name='Bots'))
try:
await member.edit(nick='[' + await self.bot.db_con.fetchval('select prefix from bots where id = $1', member.id)
@ -61,7 +61,7 @@ class BotManager:
await ctx.send(embed=em)
em = discord.Embed(title="Bot invite", colour=discord.Color(0x363941))
em.description = discord.utils.oauth_url(client_id, permissions=None, guild=ctx.guild)
em.description = discord.utils.oauth_url(client_id, permissions=None, guild=ctx.guild))
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) + "`")

View File

@ -8,7 +8,7 @@ import asyncio
class Tag:
def __init__(self, bot):
self.bot = bot
with open("sebimachine/shared_libs/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)

View File

@ -156,11 +156,11 @@ class Capturing(list):
def __exit__(self, *args):
self.extend(self._stringio.getvalue().splitlines())
del self._stringio # free up some memory
del self._stringio # free up some memory
sys.stdout = self._stdout
def to_list_of_str(items, out: list=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:
@ -174,40 +174,42 @@ def to_list_of_str(items, out: list=list(), level=1, recurse=0):
out = to_list_of_str(item, out, new_level, 1)
out.append(f'{" "*level}}}')
else:
out.append(f'{" "*level}{quote+key+quote+": " if key else ""}{repr(item)},')
out.append(
f'{" "*level}{quote+key+quote+": " if key else ""}{repr(item)},'
)
if type(items) == list:
if not recurse:
out = list()
out.append('[')
out.append("[")
for item in items:
rec_loop(item, None, out, level)
if not recurse:
out.append(']')
out.append("]")
elif type(items) == dict:
if not recurse:
out = list()
out.append('{')
out.append("{")
for key in items:
rec_loop(items[key], key, out, level)
if not recurse:
out.append('}')
out.append("}")
return out
def paginate(text, maxlen=1990):
paginator = Paginator(prefix='```py', max_size=maxlen+10)
paginator = Paginator(prefix="```py", max_size=maxlen + 10)
if type(text) == list:
data = to_list_of_str(text)
elif type(text) == dict:
data = to_list_of_str(text)
else:
data = str(text).split('\n')
data = str(text).split("\n")
for line in data:
if len(line) > maxlen:
n = maxlen
for l in [line[i:i+n] for i in range(0, len(line), n)]:
for l in [line[i : i + n] for i in range(0, len(line), n)]:
paginator.add_line(l)
else:
paginator.add_line(line)
@ -219,7 +221,8 @@ async def run_command(args):
process = await asyncio.create_subprocess_shell(
args,
# stdout must a pipe to be accessible as process.stdout
stdout=asyncio.subprocess.PIPE)
stdout=asyncio.subprocess.PIPE,
)
# Wait for the subprocess to finish
stdout, stderr = await process.communicate()
# Return stdout