Esempio n. 1
0
 async def execute(self, bot, guild, data, raid_id, raider_ids, shield):
     try:
         channel = guild.get_channel(data["channel"])
         if channel is not None:
             await channel.send(
                 data["message"].format(server_name=guild.name))
         else:
             log(guild.id,
                 'raid_message_failed_missing_channel',
                 shield,
                 cid=data["channel"])
             GearbotLogging.log_raw(
                 guild.id, 'raid_message_failed_missing_channel',
                 data["message"].format(server_name=guild.name))
     except Forbidden:
         log(guild.id,
             'raid_message_failed_channel',
             shield,
             cid=data["channel"])
         GearbotLogging.log_raw(
             guild.id, 'raid_message_failed_missing_channel',
             data["message"].format(server_name=guild.name))
     except Exception as ex:
         log(guild.id,
             'raid_message_failed_channel_unknown_error',
             shield,
             cid=data["channel"])
         GearbotLogging.log_raw(
             guild.id, 'raid_message_failed_missing_channel',
             data["message"].format(server_name=guild.name))
         await TheRealGearBot.handle_exception('RAID NOTIFICATION FAILURE',
                                               bot, ex)
Esempio n. 2
0
    async def on_raw_message_delete(self, data: RawMessageDeleteEvent):
        if data.message_id in self.bot.data["message_deletes"]:
            self.bot.data["message_deletes"].remove(data.message_id)
            return
        c = self.bot.get_channel(data.channel_id)
        if c is None or isinstance(c, DMChannel) or c.guild is None or (not Features.is_logged(c.guild.id, "MESSAGE_LOGS")) or data.channel_id in Configuration.get_var(c.guild.id, "MESSAGE_LOGS", "IGNORED_CHANNELS_OTHER"):
            return
        message = await MessageUtils.get_message_data(self.bot, data.message_id)
        if message is not None:
            if message.channel in self.bot.being_cleaned:
                self.bot.being_cleaned[message.channel].add(data.message_id)
                return
            guild = self.bot.get_guild(message.server)
            user: discord.User = await Utils.get_user(message.author)
            hasUser = user is not None
            if not hasUser or user.id in Configuration.get_var(guild.id, "MESSAGE_LOGS", "IGNORED_USERS") or user.id == guild.me.id:
                return
            channel = self.bot.get_channel(message.channel)
            name = Utils.clean_user(user) if hasUser else str(message.author)
            GearbotLogging.log_key(guild.id, 'message_removed', name=name, user_id=user.id if hasUser else 'WEBHOOK', channel=channel.mention)
            type_string = None
            if message.type is not None:
                if message.type == MessageType.new_member.value:
                    type_string = Translator.translate('system_message_new_member', guild)
                elif message.type == MessageType.pins_add.value:
                    type_string = Translator.translate('system_message_new_pin', guild)
                else:
                    type_string = Translator.translate('system_message_unknown', guild)

                type_string = Translator.translate('system_message', guild, type=type_string)
            if Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", "EMBED"):
                embed_content = type_string or message.content

                if len(embed_content) == 0:
                    embed_content = Translator.translate('no_content_embed', guild)

                embed = discord.Embed(timestamp=datetime.datetime.utcfromtimestamp(time.time()),
                                      description=embed_content)
                embed.set_author(name=user.name if hasUser else message.author,
                                 icon_url=user.avatar_url if hasUser else EmptyEmbed)

                embed.set_footer(text=Translator.translate('sent_in', guild, channel=channel.name))
                if len(message.attachments) > 0:
                    embed.add_field(name=Translator.translate('attachment_link', guild),
                                    value='\n'.join(Utils.assemble_attachment(channel.id, attachment.id, attachment.name) for attachment in message.attachments))
                GearbotLogging.log_raw(guild.id, "message_removed", embed=embed)
            else:
                if type_string is None:
                    if len(message.content) != 0:
                        cleaned_content = await Utils.clean(message.content, channel.guild)
                        GearbotLogging.log_raw(guild.id, 'message_removed', Translator.translate('content', guild.id, content=cleaned_content))
                else:
                    GearbotLogging.log_raw(guild.id, "message_removed", type_string)

                count = 1
                multiple_attachments = len(message.attachments) > 1
                for attachment in message.attachments:
                    attachment_url = Utils.assemble_attachment(channel.id, attachment.id, attachment.name)
                    if multiple_attachments:
                        attachment_str = Translator.translate('attachment_item', guild, num=count, attachment=attachment_url)
                    else:
                        attachment_str = Translator.translate('attachment_single', guild, attachment=attachment_url)

                    GearbotLogging.log_raw(guild.id, "message_removed", attachment_str)
                    count += 1
