Пример #1
0
 async def on_message(self, message):
     member = self.bot.guild.get_member(message.author.id)
     if isinstance(message.author, discord.Member) and (
         message.guild != self.bot.guild
     ):
         return
     with DBManager.create_session_scope() as db_session:
         user = User._create_or_get_by_discord_id(
             db_session,
             message.author.id,
             user_name=str(member) if member else str(message.author),
         )
         Message._create(
             db_session,
             message.id,
             message.author.id,
             message.channel.id
             if isinstance(message.author, discord.Member)
             else None,
             message.content,
         )
         db_session.commit()
         HandlerManager.trigger(
             "discord_message",
             message_raw=message,
             message=message.content,
             author=message.author,
             user_level=user.level if user else 50,
             channel=message.channel
             if isinstance(message.author, discord.Member)
             else None,
             whisper=not isinstance(message.author, discord.Member),
         )
Пример #2
0
    def wait_discord_load(self):
        self.socket_manager = SocketManager(self.bot_name, self.execute_now)
        self.module_manager = ModuleManager(self.socket_manager,
                                            bot=self).load()

        self.commands = CommandManager(
            socket_manager=self.socket_manager,
            module_manager=self.module_manager,
            bot=self,
        ).load()
        HandlerManager.trigger("manager_loaded")

        # promote the admin to level 2000
        owner = self.config["main"].get("owner_id", None)
        if owner is None:
            log.warning(
                "No admin user specified. See the [main] section in the example config for its usage."
            )
        else:
            with DBManager.create_session_scope() as db_session:
                owner = User._create_or_get_by_discord_id(
                    db_session, str(owner))
                if owner is None:
                    log.warning(
                        "The login name you entered for the admin user does not exist on twitch. "
                        "No admin user has been created.")
                else:
                    owner.level = 2000
Пример #3
0
 async def on_ready(self):
     self.bot.guild = self.get_guild(int(self.bot.settings["discord_guild_id"]))
     if not self.bot.guild:
         log.error("Discord Guild not found!")
         return
     log.info(f"Discord Bot has started with id {self.user.id}")
     HandlerManager.trigger("discord_ready")
Пример #4
0
 def quit_bot(self):
     HandlerManager.trigger("on_quit")
     try:
         ScheduleManager.base_scheduler.print_jobs()
         ScheduleManager.base_scheduler.shutdown(wait=False)
     except:
         log.exception("Error while shutting down the apscheduler")
     self.private_loop.call_soon_threadsafe(self.private_loop.stop)
     self.socket_manager.quit()