Esempio n. 1
0
async def processCommand(bundle):
    # Parse our command.
    args = bundle.message.content.split(" ")
    c = args[0]
    if bundle.prefix in c:
        c = c.replace(bundle.prefix, bundle.bot.prefix)

    # Restart the bot if the master says so.
    if c.lower() == "bot.restart":
        if str(bundle.message.author) == bundle.bot.botMaster:
            utils.restart_program()

    # Continue loading the plugin.
    command = bundle.bot.commands.get(c, null)
    if command != null:
        if isinstance(command, str):
            # print("Sending a reply...")
            # Reply to the user or channel
            await bundle.message.channel.send(command)
        else:
            # Create a new loader instance and run the plugin with args.
            try:
                name = args[0][len(bundle.prefix):].lower()
                args[0] = str(bundle.message.author)
                plugin = utils.Loader(bundle.bot, name, bundle.message, args)
                command.loader = plugin
                command.message = bundle.message
                await plugin.start()
            except Exception as error:
                bundle.message.channel.send(str(error))
                if logging.Logger.verbosityLevel >= logging.Verbosity.NONE:
                    messages.printMessage(str(error), messages.MessageType.EXCEPTION, True)
Esempio n. 2
0
 async def remind(self):
     try:
         if str(self.message.author) in self.bot.friends:
             reminded = 0
             guild = self.message.author.guild
             reminder = "**NOTICE**: This is a reminder to please obtain a role within *" + str(guild.name) + "* by using the roles command by " \
                        "typing — *bot.roles get* — in order for me to stop nagging you about it. And, you know that I wouldn't do it if I didn't love you. :heart:\n\n" \
                        "If you need help understanding commands or how I operate then type: *autumn.help* for more information. :kiss:"
             for member in guild.members:
                 if member.top_role is guild.default_role:
                     try:
                         await member.send(reminder)
                         messages.printMessage(
                             str(member.name) + " has been reminded!")
                         reminded += 1
                     except:
                         messages.printMessage(
                             member.name + " was unable to be reminded.")
                 else:
                     pass
             if reminded > 0:
                 await self.message.channel.send(
                     "Users have been reminded about their roles!")
             else:
                 await self.message.channel.send(
                     "Not all users could be reminded about their roles.")
         else:
             await self.message.channel.send(
                 "Only my master or a server administrator can remind users about roles."
             )
     except:
         await self.message.channel.send(
             "I'm unable to remind users about their roles...")
Esempio n. 3
0
def startBot():
    startResolver()
    if logging.Logger.verbosityLevel > logging.Verbosity.DEFAULT:
        messages.printMessage("Loading internal commands...")
        for command, obj in bot.commands.items():
            messages.printMessage(("Command: %s" % command), NONE, False)
    startProcessing()
Esempio n. 4
0
def populate_info(files, path):
    guilds = {}
    # Unpickle all of the guild info files.
    for file in files:
        guild = pickle.load(open(path + file, 'rb'))
        guilds[guild.id] = guild
    if len(guilds) > 0:
        return guilds
    else:
        messages.printMessage("Some guilds' info couldn't be loaded. ",
                              messages.MessageType.WARNING)
Esempio n. 5
0
 async def start(self):
     try:
         if logging.Logger.verbosityLevel >= logging.Verbosity.DEFAULT:
             messages.printMessage(
                 "Running '" + self.plugin +
                 "' for %s" % str(self.message.author),
                 messages.MessageType.NOTICE)
         await self.startPlugin(self.plugin, self.args)
     except Exception as exception:
         print(exception)
         pass
Esempio n. 6
0
 def save_settings(self):
     try:
         pickle.dump(self,
                     open(self.settings_path + self.settings_file, 'wb'))
         if logging.Logger.verbosityLevel > logging.Verbosity.DEFAULT:
             messages.printMessage("Settings have been successfully saved!",
                                   messages.MessageType.SUCCESS)
         else:
             pass
     except Exception as ex:
         messages.printMessage("I couldn't save settings.",
                               messages.MessageType.EXCEPTION)
Esempio n. 7
0
 def serialize_guild_info(self, path):
     filename = path + str(self.id) + ".agi"
     if not os.path.exists(path):
         os.mkdir(path)
     file = open(filename, 'wb')
     try:
         pickle.dump(self, file)
         messages.printMessage(
             "Successfully saved " + self.name + "'s settings!",
             messages.MessageType.SUCCESS)
     except:
         messages.printMessage(
             self.name + "'s settings could not be saved.",
             messages.MessageType.EXCEPTION)