Esempio n. 3
0
    async def on_raw_message_edit(self, event: RawMessageUpdateEvent):
        cid = int(event.data["channel_id"])
        if cid == Configuration.get_master_var("BOT_LOG_CHANNEL"):
            return
        c = self.bot.get_channel(cid)
        if c is None or isinstance(c, DMChannel) or c.guild is None or (not Features.is_logged(c.guild.id, "MESSAGE_LOGS")) or cid in Configuration.get_var(c.guild.id, "MESSAGE_LOGS", "IGNORED_CHANNELS_OTHER"):
            return
        message = await MessageUtils.get_message_data(self.bot, event.message_id)
        if message is not None and "content" in event.data:
            channel: discord.TextChannel = self.bot.get_channel(int(event.data["channel_id"]))
            if channel.guild is None:
                return
            user: discord.User = self.bot.get_user(message.author)
            hasUser = user is not None
            if message.content == event.data["content"]:
                # either pinned or embed data arrived, if embed data arrives it's gona be a recent one so we'll have the cached message to compare to
                old = message.pinned
                new = event.data["pinned"]
                if old == new:
                    return
                else:
                    parts = dict(channel=Utils.escape_markdown(c.name), channel_id=c.id)
                    if new:
                        # try to find who pinned it
                        key = "message_pinned"
                        m = await c.history(limit=5).get(type = MessageType.pins_add)
                        if m is not None:
                            key += "_by"
                            parts.update(user=Utils.escape_markdown(m.author), user_id=m.author.id)
                    else:
                        # impossible to determine who unpinned it :meowsad:
                        key = "message_unpinned"
                    GearbotLogging.log_key(c.guild.id, key, **parts)
                    GearbotLogging.log_raw(c.guild.id, key, f'```\n{Utils.trim_message(event.data["content"], 1990)}\n```')
                    GearbotLogging.log_raw(c.guild.id, key, f"{Translator.translate('jump_link', c.guild.id)}: {MessageUtils.construct_jumplink(c.guild.id, c.id, event.message_id)}")
                    await MessageUtils.update_message(self.bot, event.message_id, message.content, new)
                    return

            mc = message.content
            if mc is None or mc == "":
                mc = f"<{Translator.translate('no_content', channel.guild.id)}>"
            after = event.data["content"]
            if after is None or after == "":
                after = f"<{Translator.translate('no_content', channel.guild.id)}>"
            if hasUser and user.id not in Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", "IGNORED_USERS") and user.id != channel.guild.me.id:
                GearbotLogging.log_key(channel.guild.id, 'edit_logging', user=Utils.clean_user(user), user_id=user.id, channel=channel.mention)
                if Configuration.get_var(channel.guild.id, "MESSAGE_LOGS", "EMBED"):
                    embed = discord.Embed()
                    embed.set_author(name=user if hasUser else message.author,
                                     icon_url=user.avatar_url if hasUser else EmptyEmbed)
                    embed.set_footer(
                        text=Translator.translate('sent_in', channel.guild.id, channel=f"#{channel.name}"))
                    embed.add_field(name=Translator.translate('before', channel.guild.id),
                                    value=Utils.trim_message(mc, 1024), inline=False)
                    embed.add_field(name=Translator.translate('after', channel.guild.id),
                                    value=Utils.trim_message(after, 1024), inline=False)
                    GearbotLogging.log_raw(channel.guild.id, "edit_logging", embed=embed)
                else:
                    clean_old = await Utils.clean(mc, channel.guild)
                    clean_new = await Utils.clean(after, channel.guild)
                    GearbotLogging.log_raw(channel.guild.id, "edit_logging", f"**Old:** {clean_old}")
                    GearbotLogging.log_raw(channel.guild.id, "edit_logging", f"**New:** {clean_new}")
            await MessageUtils.update_message(self.bot, event.message_id, after, event.data["pinned"])