async def emoji_edit(self, client, emoji, old): Task(self.old_events['emoji_edit'](client, emoji, old), KOKORO) if self.channel is None: return result = [] result.append( f'Emoji edited: {emoji.name} {emoji.id} at guild {emoji.guild!r}') for key, value in old.items(): if key == 'roles': removed, added = list_difference(value, emoji.roles) if removed: result.append(f'Removed roles: ({len(removed)})') for role in removed: result.append(f'- {role.name} {role.id}') if added: result.append(f'Added roles: ({len(added)})') for role in added: result.append(f'- {role.name} {role.id}') continue result.append(f'{key}: {value} -> {getattr(emoji, key)}') continue pages = [Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages, timeout=120.)
async def guild_user_edit(self, client, user, guild, old): Task(self.old_events['guild_user_edit'](client, user, old, guild), KOKORO) if self.channel is None: return result = [ f'{user.full_name} {user.id} profile was edited at guild {guild.name!r} {guild.id}:' ] profile = user.guild_profiles[guild] for key, value in old.items(): if key in ('nick', 'boosts_since'): result.append( f'{key} changed: {value!r} -> {getattr(profile, key)!r}') continue if key == 'roles': removed, added = list_difference(value, profile.roles) if removed: result.append(f'Roles removed: ({len(removed)})') for role in removed: result.append(f'- {role.name} {role.id}') if added: result.append(f'Roles added: ({len(added)})') for role in added: result.append(f'- {role.name} {role.id}') continue raise RuntimeError(key) pages = [Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages, timeout=120.)
async def channel_edit(self, client, channel, old): print(client, channel, old) Task(self.old_events['channel_edit'](client, channel, old), KOKORO) if self.channel is None: return result = [ f'A channel was edited: {channel.name} {channel.id}\n' f'channel type: {channel.__class__.__name__} ({channel.type})' ] for key, value in old.items(): if key == 'overwrites': removed, added = list_difference(sorted(value), sorted(channel.overwrites)) if removed: result.append(f'Overwrites removed : ({len(removed)})') for value in removed: result.append( f'- {value.target!r} : {value.allow} {value.deny}') if added: result.append(f'Overwrites added: ({len(added)})') for value in added: result.append( f'- {value.target!r} : {value.allow} {value.deny}') continue if key == 'region': other = getattr(channel, key) result.append( f'- {key} : {value!s} {value.value} -> {other!s} {other.value}' ) continue result.append( f'{key} changed: {value!r} -> {getattr(channel, key)!r}') pages = [Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages, timeout=120.)
async def message_edit(self, client, message, old): Task(self.old_events['message_edit'](client, message, old), KOKORO) if self.channel is None: return result = [f'Message {message.id} was edited'] channel = message.channel result.append(f'At channel : {channel:d} {channel.id}') guild = channel.guild if guild is not None: result.append(f'At guild : {guild.name} {guild.id}') if old is None: result.append('The message is uncached, cannot provide changes!') content = message.content content_length = len(content) result.append(f'content: (len={content_length})') if content_length > 500: content = content[:500].replace('`', '\\`') result.append( f'--------------------\n{content}\n... +{content_length-500} more\n--------------------' ) else: content = content.replace('`', '\\`') result.append( f'--------------------\n{content}\n--------------------') else: for key, value in old.items(): if key in ('pinned', 'activity_party_id', 'everyone_mention'): result.append( f'{key} changed: {value!r} -> {getattr(message, key)!r}' ) continue if key in ('edited_at', ): if value is None: result.append( f'{key} changed: None -> {getattr(message, key):%Y.%m.%d-%H:%M:%S}' ) else: result.append( f'{key} changed: {value:%Y.%m.%d-%H:%M:%S} -> {getattr(message, key):%Y.%m.%d-%H:%M:%S}' ) continue if key in ('application', 'activity', 'attachments', 'embeds'): result.append(f'{key} changed:') if value is None: result.append('From None') else: result.extend(pretty_print(value)) value = getattr(message, key) if value is None: result.append('To None') else: result.extend(pretty_print(value)) continue if key in ('content', ): result.append(f'{key} changed from:') content = value break_ = False while True: content_length = len(content) result.append(f'{key}: (len={content_length})') if content_length > 500: content = content[:500].replace('`', '\\`') result.append( f'--------------------\n{content}\n... +{content_length-500} more\n--------------------' ) else: content = content.replace('`', '\\`') result.append( f'--------------------\n{content}\n--------------------' ) if break_: break break_ = True content = getattr(message, key) result.append('To:') continue if key in ('user_mentions', 'role_mentions', 'cross_mentions'): removed, added = list_difference(value, getattr(message, key)) if removed: result.append(f'{key} removed : {len(removed)}') for obj in removed: result.append(f'- {obj.name} {obj.id}') if added: result.append(f'{key} added : {len(added)}') for obj in added: result.append(f'- {obj.name} {obj.id}') continue if key in ('flags', ): old = list(value) old.sort() value = getattr(message, key) new = list(value) new.sort() removed, added = list_difference(old, new) if removed: result.append(f'{key} removed : {len(removed)}') for name in removed: result.append(f'- {name}') if added: result.append(f'{key} added : {len(added)}') for name in added: result.append(f'- {name}') continue # for the new stuff result.append(f'{key} changed:') if value is None: result.append('From None') else: result.extend(repr(value)) value = getattr(message, key) if value is None: result.append('To None') else: result.extend(repr(value)) continue text = cchunkify(result) pages = [Embed(description=chunk) for chunk in text] await Pagination(client, self.channel, pages, timeout=120.)
async def guild_edit(self, client, guild, old): Task(self.old_events['guild_edit'](client, guild, old), KOKORO) if self.channel is None: return result = [f'A guild got edited {guild.name} {guild.id}'] for key, value in old.items(): if key in ( 'name', 'icon', 'invite_splash', 'user_count', 'afk_timeout', 'available', 'description', 'vanity_code', 'banner', 'max_members', 'max_presences', 'premium_tier', 'booster_count', 'widget_enabled', 'preferred_language', 'discovery_splash', 'max_video_channel_users', ): result.append(f'- {key} : {value} - > {getattr(guild, key)}') continue if key in ('verification_level', 'message_notification', 'mfa', 'content_filter', 'region', 'preferred_language'): other = getattr(guild, key) result.append( f'- {key} : {value!s} {value.value} -> {other!s} {other.value}' ) continue if key == 'features': removed, added = list_difference(value, guild.features) if removed: result.append(f'Features removed: ({len(removed)}') for feature in removed: result.append(f'- {feature.value}') if added: result.append(f'Features added: ({len(added)})') for feature in added: result.append(f'- {feature.value}') continue if key in ('system_channel', 'afk_channel', 'widget_channel', 'rules_channel', 'public_updates_channel'): other = getattr(guild, key) if value is None: result.append(f'{key} : None -> {other.name} {other.id}') elif other is None: result.append(f'{key} : {value.name} {value.id} -> None') else: result.append( f'{key} : {value.name} {value.id} -> {other.name} {other.id}' ) continue if key in ('system_channel_flags', ): old = list(value) old.sort() new = list(getattr(guild, key)) new.sort() removed, added = list_difference(old, new) if removed: result.append(f'{key} removed : ({len(removed)})') for name in removed: result.append(f' - {name}') if added: result.append(f'{key} added : ({len(added)})') for name in added: result.append(f' - {name}') continue if key in ('owner', ): other = getattr(guild, 'owner') result.append( f'{key} : {value.full_name} {value.id} -> {other.full_name} {other.id}' ) continue raise RuntimeError(key) pages = [Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages, timeout=120.)