Browse Source

this runs woo

tags/v1.4.0
roxie 6 years ago
parent
commit
fd9744e4f0
2 changed files with 79 additions and 62 deletions
  1. +62
    -0
      err_handle.py
  2. +17
    -62
      main.py

+ 62
- 0
err_handle.py View File

@@ -0,0 +1,62 @@
import traceback
import datetime
import load_config
import discord
from config.server_config import ServerConfig
from discord.ext import commands


class ErrHandle():
def __init__(self, Bot):
self.bot = Bot
self.dev = True # For debugging
self.slow_mode = False
self.slow_mode_channels = {}
self.users = {}
self.con = ServerConfig()
self.servers = self.con.servers

async def on_error(self, event, *args, **kwargs):
if self.dev:
traceback.print_exc()
else:
embed = discord.Embed(title=':x: Event Error', colour=0xe74c3c) #Red
embed.add_field(name='Event', value=event)
embed.description = '```py\n%s\n```' % traceback.format_exc()
embed.timestamp = datetime.datetime.utcnow()
try:
await self.bot.send_message(self.bot.owner_id, embed=embed)
except:
pass


async def on_command_error(self, error, ctx):
if isinstance(error, commands.NoPrivateMessage):
await self.bot.send_message(ctx.message.author, "This command cannot be used in private messages.")
elif isinstance(error, commands.DisabledCommand):
await self.bot.send_message(ctx.message.channel, content="This command is disabled.")
elif isinstance(error, commands.CheckFailure):
await self.bot.send_message(ctx.message.channel, content="You do not have permission to do this. Back off, thot!")
elif isinstance(error, KeyError):
await self.bot.send_message(ctx.message.channel, content="Belgh")
elif isinstance(error, commands.CommandInvokeError):
if self.dev:
raise error
else:
embed = discord.Embed(title=':x: Command Error', colour=0x992d22) #Dark Red
embed.add_field(name='Error', value=str(error))
embed.add_field(name='Server', value=ctx.message.server)
embed.add_field(name='Channel', value=ctx.message.channel)
embed.add_field(name='User', value=ctx.message.author)
embed.add_field(name='Message', value=ctx.message.content)
embed.timestamp = datetime.datetime.utcnow()
try:
await self.bot.send_message(await self.bot.get_user_info(load_config.owner), embed=embed)
except:
raise error
else:
if self.dev:
raise error

def setup(Bot):
Bot.add_cog(ErrHandle(Bot))

+ 17
- 62
main.py View File

@@ -4,14 +4,21 @@ import time
import logging
import os.path
import datetime
import traceback

import discord
from discord.ext import commands

import load_config
from config.server_config import ServerConfig


if not os.path.isfile("settings/preferences.ini"):
print(
"PREFERENCE FILE MISSING. Something has gone wrong. Please make sure there is a file called 'preferences.ini' in the settings folder")
exit(0)

if not os.path.isfile("config/servers.json"):
with open("config/servers.json", "w+") as fp:
fp.write("{}")

start_time = time.time()

# Sets up Logging that discord.py does on its own
@@ -21,11 +28,9 @@ handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w'
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)


server_config = ServerConfig()
bot = commands.Bot(command_prefix=load_config.command_prefix, description=load_config.__description__)
bot.dev = True # For debugging
bot.owner = load_config.owner
bot = commands.Bot(command_prefix=load_config.command_prefix, description=load_config.description, owner_id=load_config.owner)



def blacklisted(user):
@@ -40,7 +45,7 @@ async def on_ready():
server_config.error_check(bot.guilds)
print("Discord.py version: " + discord.__version__)
print("Client logged in\n")
bot.owner = load_config.owner
bot.load_extension("err_handle")

#print("Cogs Loaded:")
#for cog in load_config.cogs:
@@ -77,51 +82,9 @@ async def on_message(message):
return
return await bot.process_commands(message)

@bot.event
async def on_error(event, *args, **kwargs):
if bot.dev:
traceback.print_exc()
else:
embed = discord.Embed(title=':x: Event Error', colour=0xe74c3c) #Red
embed.add_field(name='Event', value=event)
embed.description = '```py\n%s\n```' % traceback.format_exc()
embed.timestamp = datetime.datetime.utcnow()
try:
await bot.send_message(bot.owner, embed=embed)
except:
pass

@bot.event
async def on_command_error(error, ctx):
if isinstance(error, commands.NoPrivateMessage):
await bot.send_message(ctx.message.author, "This command cannot be used in private messages.")
elif isinstance(error, commands.DisabledCommand):
await bot.send_message(ctx.message.channel, content="This command is disabled.")
elif isinstance(error, commands.CheckFailure):
await bot.send_message(ctx.message.channel, content="You do not have permission to do this. Back off, thot!")
elif isinstance(error, KeyError):
await bot.send_message(ctx.message.channel, content="Belgh")
elif isinstance(error, commands.CommandInvokeError):
if bot.dev:
raise error
else:
embed = discord.Embed(title=':x: Command Error', colour=0x992d22) #Dark Red
embed.add_field(name='Error', value=str(error))
embed.add_field(name='Server', value=ctx.message.server)
embed.add_field(name='Channel', value=ctx.message.channel)
embed.add_field(name='User', value=ctx.message.author)
embed.add_field(name='Message', value=ctx.message.content)
embed.timestamp = datetime.datetime.utcnow()
try:
await bot.send_message(await bot.get_user_info(load_config.owner), embed=embed)
except:
raise error
#else:
# if bot.dev:
# raise error

@bot.command()
async def about():
async def about(ctx):
"""
Outputs info about RoxBot, showing uptime, what settings where set in prefs.ini and credits.
"""
@@ -132,8 +95,8 @@ async def about():
em.add_field(name="Command Prefix", value=load_config.command_prefix)
em.add_field(name="Owner", value=ownername)
em.add_field(name="Owner ID", value=load_config.owner)
em.add_field(name="Bot Version", value=load_config.version)
em.add_field(name="Author", value=load_config.author)
em.add_field(name="Bot Version", value=load_config.__version__)
em.add_field(name="Author", value=load_config.__author__)
em.set_footer(text="RoxBot is licensed under the MIT License")

# Do time calc late in the command so that the time returned is closest to when the message is received
@@ -141,16 +104,8 @@ async def about():
uptime = str(datetime.timedelta(seconds=uptimeflo))
em.add_field(name="Current Uptime", value=str(uptime.split(".")[0]))

return await bot.say(embed=em)
return await ctx.channel.say(embed=em)


if __name__ == "__main__":
if not os.path.isfile("settings/preferences.ini"):
print("PREFERENCE FILE MISSING. Something has gone wrong. Please make sure there is a file called 'preferences.ini' in the settings folder")
exit(0)

if not os.path.isfile("config/servers.json"):
with open("config/servers.json", "w") as fp:
fp.write("{}")

bot.run(load_config.token)

Loading…
Cancel
Save