async def slash_factoid(self, ctx: ApplicationCommandInteraction, mention: Member = None): if not self.bot.is_supporter(ctx.author) and self.limiter.is_limited( ctx.data.id, ctx.channel_id): logger.debug( f'rate-limited (sc): "{ctx.author}", channel: "{ctx.channel}", factoid: "{ctx.data.name}"' ) return logger.info( f'factoid requested (sc) by: "{ctx.author}", channel: "{ctx.channel}", factoid: "{ctx.data.name}"' ) await self.increment_uses(ctx.data.name) message = self.resolve_variables( self.factoids[ctx.data.name]['message']) embed = None if self.factoids[ctx.data.name]['embed']: embed = Embed(colour=self._factoids_colour, description=message) message = '' if self.factoids[ctx.data.name]['image_url']: embed.set_image(url=self.factoids[ctx.data.name]['image_url']) if mention and isinstance(mention, Member): return await ctx.send(content=f'{mention.mention} {message}', embed=embed) else: return await ctx.send(content=message, embed=embed)
async def on_message(self, message: disnake.Message): if message.author.bot or message.webhook_id is not None: return if not hasattr(message.channel, "guild") or message.channel.guild is None: return me = message.guild.me if me is None: me = Utils.get_member(self.bot, message.guild, self.bot.user.id) permissions = message.channel.permissions_for(me) if me is None: return if not (permissions.read_messages and permissions.send_messages and permissions.embed_links): return role_list = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "ROLES") role_required = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") channel_list = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "CHANNELS") channels_ignored = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") mod_bypass = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "MOD_BYPASS") is_mod = message.author is not None and Permissioncheckers.is_mod( message.author) if (message.channel.id in channel_list) is channels_ignored and not ( is_mod and mod_bypass): return has_role = False if message.author is not None and hasattr(message.author, "roles"): for role in message.author.roles: if role.id in role_list: has_role = True break if has_role is not role_required and not (is_mod and mod_bypass): return prefix = Configuration.get_var(message.guild.id, "GENERAL", "PREFIX") if message.content.startswith(prefix, 0) and message.guild.id in self.commands: for trigger in self.commands[message.guild.id]: if message.content.lower() == prefix + trigger or ( message.content.lower().startswith( trigger, len(prefix)) and message.content.lower()[len(prefix + trigger)] == " "): info = self.commands[message.guild.id][trigger] images = IMAGE_MATCHER.findall(info.content) image = None if len(images) == 1: image = images[0] description = info.content.replace(image, "") else: description = info.content embed = Embed(description=description) if info.created_by is not None: creator = await Utils.get_user(info.created_by) embed.set_footer( text= f"Created by {str(creator)} ({info.created_by})", icon_url=creator.avatar.url) if image is not None: embed.set_image(url=image) await message.channel.send(embed=embed) self.bot.custom_command_count += 1
text = input( f"{fore}\nPlease write something for the webhook to send: ") title, description, image, thumbnail, footer = handle_embed_input() embed = Embed( title=split(title), description=split(description), ) image_url = urL_or_file(image) thumbnail_url = urL_or_file(thumbnail) files = [] if isinstance(image_url, str): embed.set_image(url=image_url) else: embed.set_image(file=image_url) files.append(image_url) if isinstance(thumbnail_url, str): embed.set_thumbnail(url=thumbnail_url) else: embed.set_thumbnail(file=thumbnail_url) files.append(thumbnail_url) embed.set_footer(text=split(footer)) wb.send( content=split(text), embed=embed,
async def on_message(self, msg: Message): # ignore our own messages if msg.author == self.bot.user: return if not msg.content or len(msg.content) < 2 or msg.content[0] != '!': return msg_parts = msg.content[1:].split() factoid_name = msg_parts[0].lower() if factoid_name not in self.factoids: if factoid_name in self.alias_map: factoid_name = self.alias_map[factoid_name] else: # factoid does not exit return if not self.bot.is_supporter(msg.author) and self.limiter.is_limited( factoid_name, msg.channel.id): logger.debug( f'rate-limited: "{msg.author}", channel: "{msg.channel}", factoid: "{factoid_name}"' ) return logger.info( f'factoid requested by: "{msg.author}", channel: "{msg.channel}", factoid: "{factoid_name}"' ) factoid = self.factoids[factoid_name] await self.increment_uses(factoid_name) message = self.resolve_variables(factoid['message']) # attempt to delete the message requesting the factoid if it's within a reply and only contains command if msg.reference and len(msg_parts) == 1: await msg.delete(delay=0.0) # if users are mentioned (but it's not a reply), mention them in the bot reply as well user_mention = None if msg.mentions and not msg.reference: user_mention = ' '.join(user.mention for user in msg.mentions) embed = None if factoid['embed']: embed = Embed(colour=self._factoids_colour, description=message) message = '' if factoid['image_url']: embed.set_image(url=factoid['image_url']) if user_mention and embed is not None: return await msg.channel.send(user_mention, embed=embed) elif user_mention: return await msg.channel.send(f'{user_mention} {message}') else: msg_reference = msg.reference # If reference is a message from a bot, try resolving the referenced message's reference if msg_reference and msg.reference.resolved.author.bot and ( ref := msg.reference.resolved.reference): msg_reference = ref return await msg.channel.send( message, embed=embed, # type: ignore reference=msg_reference, mention_author=True)