def __init__(self, message: str, is_one_of: bool): self.is_one_of = is_one_of if is_command_message('vote', message) or is_command_message('singlevote', message): message = message[(message.index('vote') + 4):] # If date/time line is present: # line 1: date # line 2: question # lines 3,4..n: emoji option if len(message.strip()) == 0: raise self.ParseError() lines = message.splitlines(False) if len(lines) < 3: raise self.ParseError() try: self.end_date = parser.parse(lines[0], dayfirst=True, fuzzy=True) lines = lines[1:] # Only keep lines with the question and the options except parser.ParserError: self.end_date = None # The user might have actually followed the help and put a newline before the question if len(lines[0].strip()) == 0: lines = lines[1:] if len(lines) < 3: # Do we still have at least the question and two options? raise self.ParseError() self.question = lines[0] parsed_opts = [self.parse_option(x.strip()) for x in lines[1:]] self.options: Dict[str, 'VoteMessage.VoteOption'] = {x.emoji: x for x in parsed_opts} # Check if emojis are unique if len(self.options) != len(set(self.options.keys())): raise self.ParseError()
async def on_raw_reaction_add(self, payload): """Catch reaction, get all properties and then call proper cog/s""" ctx: ReactionContext = await ReactionContext.from_payload( self.bot, payload) if ctx is None: return if self.bot.get_cog("Vote") is not None and (is_command_message( 'vote', ctx.message.content) or is_command_message( 'singlevote', ctx.message.content, False)): try: await self.bot.get_cog("Vote").handle_raw_reaction_add(payload) except sqlalchemy.exc.InternalError: session.rollback() return cogs = [] if (ctx.message.embeds and ctx.message.embeds[0].title is not discord.Embed.Empty and "reviews" in ctx.message.embeds[0].title): cogs.append(self.bot.get_cog("Review")) if ctx.emoji == "📌": cogs.append(self.bot.get_cog("AutoPin")) if ctx.channel.id not in config.role_channels: cogs.append(self.bot.get_cog("Karma")) else: cogs.append(self.bot.get_cog("ReactToRole")) if (ctx.emoji == "❎" and payload.channel_id in config.deduplication_channels and not payload.member.bot and ctx.message.author.bot): cogs.append(self.bot.get_cog("Warden")) if (ctx.message.embeds and ctx.message.embeds[0].author.name is not discord.Embed.Empty and "streamlinks" in ctx.message.embeds[0].author.name.lower()): cogs.append(self.bot.get_cog("StreamLinks")) if (ctx.channel.id == config.meme_room or ctx.channel.id == config.meme_repost_room) and \ ctx.message.author.id != ctx.member.id: cogs.append(self.bot.get_cog("MemeRepost")) for cog in cogs: # check if cog is loaded if cog: try: await cog.handle_reaction(ctx) except sqlalchemy.exc.InternalError: session.rollback() except discord.errors.DiscordServerError: pass
async def on_raw_reaction_add(self, payload): """Catch reaction, get all properties and then call proper cog/s""" ctx: ReactionContext = await ReactionContext.from_payload(self.bot, payload) if ctx is None: return if self.bot.get_cog("Vote") is not None and ( is_command_message("vote", ctx.message.content) or is_command_message("singlevote", ctx.message.content, False) ): try: await self.bot.get_cog("Vote").handle_raw_reaction_add(payload) except sqlalchemy.exc.InternalError: session.rollback() return cogs = [] # send embed to user where he left reading if ctx.emoji == "🔖": await self.bot.get_cog("Bookmark").bookmark_reaction(ctx) return if ctx.emoji == "📌": cogs.append(self.bot.get_cog("AutoPin")) if ctx.channel.id not in config.role_channels: cogs.append(self.bot.get_cog("Karma")) else: cogs.append(self.bot.get_cog("Roles")) if ( ctx.emoji == "❎" and payload.channel_id in config.deduplication_channels and not payload.member.bot and ctx.message.author.bot ): cogs.append(self.bot.get_cog("Warden")) if (ctx.channel.id == config.meme_room or ctx.channel.id == config.meme_repost_room) and \ ctx.message.author.id != ctx.member.id: cogs.append(self.bot.get_cog("MemeRepost")) for cog in cogs: # check if cog is loaded if cog: try: await cog.handle_reaction(ctx) except sqlalchemy.exc.InternalError: session.rollback() except disnake.errors.DiscordServerError: pass