Esempio n. 8
0
 def load_settings(self):
     try:
         if not os.path.exists(self.settings_path):
             os.mkdir(self.settings_path)
         if os.path.exists(self.settings_path + self.settings_file):
             if os.path.isfile(self.settings_path + self.settings_file):
                 if logging.Logger.verbosityLevel > logging.Verbosity.DEFAULT:
                     messages.printMessage(
                         "Settings have been successfully loaded!",
                         messages.MessageType.SUCCESS)
                 else:
                     pass
                 return pickle.load(
                     open(self.settings_path + self.settings_file, 'rb'))
             else:
                 messages.printMessage(
                     "The settings file exists but is corrupt.",
                     messages.MessageType.Warning)
         else:
             messages.printMessage("No settings file exists.",
                                   messages.MessageType.EXCEPTION)
             return Settings(self.bot)
     except Exception as ex:
         messages.printMessage("I couldn't load settings.",
                               messages.MessageType.EXCEPTION)
Esempio n. 9
0
def getMD5(filename, block=2**20):
    import hashlib
    md5 = hashlib.md5()
    try:
        file = open(filename, 'rb')
        while True:
            data = file.read(block)
            if not data:
                break
            md5.update(data)
    except IOError:
        if logging.Logger.verbosityLevel >= logging.Verbosity.DEBUG:
            messages.printMessage("File \'" + filename + "\' not found!",
                                  messages.MessageType.NONE, False)
        return None
    except:
        return None
    return md5.hexdigest()
Esempio n. 10
0
def startProcessing():
    if logging.Logger.verbosityLevel >= logging.Verbosity.TRACE:
        messages.printMessage("Connecting to server...")
    try:
        # Connect to any permissible servers.
        Handler(bot).start(bot)  # Create a new handler object and start it.
    except Exception as error:  # Typically when someone sends an invalid character code.
        messages.printMessage(error, messages.MessageType.EXCEPTION)
    messages.printMessage("Adiós, mi amor. 🌸", messages.MessageType.EXCEPTION)
Esempio n. 11
0
def main():
    printGreeting()
    current = sys.path[0]
    sys.excepthook = exception_handler
    sys.path.append(current + "/modules")
    sys.path.append(current + "/plugins")
    bot.settings = bot.settings.load_settings()
    messages.printMessage("Settings Version: " + bot.settings.version)
    if logging.Logger.verbosityLevel > logging.Verbosity.DEFAULT:
        messages.printMessage("Appending system module paths...")
        for path in sys.path:
            messages.printMessage(("Path: %s" % path), NONE, False)
    startBot()
    exit(0)  # End the script gracefully.
Esempio n. 12
0
def printGreeting():
    bold = messages.Colors.bold
    reset = messages.Colors.reset
    messages.printMessage("===================================", NONE, False)
    messages.printMessage("🌙      Welcome to: Autumn!      🌙", NONE, False)
    messages.printMessage("===================================\n", NONE, False)
    messages.printMessage(
        "⇢ " + bold + "Author" + reset + ": Jason Drawdy (Buddha)", NONE,
        False)
    messages.printMessage("⇢ " + bold + "Date" + reset + ": 4.10.20", NONE,
                          False)
    messages.printMessage(
        "⇢ " + bold + "Version" + reset + ": 3.0.0 (Strawberry) 🍓\n", NONE,
        False)
    messages.printMessage("===================================", NONE, False)
Esempio n. 13
0
def startResolving():
    if logging.Logger.verbosityLevel > logging.Verbosity.TRACE:
        messages.printMessage("Loading plugins...")
    sentinel = Handler(bot, "plugins")
    asyncio.run(sentinel.watch_plugins())
Esempio n. 14
0
def exception_handler(exception_type,
                      exception,
                      traceback,
                      debug_hook=sys.excepthook):
    messages.printMessage("Refreshing Watson session key.",
                          messages.MessageType.INFO)
Esempio n. 15
0
 async def on_ready():
     messages.printMessage('We have logged in as {0.user}'.format(
         autumn.client))
     messages.printMessage('Checking for guild information.')
     autumn.check_guild_info()