async def embed_update(self, client, message, flag): Task(self.old_events['embed_update'](client, message, flag), KOKORO) if self.channel is None: return result = [f'Message {message.id} got embed update:'] 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 flag == 3: result.append('Less embeds than before???') else: if flag == 1: result.append('Only sizes were update.') elif flag == 2: result.append('Links! Links everywhere...') embeds = message.embeds if embeds is None: result.append('This should not happen, there are no embeds...') else: if flag == 1: for index, embed in enumerate(embeds, 1): if flag == 1: collected = [] image = embed.image if image is not None: collected.append( ('image.height', image.height)) collected.append(('image.width', image.width)) thumbnail = embed.thumbnail if thumbnail is not None: collected.append( ('thumbnail.height', thumbnail.height)) collected.append( ('thumbnail.width', thumbnail.width)) video = embed.video if video is not None: collected.append( ('video.height', video.height)) collected.append(('video.width', video.width)) if collected: result.append( f'Sizes got update at embed {index}:') for name, value in collected: result.append(f'- {name} : {value}') elif flag == 2: for index, embed in enumerate(embeds, 1): if embed.type in EXTRA_EMBED_TYPES: result.append( f'New embed appeared at index {index}:') result.extend(pretty_print(embed)) text = cchunkify(result) pages = [Embed(description=chunk) for chunk in text] await Pagination(client, self.channel, pages, timeout=120.)
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 = listdifference(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,120.)
async def user_voice_update(self, client, voice_state, old_attributes): Task(self.old_events['user_voice_update'](client, voice_state, old_attributes), KOKORO) if self.channel is None: return result = [] result.append('Voice state update') user = voice_state.user if user.partial: result.append(f'user : Parital user {user.id}') else: result.append(f'user : {user.full_name} ({user.id})') guild = voice_state.channel.guild if guild is not None: result.append(f'guild : {guild.name} ({guild.id})') result.append(f'session_id : {voice_state.session_id!r}') result.append('Changes:') for key, value in old_attributes.items(): if key == 'channel': other = voice_state.channel result.append(f'channel : {value.name} {value.id} -> {other.name} {other.id}') continue result.append(f'{key} : {value} -> {getattr(voice_state, key)}') pages = [Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages, 120.)
async def role_edit(self, client, role, old): Task(self.old_events['role_edit'](client, role, old), KOKORO) if self.channel is None: return result = [f'A role got edited at {role.guild.name} {role.guild.id}\nRole: {role.name} {role.id}'] for key, value in old.items(): if key in ('name', 'separated', 'managed', 'mentionable', 'position',): result.append(f'{key} : {value} -> {getattr(role, key)}') continue if key == 'color': result.append(f'{key} : {value.as_html} -> {role.color.as_html}') continue if key == 'permissions': result.append('permissions :') other = role.permissions for name,index in Permission.__keys__.items(): old_value = (value>>index)&1 new_value = (other>>index)&1 if old_value != new_value: result.append(f'{name} : {bool(old_value)} -> {bool(new_value)}') continue pages=[Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages,120.)
async def user_profile_edit(self,client, user, guild, old): Task(self.old_events['user_profile_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 = listdifference(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,120.)
async def emoji_delete(self,client, emoji, guild): Task(self.old_events['emoji_delete'](client, emoji, guild), KOKORO) if self.channel is None: return result=pretty_print(emoji) result.insert(0, f'Emoji deleted: {emoji.name} {emoji.id} at guild {guild!r}') pages=[Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages,120.)
async def guild_create(self,client, guild): Task(self.old_events['guild_create'](client, guild,), KOKORO) if self.channel is None: return result = pretty_print(guild) result.insert(0, f'Guild created: {guild.id}') pages = [Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages,120.)
async def role_create(self,client,role): Task(self.old_events['role_create'](client,role,), KOKORO) if self.channel is None: return result=pretty_print(role) result.insert(0, f'A role got created at {role.guild.name} {role.guild.id}') pages=[Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages,120.)
async def message_delete(self,client, message): Task(self.old_events['message_delete'](client, message), KOKORO) if self.channel is None: return text = pretty_print(message) text.insert(0, f'Message {message.id} got deleted') pages = [Embed(description=chunk) for chunk in cchunkify(text)] await Pagination(client, self.channel, pages,120.)
async def test_user_data(client, message, user: User): ''' Prints out user data as received json ''' data = await client.http.user_get(user.id) await Pagination(client, message.channel, [ Embed(description=chunk) for chunk in cchunkify( json.dumps(data, indent=4, sort_keys=True).splitlines()) ])
async def invite_delete(self,client,invite): Task(self.old_events['invite_delete'](client, invite), KOKORO) if self.channel is None: return text = pretty_print(invite) text.insert(0, f'Invite deleted:') pages = [Embed(description=chunk) for chunk in cchunkify(text)] await Pagination(client, self.channel, pages,120.)
async def channel_create(self,client,channel): Task(self.old_events['channel_create'](client,channel), KOKORO) if self.channel is None: return result=pretty_print(channel) result.insert(0, f'A channel was created: {channel.name} {channel.id}\nchannel type: {channel.__class__.__name__} ({channel.type})') pages=[Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages,120.)
async def test_get_channel_thread_users(client, message): """ Gets the channel's threads' users probably, no clue. """ data = await client.http.thread_users(message.channel.id) pages = [ Embed(description=chunk) for chunk in cchunkify( json.dumps(data, indent=4, sort_keys=True).splitlines()) ] await Pagination(client, message.channel, pages)
async def test_start_channel_thread(client, message): """ Does a post request to the channel's threads. """ data = await client.http.channel_thread_start(message.channel.id, None) pages = [ Embed(description=chunk) for chunk in cchunkify( json.dumps(data, indent=4, sort_keys=True).splitlines()) ] await Pagination(client, message.channel, pages)
def get_buffer_value(buffer): buffer.seek(0) data = buffer.read() if data: lines = data.split('\n') chunks = cchunkify(lines, lang='py') else: chunks = None return chunks
async def integration_edit(self, client, guild, integration): Task(self.old_events['integration_edit'](client, guild, integration), KOKORO) if self.channel is None: return text = pretty_print(integration) text.insert(0, f'integration_edit at {guild.name} ({guild.id}):') pages = [Embed(description=chunk) for chunk in cchunkify(text)] await Pagination(client, self.channel, pages, 120.)
async def stage_edit(self, client, stage, old_attributes): Task(self.old_events['stage_edit'](client, stage), KOKORO) text = [f'Stage: {stage.id}' f'At: {stage.channel.name}' 'Was edited:'] for attribute_name, attribute_value in old_attributes.items(): text.append( f'`{attribute_name}` : {attribute_value!r} -> {getattr(stage, attribute_name)}' ) pages = [Embed(description=chunk) for chunk in cchunkify(text)] await Pagination(client, self.channel, pages, timeout=120.)
async def integration_update(self, client, guild): Task(self.old_events['integration_update'](client, guild), KOKORO) if self.channel is None: return text = [ f'integration_update at {guild.name} ({guild.id}):', ] pages = [Embed(description=chunk) for chunk in cchunkify(text)] await Pagination(client, self.channel, pages, 120.)
async def test_delete_channel_thread_user(client, message): """ Deletes you to the channel's threads. """ data = await client.http.thread_user_delete(message.channel.id, message.author.id) pages = [ Embed(description=chunk) for chunk in cchunkify( json.dumps(data, indent=4, sort_keys=True).splitlines()) ] await Pagination(client, message.channel, pages)
async def user_voice_leave(self, client, voice_state): Task(self.old_events['user_voice_leave'](client, voice_state), KOKORO) if self.channel is None: return result = [] result.append('User voice leave') result.extend(pretty_print(voice_state)) pages = [Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages, 120.)
async def test_get_eula(client, message): """ Gets an eula. """ data = await client.http.eula_get(542074049984200704) pages = [ Embed(description=chunk) for chunk in cchunkify( json.dumps(data, indent=4, sort_keys=True).splitlines()) ] await Pagination(client, message.channel, pages)
async def test_get_applications_detectable(client, message): """ Requests the detectable applications. """ data = await client.http.applications_detectable() pages = [ Embed(description=chunk) for chunk in cchunkify( json.dumps(data, indent=4, sort_keys=True).splitlines()) ] await Pagination(client, message.channel, pages)
async def user_edit(self,client, user, old): Task(self.old_events['user_edit'](client, user, old), KOKORO) if self.channel is None: return result=[f'A user was updated: {user:f} {user.id}'] for key, value in old. items(): result.append(f'{key} : {value} -> {getattr(user, key)}') pages=[Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages,120.)
async def guild_delete(self,client, guild, profile): Task(self.old_events['guild_delete'](client, guild, profile), KOKORO) if self.channel is None: return result=pretty_print(guild) result.insert(0, f'Guild deleted {guild.id}') result.insert(1, f'I had {len(profile.roles)} roles there') result.insert(2, 'At least i did not boost' if (profile.boosts_since is None) else 'Rip by boost ahhhh...') pages=[Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages,120.)
async def reaction_clear(self,client, message, old): Task(self.old_events['reaction_clear'](client, message, old), KOKORO) if self.channel is None: return if old is None: text = [] else: text = pretty_print(old) text.insert(0, f'Reactions got cleared from message {message.id}:') pages = [Embed(description=chunk) for chunk in cchunkify(text)] await Pagination(client, self.channel, pages,120.)
async def reaction_delete_emoji(self,client, message, emoji, users): Task(self.old_events['reaction_delete_emoji'](client, message, emoji, users), KOKORO) if self.channel is None: return if users is None: text = [] else: text = pretty_print(users) text.insert(0, f'{emoji:e} were removed from message {message.id}:') pages = [Embed(description=chunk) for chunk in cchunkify(text)] await Pagination(client, self.channel, pages,120.)
async def user_presence_update(self, client, user, old): Task(self.old_events['user_presence_update'](client, user, old), KOKORO) if self.channel is None: return result = [f'Presence update on user: {user:f} {user.id}'] try: statuses = old['statuses'] except KeyError: pass else: for key in ('desktop', 'mobile', 'web'): result.append( f'{key} status: {statuses.get(key, Status.offline)} -> {user.statuses.get(key, Status.offline)}' ) try: status = old['status'] except KeyError: pass else: result.append(f'status changed: {status} -> {user.status}') try: activities = old['activities'] except KeyError: pass else: added, updated, removed = activities if (added is not None): for activity in added: result.append('Added activity:') result.extend(pretty_print(activity)) if (updated is not None): for activity_change in updated: result.append('Activity updated:') activity = activity_change.activity for key, value in activity_change.old_attributes.items(): result.append( f'- {key} : {value} -> {getattr(activity, key)}') if (removed is not None): for activity in removed: result.append('Removed activity:') result.extend(pretty_print(activity)) pages = [Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages, timeout=120.)
async def get_guild(client, message): ''' Gets the current guild. ''' guild = message.guild if guild is None: await client.message_create(message.channel, 'Please use this command at a guild.') data = await client.http.guild_get(guild.id) await Pagination(client, message.channel, [ Embed(description=chunk) for chunk in cchunkify( json.dumps(data, indent=4, sort_keys=True).splitlines()) ])
async def typing(self,client,channel, user,timestamp): Task(self.old_events['typing'](client,channel, user,timestamp), KOKORO) if self.channel is None: return result = ['Typing:'] if user.partial: result.append(f'user : Parital user {user.id}') else: result.append(f'user : {user.full_name} ({user.id})') result.append(f'channel : {channel.name} {channel.id}') result.append(f'timestamp : {timestamp:%Y.%m.%d-%H:%M:%S}') pages = [Embed(description=chunk) for chunk in cchunkify(result)] await Pagination(client, self.channel, pages,120.)
async def test_get_welcome_screen(client, message): """ Gets an eula. """ guild = message.guild if guild is None: return data = await client.http.welcome_screen_get(guild.id) pages = [ Embed(description=chunk) for chunk in cchunkify( json.dumps(data, indent=4, sort_keys=True).splitlines()) ] await Pagination(client, message.channel, pages)