async def set_embed_with_aliases(self, name, server_id=None): """Create an embed with the aliases of the names of groups or idols sent in""" members = await self.get_idol_where_member_matches_name( name, mode=1, server_id=server_id) groups, group_names = await self.get_group_where_group_matches_name( name, mode=1, server_id=server_id) embed_list = [] count = 0 page_number = 1 embed = discord.Embed(title=f"{name} Aliases Page {page_number}", description="", color=ex.get_random_color()) for member in members: aliases = ', '.join(member.aliases) local_aliases = member.local_aliases.get(server_id) if local_aliases: aliases += ", ".join(local_aliases) embed.add_field( name= f"{member.full_name} ({member.stage_name}) [Idol {member.id}]", value=aliases or "None", inline=True) count += 1 if count == 24: count = 0 page_number += 1 embed_list.append(embed) embed = discord.Embed( title=f"{name} Aliases Page {page_number}", description="", color=ex.get_random_color()) for group in groups: aliases = ', '.join(group.aliases) embed.add_field(name=f"{group.name} [Group {group.id}]", value=aliases or "None", inline=True) count += 1 if count == 24: count = 0 page_number += 1 embed_list.append(embed) embed = discord.Embed( title=f"{name} Aliases Page {page_number}", description="", color=ex.get_random_color()) if count: embed_list.append(embed) return embed_list
async def on_message_user_notifications(message): # user phrase notifications try: if message.author.bot: return message_split = message.content.lower().split(" ") for guild_id, user_id, phrase in ex.cache.user_notifications: if phrase not in message_split or guild_id != message.guild.id: continue if message.author.id == user_id or user_id not in [member.id for member in message.channel.members]: continue log.console(f"message_notifications 1 - {phrase} to {user_id}") dm_channel = await ex.get_dm_channel(user_id) log.console(f"message_notifications 2 - {phrase} to {user_id}") start_loc = (message.content.lower()).find(phrase) end_loc = start_loc + len(phrase) new_message_content = f"{message.content[0:start_loc]}`{message.content[start_loc:end_loc]}`" \ f"{message.content[end_loc:len(message.content)]}" title_desc = f""" Phrase: {phrase} Message Author: {message.author} **Message:** {new_message_content} [Click to go to the Message]({message.jump_url}) """ embed = await ex.create_embed(title="Phrase Found", color=ex.get_random_color(), title_desc=title_desc) await dm_channel.send(embed=embed) except: pass
async def interact_with_user(ctx, user, interaction, interaction_type, self_interaction=False): await ex.u_patreon.reset_patreon_cooldown(ctx) try: if user == discord.Member: user = ctx.author list_of_links = await ex.conn.fetch( "SELECT url FROM general.interactions WHERE interaction = $1", interaction_type) if not self_interaction: if ctx.author.id == user.id: ctx.command.reset_cooldown(ctx) return await ctx.send( f"> **{ctx.author.display_name}, you cannot perform this interaction on yourself.**" ) link = random.choice(list_of_links) embed = discord.Embed( title= f"**{ctx.author.display_name}** {interaction} **{user.display_name}**", color=ex.get_random_color()) if not await ex.u_patreon.check_if_patreon(ctx.author.id): embed.set_footer( text= f"Become a {await ex.get_server_prefix_by_context(ctx)}patreon to get rid of interaction cooldowns!" ) embed.set_image(url=link[0]) return await ctx.send(embed=embed) except Exception as e: log.console(e) return await ctx.send( f"> **{ctx.author.display_name}, there are no links saved for this interaction yet.**" )
async def on_message_notifications(message): try: message_sender = message.author message_guild_id = message.guild.id message_content = message.content if not message_sender.bot: for notification in ex.cache.user_notifications: guild_id = notification[0] user_id = notification[1] phrase = notification[2] message_split = message_content.lower().split(" ") if phrase in message_split and guild_id == message_guild_id and message_sender.id != user_id and user_id in [member.id for member in message.channel.members]: log.console(f"message_notifications 1 - {phrase} to {user_id}") dm_channel = await ex.get_dm_channel(user_id) log.console(f"message_notifications 2 - {phrase} to {user_id}") start_loc = (message_content.lower()).find(phrase) end_loc = start_loc + len(phrase) new_message_content = f"{message_content[0:start_loc]}`{message_content[start_loc:end_loc]}`{message_content[end_loc:len(message_content)]}" title_desc = f""" Phrase: {phrase} Message Author: {message_sender} **Message:** {new_message_content} [Click to go to the Message]({message.jump_url}) """ embed = await ex.create_embed(title="Phrase Found", color=ex.get_random_color(), title_desc=title_desc) await dm_channel.send(embed=embed) except Exception as e: pass
async def lyrics(self, ctx, *, song_query): """Get the lyrics of a song (From https://api.ksoft.si) [Format: %lyrics (song)]""" if not keys.lyric_client: log.console( f"There is no API Key currently set for the Lyrics and the Developer is working on it." ) return await ctx.send( "> **There is no API Key currently set for the Lyrics and the Developer is working on it.**" ) try: results = await keys.lyric_client.music.lyrics(song_query) except keys.ksoftapi.NoResults: log.console(f"No lyrics were found for {song_query}.") return await ctx.send( f"> **No lyrics were found for {song_query}.**") except Exception as e: await ctx.send(f"An error has occurred.") log.console(e) else: song = results[0] if len(song.lyrics) >= 1500: first_page = song.lyrics[0:1500] second_page = song.lyrics[1500:len(song.lyrics)] embed = await ex.create_embed( title=f"{song.name} by {song.artist}", color=ex.get_random_color(), title_desc=first_page, footer_desc= "Thanks for using Irene! Lyrics API is from ksoft.si.") embed2 = await ex.create_embed( title=f"{song.name} by {song.artist}", color=ex.get_random_color(), title_desc=second_page, footer_desc= "Thanks for using Irene! Lyrics API is from ksoft.si.") msg = await ctx.send(embed=embed) return await ex.check_left_or_right_reaction_embed( msg, [embed, embed2]) embed = await ex.create_embed( title=f"{song.name} by {song.artist}", color=ex.get_random_color(), title_desc=song.lyrics, footer_desc= "Thanks for using Irene! Lyrics API is from ksoft.si.") await ctx.send(embed=embed)
async def create_fm_embed(title, stats_info, inline=False, individual=False): """Create and return an embed that matches the format for FM tracks and artists.""" embed = await ex.create_embed(title=title, color=ex.get_random_color()) for info in stats_info: if not individual: embed.add_field(name=info[0], value=info[1], inline=inline) else: embed.description = info[1] return embed
async def set_embed_card_info(self, obj, group=False, server_id=None): """Sets General Information about a Group or Idol.""" if group: title = f"{obj.name} [{obj.id}]\n" card_description = await self.format_card_fields( obj, ex.cache.group_description) else: title = f"{obj.full_name} ({obj.stage_name}) [{obj.id}]\n" card_description = await self.format_card_fields( obj, ex.cache.idol_description) general_description = await self.format_card_fields( obj, ex.cache.general_description) website_description = await self.format_card_fields( obj, ex.cache.website_description) full_description = f"{general_description}" \ f"{card_description}" \ f"{website_description}" embed = await ex.create_embed(title=title, color=ex.get_random_color(), title_desc=full_description) if obj.tags: embed.add_field(name="Tags", value=', '.join(obj.tags), inline=False) if obj.aliases: embed.add_field(name="Aliases", value=', '.join(obj.aliases), inline=False) if obj.local_aliases.get(server_id): embed.add_field(name="Server Aliases", value=', '.join(obj.local_aliases.get(server_id)), inline=False) if group: if obj.members: try: value = f"{' | '.join([f'{(await self.get_member(idol_id)).stage_name} [{idol_id}]' for idol_id in obj.members])}\n" except: value = "This group has an Idol that doesn't exist. Please report it.\n" embed.add_field(name="Members", value=value, inline=False) else: if obj.groups: value = await self.get_group_names_as_string(obj) embed.add_field(name="Groups", value=value) if obj.thumbnail: embed.set_thumbnail(url=obj.thumbnail) if obj.banner: embed.set_image(url=obj.banner) return embed
async def get_idol_post_embed(self, group_id, idol, photo_link, user_id=None, guild_id=None, guessing_game=False, scores=None): """The embed for an idol post.""" if not guessing_game: if not group_id: embed = discord.Embed( title=f"{idol.full_name} ({idol.stage_name}) [{idol.id}]", color=ex.get_random_color(), url=photo_link) else: group = await self.get_group(group_id) embed = discord.Embed( title=f"{group.name} ({idol.stage_name}) [{idol.id}]", color=ex.get_random_color(), url=photo_link) patron_msg = f"Please consider becoming a {await ex.get_server_prefix(guild_id)}patreon." # when user_id is None, the post goes to the dead images channel. if user_id: if not await ex.u_patreon.check_if_patreon(user_id): embed.set_footer(text=patron_msg) else: current_scores = "" if scores: for user_id in scores: current_scores += f"<@{user_id}> -> {scores.get(user_id)}\n" embed = discord.Embed(description=current_scores, color=ex.get_random_color(), url=photo_link) return embed
async def create_fm_embed(title, stats_info, inline=False, individual=False): """Create and return an embed that matches the format for FM tracks and artists.""" embed = await ex.create_embed(title=title, color=ex.get_random_color()) for info in stats_info: # DO NOT SHORTEN FOR LOOP -> stats_info may contain less/more values to unpack than needed. name = info[0] value = info[1] if not individual: embed.add_field(name=name, value=value, inline=inline) else: embed.description = value return embed
async def addinteraction(self, ctx, interaction_type, *, links): """Add a gif/photo to an interaction (ex: slap,kiss,lick,hug) [Format: %addinteraction (interaction) (url,url)""" links = links.split(',') try: if interaction_type.lower() in keys.interaction_list: for url in links: url = url.replace(' ', '') url = url.replace('\n', '') await ex.conn.execute( "INSERT INTO general.interactions(url, interaction) VALUES ($1, $2)", url, interaction_type.lower()) embed = discord.Embed( title=f"**Added {url} to {interaction_type.lower()}**", color=ex.get_random_color()) embed.set_image(url=url) await ctx.send(embed=embed) else: await ctx.send(f"> **Please choose a proper interaction.**") except Exception as e: await ctx.send(f"**ERROR -** {e}") log.console(e)
async def fm(self, ctx, user: typing.Union[discord.User, str] = None): """Get information about a Last FM account by a discord user or a Last FM username. [Format: %fm @user].""" try: user = await self.set_user(ctx, user) if user is not None: response = await ex.get_fm_response('user.getinfo', user) user_info = response['user'] title_desc = f"""Age: {user_info['age']} Country: {user_info['country']} Gender: {user_info['gender']} Name: {user_info['name']} Total PlayCount: {user_info['playcount']} Playlists: {user_info['playlists']} URL: {user_info['url']} """ title = f"{user}'s LastFM Account Info" embed = await ex.create_embed(title=title, color=ex.get_random_color(), title_desc=title_desc) await ctx.send(embed=embed) else: await events.Events.error(ctx, self.user_does_not_exist) except KeyError: await events.Events.error(ctx, self.user_not_found) except Exception as e: log.console(e) await ctx.send( f"> **Something went wrong.. Please {await ex.get_server_prefix_by_context(ctx)}report it.**" )
def create_embed(): return discord.Embed( title=f"{mode} Global/Local Aliases Page {page_number}", color=ex.get_random_color())
async def queue(self, ctx, page_number=1): """Shows Current Queue [Format: %queue]""" try: embed_page_number = 1 current_songs = queued[ctx.guild.id] embed_list = [] counter = 1 set_of_songs = "" total_amount_of_time = 0 for song in current_songs: author_id = song[4] if check_if_player(song[0]): player = song[0] youtube_channel = player.uploader song_name = player.title song_link = player.url duration = player.duration else: video = song[0] youtube_channel = video.get('uploader') song_name = video.get('title') song_link = video.get('webpage_url') duration = video.get('duration') try: try: total_amount_of_time += duration except: pass duration = await ex.u_miscellaneous.get_cooldown_time( duration) except: duration = "N/A" if counter == 1: song_desc = f"[{counter}] **NOW PLAYING:** [{youtube_channel} - {song_name}]({song_link}) - {duration} - Requested by <@{author_id}> \n\n" else: song_desc = f"[{counter}] [{youtube_channel} - {song_name}]({song_link}) - {duration} - Requested by <@{author_id}>\n\n" set_of_songs += song_desc if counter % 10 == 0: embed = discord.Embed( title= f"{ctx.guild.name}'s Music Playlist Page {embed_page_number}", description=set_of_songs, color=ex.get_random_color()) embed = await ex.set_embed_author_and_footer( embed, footer_message="Thanks for using Irene.") set_of_songs = "" embed_list.append(embed) embed_page_number += 1 counter += 1 # if there are not more than 10 songs in queue. embed = discord.Embed( title= f"{ctx.guild.name}'s Music Playlist Page {embed_page_number}", description=set_of_songs, color=ex.get_random_color()) embed = await ex.set_embed_author_and_footer( embed, footer_message="Thanks for using Irene.") embed_list.append(embed) if page_number > len(embed_list): page_number = 1 elif page_number <= 0: page_number = 1 await ex.set_embed_author_and_footer( embed_list[page_number - 1], footer_message= f"Total time of songs queued: {await ex.u_miscellaneous.get_cooldown_time(total_amount_of_time)}" ) msg = await ctx.send(embed=embed_list[page_number - 1]) await ex.check_left_or_right_reaction_embed( msg, embed_list, page_number - 1) except KeyError: await ctx.send(f"> **There are no songs queued in this server.**") except Exception as e: log.console(e) await ctx.send( f"> **Something went wrong.. Please {await ex.get_server_prefix_by_context(ctx)}report it.**" )
async def get_new_embed(desc): return await ex.create_embed(f"Custom Commands for {ctx.guild.name} ({ctx.guild.id})", color=ex.get_random_color(), title_desc=desc)
async def set_embed_card_info(self, obj, group=False, server_id=None): """Sets General Information about a Group or Idol.""" description = "" if obj.description: description += f"{obj.description}\n\n" if obj.id: description += f"ID: {obj.id}\n" if obj.gender: description += f"Gender: {obj.gender}\n" if group: title = f"{obj.name} [{obj.id}]\n" if obj.name: description += f"Name: {obj.name}\n" if obj.debut_date: description += f"Debut Date: {obj.debut_date}\n" if obj.disband_date: description += f"Disband Date: {obj.disband_date}\n" if obj.fandom: description += f"Fandom Name: {obj.fandom}\n" if obj.company: description += f"Company: {obj.company}\n" if obj.website: description += f"[Official Website]({obj.website})\n" else: title = f"{obj.full_name} ({obj.stage_name}) [{obj.id}]\n" if obj.full_name: description += f"Full Name: {obj.full_name}\n" if obj.stage_name: description += f"Stage Name: {obj.stage_name}\n" if obj.former_full_name: description += f"Former Full Name: {obj.former_full_name}\n" if obj.former_stage_name: description += f"Former Stage Name: {obj.former_stage_name}\n" if obj.birth_date: description += f"Birth Date: {obj.birth_date}\n" if obj.birth_country: description += f"Birth Country: {obj.birth_country}\n" if obj.birth_city: description += f"Birth City: {obj.birth_city}\n" if obj.height: description += f"Height: {obj.height}cm\n" if obj.zodiac: description += f"Zodiac Sign: {obj.zodiac}\n" if obj.blood_type: description += f"Blood Type: {obj.blood_type}\n" if obj.called: description += f"Called: {obj.called} times\n" description += f"GuessingGame Difficulty: {obj.difficulty}\n" if obj.twitter: description += f"[Twitter](https://twitter.com/{obj.twitter})\n" if obj.youtube: description += f"[Youtube](https://www.youtube.com/channel/{obj.youtube})\n" if obj.melon: description += f"[Melon](https://www.melon.com/artist/song.htm?artistId={obj.melon})\n" if obj.instagram: description += f"[Instagram](https://instagram.com/{obj.instagram})\n" if obj.vlive: description += f"[V Live](https://channels.vlive.tv/{obj.vlive})\n" if obj.spotify: description += f"[Spotify](https://open.spotify.com/artist/{obj.spotify})\n" if obj.fancafe: description += f"[FanCafe](https://m.cafe.daum.net/{obj.fancafe})\n" if obj.facebook: description += f"[Facebook](https://www.facebook.com/{obj.facebook})\n" if obj.tiktok: description += f"[TikTok](https://www.tiktok.com/{obj.tiktok})\n" if obj.photo_count: description += f"Photo Count: {obj.photo_count}\n" embed = await ex.create_embed(title=title, color=ex.get_random_color(), title_desc=description) if obj.tags: embed.add_field(name="Tags", value=', '.join(obj.tags), inline=False) if obj.aliases: embed.add_field(name="Aliases", value=', '.join(obj.aliases), inline=False) if obj.local_aliases.get(server_id): embed.add_field(name="Server Aliases", value=', '.join(obj.local_aliases.get(server_id)), inline=False) if group: if obj.members: try: value = f"{' | '.join([f'{(await self.get_member(idol_id)).stage_name} [{idol_id}]' for idol_id in obj.members])}\n" except: value = "This group has an Idol that doesn't exist. Please report it.\n" embed.add_field(name="Members", value=value, inline=False) else: if obj.groups: value = await self.get_group_names_as_string(obj) embed.add_field(name="Groups", value=value) if obj.thumbnail: embed.set_thumbnail(url=obj.thumbnail) if obj.banner: embed.set_image(url=obj.banner) return embed