def __init__(self, bot: HuskyBot): self._bot = bot self._bot_config = HuskyConfig.get_config() self._mute_config = HuskyConfig.get_config('mutes', create_if_nonexistent=True) self.__cache__ = [] self.read_mutes_from_file() self.__task__ = self._bot.loop.create_task(self.check_mutes()) LOG.info("Manager load complete.")
def get_platform_type(): if is_docker(): return os.environ.get('HUSKYBOT_PLATFORM', 'Docker') if HuskyConfig.get_session_store().get('daemonMode', False): return os.environ.get('HUSKYBOT_PLATFORM', 'Daemonized') return os.environ.get('HUSKYBOT_PLATFORM', None)
async def send_to_keyed_channel(bot: discord.Client, channel: HuskyStatics.ChannelKeys, embed: discord.Embed): log_channel = HuskyConfig.get_config().get('specialChannels', {}).get(channel.value, None) if log_channel is not None: log_channel: discord.TextChannel = bot.get_channel(log_channel) await log_channel.send(embed=embed)
def __init__(self): self.init_stage = -1 # Load in configuration and other important things here. self.config = HuskyConfig.get_config() self.session_store = HuskyConfig.get_session_store() self.developer_mode = self.__check_developer_mode() self.superusers = [] # Private variables used for init only self.__daemon_mode = (os.getppid() == 1) self.session_store.set("daemonMode", self.__daemon_mode) self.__log_path = 'logs/huskybot.log' self.session_store.set('logPath', self.__log_path) # Database things # noinspection PyTypeChecker self.db: Optional[sqlalchemy.engine.Engine] = None self.session_factory = None # Load in HuskyBot's logger self.logger = self.__initialize_logger() # Load in HuskyBot's API self.webapp = web.Application() # Allow setting custom routes (litecord/canary/apiv7 support) discord.http.Route.BASE = os.getenv('DISCORD_API_URL', discord.http.Route.BASE) super().__init__( command_prefix=self.config.get('prefix', '/'), status=discord.Status.idle, activity=self.__build_stage0_activity(), command_not_found= "**Error:** The bot could not find the command `/{}`.", command_has_no_subcommands= "**Error:** The command `/{}` has no subcommands.", help_command=HuskyHelpFormatter()) self.init_stage = 0
def should_process_message(message: discord.Message): # Don't process direct messages if not isinstance(message.channel, discord.TextChannel): return False # Don't process messages from ignored guilds (developer mode) if message.guild.id in HuskyConfig.get_config().get("ignoredGuilds", []): return False # Don't process messages from other bots. if message.author.bot: return False # Otherwise, process. return True
def __init__(self, bot: HuskyBot): """ Initialize a new GiveawayManager for the bot. :param bot: The Bot we use to initialize everything. """ self.bot = bot self._config = bot.config self._giveaway_config = HuskyConfig.get_config('giveaways', create_if_nonexistent=True) # Random number generator self._rng = random.SystemRandom() # We store all giveaways in a time-ordered cache list. Reading and working with the file directly is # *generally* a bad idea. self.__cache__ = [] self.load_giveaways_from_file() self.__task__ = self.bot.loop.create_task(self.process_giveaways()) LOG.info("Manager load complete.")
async def convert(self, ctx: commands.Context, context: str): logging_channel = HuskyConfig.get_config() \ .get('specialChannels', {}).get(HuskyStatics.ChannelKeys.STAFF_LOG.value, None) channels = [] name = context if context.lower() == "all": for channel in ctx.guild.text_channels: if channel.id == logging_channel: continue channels.append(channel) elif context.lower() == "public": if not ctx.guild.default_role.permissions.read_messages: raise commands.BadArgument("No public channels exist in this guild.") for channel in ctx.guild.text_channels: if channel.overwrites_for(ctx.guild.default_role).read_messages is False: continue channels.append(channel) else: cl = context.split(',') converter = commands.TextChannelConverter() for ch_key in cl: channels.append(await converter.convert(ctx, ch_key.strip())) if len(channels) == 1: name = channels[0].name else: name = str(list(c.name for c in channels)) return {"name": name, "channels": channels}
def __init__(self, bot: HuskyBot): self.bot = bot self._config = bot.config self._guildsecurity_store = HuskyConfig.get_session_store( "guildSecurity") LOG.info("Loaded plugin!")