async def twitch_cog(bot: discord.ext.commands.Bot): """ setup any state specific to the execution of the given module.""" twitch_cog = cog.TwitchAlert(bot) bot.add_cog(twitch_cog) await dpytest.empty_queue() dpytest.configure(bot) return twitch_cog
async def create_autodaily_settings(bot: discord.ext.commands.Bot, guild_id: int) -> AutoDailySettings: if guild_id is None or bot is None: raise Exception( 'No parameters given. You need to specify both parameters \'bot\' and \'guild_id\'.' ) autodaily_settings = await _prepare_create_autodaily_settings(guild_id) _, channel_id, can_post, latest_message_id, delete_on_change, notify_id, notify_type, latest_message_create_date, latest_message_modify_date = autodaily_settings[ 0] try: channel = bot.get_channel(channel_id) except Exception as error: channel = None try: guild = bot.get_guild(guild_id) except Exception as error: guild = None notify = None if notify_id and notify_type and guild: if notify_type == AutoDailyNotifyType.USER: notify = guild.get_member(notify_id) elif notify_type == AutoDailyNotifyType.ROLE: notify = guild.get_role(notify_id) return AutoDailySettings(guild, channel, can_post, latest_message_id, delete_on_change, notify, latest_message_create_date, latest_message_modify_date)
def __init__(self, bot: discord.ext.commands.Bot): self.bot = bot bot.remove_command('help') config = parsing.parse_json('config.json') self.prefix = config["prefix"] self.bot_descr = config["description"] self.color = 0x1e7180 self.error = 0xcc0000
def setup(bot: discord.ext.commands.Bot): global client client = bot vac = Vac() bot.add_cog(vac) async def job(): await vac.check_vac_status_and_send_results() schedule.every().hour.do(job)
def setup(bot: discord.ext.commands.Bot): global client client = bot vac = Vac() bot.add_cog(vac) channel = bot.get_channel(int(config.default_channel)) async def job(): await vac.check_vac_status_and_send_results(channel, False) schedule.every().day.at("12:00").do(job)
def _schedule_event(bot: discord.ext.commands.Bot): task_info_list = execute_statement( create_select_query("configure__schedule")).all(as_dict=True) for task_info in task_info_list: local_guild: discord.Guild = bot.get_guild(task_info.get("guild_id")) re_schedule_task( bot, _get_task(task_info.get("task")), task_info.get("weekday"), task_info.get("at_time"), task_info.get("tag"), message=task_info.get("message"), channel=bot.get_channel(int(task_info.get("channel_id"))), number=task_info.get("number"), guild=local_guild, category=None if local_guild is None else discord.utils.get( local_guild.categories, id=int(task_info.get("category_id"))))
async def wait_react( msg: discord.Message, bot: discord.ext.commands.Bot, allowed: Tuple[str, ...] = None, timeout=10.0 ): fut = asyncio.get_running_loop().create_future() async def listener(payload: discord.RawReactionActionEvent): if allowed is not None and str(payload.emoji) not in allowed: return if payload.message_id == msg.id and payload.user_id != bot.user.id: fut.set_result(str(payload.emoji)) bot.add_listener(listener, 'on_raw_reaction_add') bot.add_listener(listener, 'on_raw_reaction_remove') r = await fut # await asyncio.wait_for(fut, timeout) bot.remove_listener(listener, 'on_raw_reaction_add') bot.remove_listener(listener, 'on_raw_reaction_remove') return str(r)
async def wednesday(config: CONF0, bot: discord.ext.commands.Bot): while True: today, today_img = config.DailyDict[dt.datetime.today.weekday()] if today: for chan in config.DailyChan: async with bot.get_channel(chan).typing(): await bot.get_channel(chan).send(file=discord.File(today_img)) hours = 60 * 60 async def bg(): while True: await asyncio.sleep(12 * hours) task = asyncio.create_task(bg()) try: await asyncio.sleep(arg) finally: task.cancel()
async def wait_for_choice(bot: discord.ext.commands.Bot, user: Union[discord.User, discord.Member], message: discord.Message, choices: list, cancellable: bool = False) -> int: """Wait for user to react with emote, then remove their reaction Example: No reaction (timeout) -> -1 Cancelled (❌) -> 0 Valid reaction -> 1 / 2 / 3 / ... (index of emoji in choices list + 1) """ number_emotes = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "0️⃣"] if cancellable: number_emotes.append("❌") choices.append("❌") # Checks if added reaction is the one we're waiting for def check(payload: discord.RawReactionActionEvent): if message.id == payload.message_id and payload.emoji.name in number_emotes and payload.user_id != bot.user.id: return True choice = None author_id = -1 while choice not in choices or author_id != user.id: # Watch for reaction try: payload: discord.RawReactionActionEvent = await bot.wait_for("raw_reaction_add", timeout=300, check=check) choice = payload.emoji.name author_id = payload.user_id # No reaction after timeout except asyncio.TimeoutError: return -1 # Remove user's reaction try: await message.remove_reaction(payload.emoji.name, bot.get_user(author_id)) except discord.errors.Forbidden: pass if choice == "❌": return 0 else: # Return emote as the number it represents (1️⃣ represents 1, 0️⃣️ represents 10) return choices.index(choice) + 1
async def report_infraction(bot: discord.ext.commands.Bot, infraction: Infraction): """Logs the infraction to the infraction report channel Required parameters: - bot: discord.ext.commands.Bot object - infraction: models.Infraction.Infraction object Returns: None """ # Get the channel the report should be send to ch = bot.get_guild(config.guild).get_channel(config.infrepch) # Send the infraction await ch.send(embed=str(infraction)) del ch
def initialize_bot(self, discord_bot: discord.ext.commands.Bot) -> None: """ initializes a discord bot with commands and listeners on this pseudo cog class :param: discord_bot: the discord_bot to initialize """ discord_bot.add_listener(self.on_ready) discord_bot.add_listener(self.on_message) if self.discord_version_enabled: discord_bot.add_command( Command(self.version, name="version", pass_context=True, ignore_extra=False, help="display the plugin's version information"))
def setup(bot: discord.ext.commands.Bot): bot.add_cog(WordFilter(bot))
def setup(bot: discord.ext.commands.Bot): bot.add_cog(Karma())
def setup(bot: discord.ext.commands.Bot): bot.add_cog(Misc(bot))
def setup(bot: discord.ext.commands.Bot): bot.add_cog(OsrsCog(bot))
async def tf_cog(bot: discord.ext.commands.Bot): tf_cog = TextFilterCog(bot) bot.add_cog(tf_cog) dpytest.configure(bot) logger.info("Tests starting") return tf_cog
def setup(bot: discord.ext.commands.Bot): bot.add_command(roll)
def teardown(bot: discord.ext.commands.Bot): bot.remove_listener(on_message)
def teardown(bot: discord.ext.commands.Bot): bot.remove_command(get_version)
def setup(bot: discord.ext.commands.Bot): bot.add_cog(Config(bot))
def setup(bot: discord.ext.commands.Bot): bot.add_listener(on_message)
def teardown(bot: discord.ext.commands.Bot): bot.remove_command(roll)
def setup(bot: discord.ext.commands.Bot): bot.add_cog(GenericCommands(bot))
def announce_cog(bot: discord.ext.commands.Bot): announce_cog = Announce.Announce(bot) bot.add_cog(announce_cog) dpytest.configure(bot) print("Tests starting") return announce_cog
def setup(bot: discord.ext.commands.Bot): bot.add_command(version)
def utils_cog(bot: discord.ext.commands.Bot): utils_cog = LastCtxCog(bot) bot.add_cog(utils_cog) dpytest.configure(bot) logger.info("Tests starting") return utils_cog
def __init__(self, bot: discord.ext.commands.Bot): self.bot = bot bot.remove_command('help')
def announce_cog(bot: discord.ext.commands.Bot): announce_cog = announce.Announce(bot) bot.add_cog(announce_cog) dpytest.configure(bot, 2, 1, 2) logger.info("Tests starting") return announce_cog
def setup(bot: discord.ext.commands.Bot): bot.add_cog(GrinchCommands(bot))
def base_cog(bot: discord.ext.commands.Bot): base_cog = BaseCog(bot) bot.add_cog(base_cog) dpytest.configure(bot) logger.info("Tests starting") return base_cog