async def set_status(self, ctx, status, status_name="Playing", status_type=0, status_url=None): # Only allow owner if not await Utils.is_owner_reply(ctx): return if status == status_url == None: self.settings.setGlobalStat('Game',None) self.settings.setGlobalStat('Stream',None) self.settings.setGlobalStat('Type',0) msg = 'Removing my {} status...'.format(status_name.lower()) message = await ctx.send(msg) await self._update_status() return await message.edit(content='{} status removed!'.format(status_name)) if status_type == 1: if not status: return await ctx.send("You need to provide a url if streaming!") if not any("twitch.tv" in x.lower() for x in Utils.get_urls(ctx)): return await ctx.send("You need to provide a valid twitch.tv url for streaming!") self.settings.setGlobalStat('Game',status) self.settings.setGlobalStat('Stream',status_url) self.settings.setGlobalStat('Type',status_type) msg = 'Setting my {} status to *{}*...'.format(status_name.lower(), status) message = await ctx.send(Utils.suppressed(ctx,msg)) await self._update_status() await message.edit(content='{} status set to **{}**{}!'.format(status_name,Utils.suppressed(ctx,status)," at `{}`".format(status_url) if status_url else ""))
async def add_to_queue(self, ctx, url, shuffle = False): queue = self.queue.get(str(ctx.guild.id),[]) url = url.strip('<>') # Check if url - if not, remove / urls = Utils.get_urls(url) url = urls[0] if len(urls) else "ytsearch:"+url.replace('/', '') tracks = await self.bot.wavelink.get_tracks(url) if tracks == None: return None tracks = tracks[0] if (url.startswith("ytsearch:") or isinstance(tracks,list)) and len(tracks) else tracks player = self.bot.wavelink.get_player(ctx.guild.id) if isinstance(tracks,wavelink.Track): # Only got one item - add it to the queue tracks.info["added_by"] = ctx.author tracks.info["ctx"] = ctx tracks.info["search"] = url # Let's also get the seek position if needed try: seek_str = next((x[2:] for x in url.split("?")[1].split("&") if x.lower().startswith("t=")),"0").lower() values = [x for x in re.split("(\\d+)",seek_str) if x] # We should have a list of numbers and non-numbers. Let's total the values total_time = 0 last_type = "s" # Assume seconds in case no value is given for x in values[::-1]: if not x.isdigit(): # Save the type last_type = x continue # We have a digit, let's calculate and add our time # Only factor hours, minutes, seconds - anything else is ignored if last_type == "h": total_time += int(x) * 3600 elif last_type == "m": total_time += int(x) * 60 elif last_type == "s": total_time += int(x) seek_pos = total_time except Exception as e: seek_pos = 0 tracks.info["seek"] = seek_pos queue.append(tracks) self.queue[str(ctx.guild.id)] = queue if not player.is_playing and not player.paused: self.bot.dispatch("next_song",ctx) return tracks # Have more than one item - iterate them tracks.search = url try: starting_index = next((int(x[6:])-1 for x in url.split("?")[1].split("&") if x.lower().startswith("index=")),0) except: starting_index = 0 starting_index = 0 if starting_index >= len(tracks.tracks) or starting_index < 0 else starting_index # Ensure we're not out of bounds tracks.tracks = tracks.tracks[starting_index:] if shuffle: random.shuffle(tracks.tracks) # Shuffle before adding for index,track in enumerate(tracks.tracks): track.info["added_by"] = ctx.author track.info["ctx"] = ctx queue.append(track) self.queue[str(ctx.guild.id)] = queue if index == 0 and not player.is_playing and not player.paused: self.bot.dispatch("next_song",ctx) return tracks
async def set_status(self, ctx, status, status_name="Playing", status_type=0, status_url=None): # Only allow owner if not await Utils.is_owner_reply(ctx): return if status == status_url == None: self.settings.setGlobalStat('Game', None) self.settings.setGlobalStat('Stream', None) self.settings.setGlobalStat('Type', 0) msg = 'Removing my {} status...'.format(status_name.lower()) em = discord.Embed(color=0XFF8C00, description=msg) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) message = await ctx.send(embed=em) await self._update_status() msg = "Status {} dihapus!".format(status_name) em = discord.Embed(color=0XFF8C00, description=msg) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) return await message.edit(embed=em) if status_type == 1: if not status: msg = "Kamu membutuhkan url jika mengubah mode streaming!" em = discord.Embed(color=0XFF8C00, description=msg) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) return await ctx.send(embed=em) if not any("twitch.tv" in x.lower() for x in Utils.get_urls(ctx)): msg = "Kamu membutuhkan url dari twitch.tv untuk streaming!" em = discord.Embed(color=0XFF8C00, description=msg) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) return await ctx.send(embed=em) self.settings.setGlobalStat('Game', status) self.settings.setGlobalStat('Stream', status_url) self.settings.setGlobalStat('Type', status_type) msg = 'Merubah status {},\nmenjadi status *{}*...'.format( status_name.lower(), status) em = discord.Embed(color=0XFF8C00, description=msg) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) message = await ctx.send(embed=em) #message = await ctx.send(Utils.suppressed(ctx,msg)) await self._update_status() msg = 'Status {} berhasil dirubah ke **{}**{}!'.format( status_name, Utils.suppressed(ctx, status), " at `{}`".format(status_url) if status_url else "") em = discord.Embed(color=0XFF8C00, description=msg) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) await message.edit(embed=em)
async def pres(self, ctx, playing_type="0", status_type="online", game=None, url=None): """Merubah bot presence (owner-only). Option untuk playing type: 0. Playing (atau None tanpa game) 1. Streaming (membutuhkan valid twitch URL) 2. Listening 3. Watching Option untuk status type: 1. Online 2. Idle 3. DnD 4. Invisible If any of the passed entries have spaces, they must be in quotes.""" if not await Utils.is_owner_reply(ctx): return # Check playing type play = None play_string = "" if playing_type.lower() in ["0", "play", "playing"]: play = 0 play_string = "Playing" elif playing_type.lower() in ["1", "stream", "streaming"]: play = 1 play_string = "Streaming" if url == None or not any("twitch.tv" in x.lower() for x in Utils.get_urls(url)): # Guess what - you failed!! :D msg = "Kamu membutuhkan url twitch.tv untuk memasang status streaming!" em = discord.Embed(color=0XFF8C00, description=msg) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) return await ctx.send(embed=em) elif playing_type.lower() in ["2", "listen", "listening"]: play = 2 play_string = "Listening" elif playing_type.lower() in ["3", "watch", "watching"]: play = 3 play_string = "Watching" # Verify we got something if play == None: # NOooooooooaooOOooOOooope. msg = "Playing type is invalid!" em = discord.Embed(color=0XFF8C00, description=msg) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) return await ctx.send(embed=em) # Clear the URL if we're not streaming if not play == 1: url = None # Check status type stat = None stat_string = "" if status_type.lower() in ["1", "online", "here", "green"]: stat = "1" stat_string = "Online" elif status_type.lower() in ["2", "idle", "away", "gone", "yellow"]: stat = "2" stat_string = "Idle" elif status_type.lower() in [ "3", "dnd", "do not disturb", "don't disturb", "busy", "red" ]: stat = "3" stat_string = "Do Not Disturb" elif status_type.lower() in [ "4", "offline", "invisible", "ghost", "gray", "black" ]: stat = "4" stat_string = "Invisible" # Verify we got something if stat == None: # OHMYGODHOWHARDISITTOFOLLOWDIRECTIONS?!?!? "Status type is invalid!" em = discord.Embed(color=0XFF8C00, description=msg) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) return await ctx.send(embed=em) # Here, we assume that everything is A OK. Peachy keen. # Set the shiz and move along self.settings.setGlobalStat("Game", game) self.settings.setGlobalStat("Stream", url) self.settings.setGlobalStat("Status", stat) self.settings.setGlobalStat("Type", play) # Actually update our shit await self._update_status() # Let's formulate a sexy little response concoction inline = True await Message.Embed(title="Presence Update", color=ctx.author, fields=[{ "name": "Game", "value": str(game), "inline": inline }, { "name": "Status", "value": stat_string, "inline": inline }, { "name": "Type", "value": play_string, "inline": inline }, { "name": "URL", "value": str(url), "inline": inline }]).send(ctx)
async def addemoji(self, ctx, *, emoji=None, name=None): '''Adds the passed emoji, url, or attachment as a custom emoji with the passed name (bot-admin only, max of 10).''' if not await Utils.is_bot_admin_reply(ctx): return if not len(ctx.message.attachments) and emoji == name == None: return await ctx.send( "Usage: `{}addemoji [emoji, url, attachment] [name]`".format( ctx.prefix)) # Let's find out if we have an attachment, emoji, or a url # Check attachments first - as they'll have priority if len(ctx.message.attachments): name = emoji emoji = " ".join([x.url for x in ctx.message.attachments]) if name: # Add the name separated by a space emoji += " " + name # Now we split the emoji string, and walk it, looking for urls, emojis, and names emojis_to_add = [] last_name = [] for x in emoji.split(): # Check for a url urls = Utils.get_urls(x) if len(urls): url = (urls[0], os.path.basename(urls[0]).split(".")[0]) else: # Check for an emoji url = self._get_emoji_url(x) if not url: # Gotta be a part of the name - add it last_name.append(x) continue if len(emojis_to_add) and last_name: # Update the previous name if need be emojis_to_add[-1][1] = "".join([ z for z in "_".join(last_name) if z.isalnum() or z == "_" ]) # We have a valid url or emoji here - let's make sure it's unique if not url[0] in [x[0] for x in emojis_to_add]: emojis_to_add.append([url[0], url[1]]) # Reset last_name last_name = [] if len(emojis_to_add) and last_name: # Update the final name if need be emojis_to_add[-1][1] = "".join( [z for z in "_".join(last_name) if z.isalnum() or z == "_"]) if not emojis_to_add: return await ctx.send( "Usage: `{}addemoji [emoji, url, attachment] [name]`".format( ctx.prefix)) # Now we have a list of emojis and names added_emojis = [] allowed = len(emojis_to_add) if len( emojis_to_add) <= self.max_emojis else self.max_emojis omitted = " ({} omitted, beyond the limit of {})".format( len(emojis_to_add) - self.max_emojis, self.max_emojis) if len(emojis_to_add) > self.max_emojis else "" message = await ctx.send("Adding {} emoji{}{}...".format( allowed, "" if allowed == 1 else "s", omitted)) for emoji_to_add in emojis_to_add[:self.max_emojis]: # Let's try to download it emoji, e_name = emoji_to_add # Expand into the parts f = await GetImage.download(emoji) if not f: continue # Open the image file with open(f, "rb") as e: image = e.read() # Clean up GetImage.remove(f) if not e_name.replace("_", ""): continue # Create the emoji and save it try: new_emoji = await ctx.guild.create_custom_emoji( name=e_name, image=image, roles=None, reason="Added by {}#{}".format(ctx.author.name, ctx.author.discriminator)) except: continue added_emojis.append(new_emoji) msg = "Created {} of {} emoji{}{}.".format(len(added_emojis), allowed, "" if allowed == 1 else "s", omitted) if len(added_emojis): msg += "\n\n" emoji_text = [ "{} - `:{}:`".format(self._get_emoji_mention(x), x.name) for x in added_emojis ] msg += "\n".join(emoji_text) await message.edit(content=msg)
async def pres(self, ctx, playing_type="0", status_type="online", game=None, url=None): """Changes the bot's presence (owner-only). Playing type options are: 0. Playing (or None without game) 1. Streaming (requires valid twitch url) 2. Listening 3. Watching Status type options are: 1. Online 2. Idle 3. DnD 4. Invisible If any of the passed entries have spaces, they must be in quotes.""" if not await Utils.is_owner_reply(ctx): return # Check playing type play = None play_string = "" if playing_type.lower() in ["0", "play", "playing"]: play = 0 play_string = "Playing" elif playing_type.lower() in ["1", "stream", "streaming"]: play = 1 play_string = "Streaming" if url == None or not any("twitch.tv" in x.lower() for x in Utils.get_urls(url)): # Guess what - you failed!! :D return await ctx.send( "You need a valid twitch.tv url to set a streaming status!" ) elif playing_type.lower() in ["2", "listen", "listening"]: play = 2 play_string = "Listening" elif playing_type.lower() in ["3", "watch", "watching"]: play = 3 play_string = "Watching" # Verify we got something if play == None: # NOooooooooaooOOooOOooope. return await ctx.send("Playing type is invalid!") # Clear the URL if we're not streaming if not play == 1: url = None # Check status type stat = None stat_string = "" if status_type.lower() in ["1", "online", "here", "green"]: stat = "1" stat_string = "Online" elif status_type.lower() in ["2", "idle", "away", "gone", "yellow"]: stat = "2" stat_string = "Idle" elif status_type.lower() in [ "3", "dnd", "do not disturb", "don't disturb", "busy", "red" ]: stat = "3" stat_string = "Do Not Disturb" elif status_type.lower() in [ "4", "offline", "invisible", "ghost", "gray", "black" ]: stat = "4" stat_string = "Invisible" # Verify we got something if stat == None: # OHMYGODHOWHARDISITTOFOLLOWDIRECTIONS?!?!? return await ctx.send("Status type is invalid!") # Here, we assume that everything is A OK. Peachy keen. # Set the shiz and move along self.settings.setGlobalStat("Game", game) self.settings.setGlobalStat("Stream", url) self.settings.setGlobalStat("Status", stat) self.settings.setGlobalStat("Type", play) # Actually update our shit await self._update_status() # Let's formulate a sexy little response concoction inline = True await Message.Embed(title="Presence Update", color=ctx.author, fields=[{ "name": "Game", "value": str(game), "inline": inline }, { "name": "Status", "value": stat_string, "inline": inline }, { "name": "Type", "value": play_string, "inline": inline }, { "name": "URL", "value": str(url), "inline": inline }]).send(ctx)
async def addemoji(self, ctx, *, emoji=None, name=None): '''Menambahkan emoji (bot-admin only, maksimal 10 dalam 1 command) Dengan format berupa: • Attachment Gambar (Upload gambar) • Link URL • Atau emoji dari server lain (lebih mudah untuk pengguna nitro)''' if not await Utils.is_bot_admin_reply(ctx): return if not len(ctx.message.attachments) and emoji == name == None: em = discord.Embed( color=0XFF8C00, description="> Upload emoji gak usak pake ribet\n> \n" "> **Panduan pengunaan**\n" "> `{}addemoji [emoji server lain, url, attachment] [name]`". format(ctx.prefix)) em.set_author( name="Help command", url="https://acinonyxesports.com/", icon_url= "https://cdn.discordapp.com/attachments/518118753226063887/725569194304733435/photo.jpg" ) em.set_footer( text= f"Saat mengetik command, tanda [] tidak usah digunakan.\nRequest By : {ctx.author.name}", icon_url=f"{ctx.author.avatar_url}") return await ctx.send(embed=em) # Let's find out if we have an attachment, emoji, or a url # Check attachments first - as they'll have priority if len(ctx.message.attachments): name = emoji emoji = " ".join([x.url for x in ctx.message.attachments]) if name: # Add the name separated by a space emoji += " " + name # Now we split the emoji string, and walk it, looking for urls, emojis, and names emojis_to_add = [] last_name = [] for x in emoji.split(): # Check for a url urls = Utils.get_urls(x) if len(urls): url = (urls[0], os.path.basename(urls[0]).split(".")[0]) else: # Check for an emoji url = self._get_emoji_url(x) if not url: # Gotta be a part of the name - add it last_name.append(x) continue if len(emojis_to_add) and last_name: # Update the previous name if need be emojis_to_add[-1][1] = "".join([ z for z in "_".join(last_name) if z.isalnum() or z == "_" ]) # We have a valid url or emoji here - let's make sure it's unique if not url[0] in [x[0] for x in emojis_to_add]: emojis_to_add.append([url[0], url[1]]) # Reset last_name last_name = [] if len(emojis_to_add) and last_name: # Update the final name if need be emojis_to_add[-1][1] = "".join( [z for z in "_".join(last_name) if z.isalnum() or z == "_"]) em = discord.Embed( color=0XFF8C00, description="> Upload emoji gak usak pake ribet\n> \n" "> **Panduan pengunaan**\n" "> `{}addemoji [emoji server lain, url, attachment] [nama]`". format(ctx.prefix)) em.set_author( name="Help command", url="https://acinonyxesports.com/", icon_url= "https://cdn.discordapp.com/attachments/518118753226063887/725569194304733435/photo.jpg" ) em.set_footer( text= f"Saat mengetik command, tanda [] tidak usah digunakan.\nRequest By : {ctx.author.name}", icon_url=f"{ctx.author.avatar_url}") if not emojis_to_add: return await ctx.send(embed=em) # Now we have a list of emojis and names added_emojis = [] allowed = len(emojis_to_add) if len( emojis_to_add) <= self.max_emojis else self.max_emojis omitted = " ({} gambar dihilangkan, karena melebihi batas maksimal {})".format( len(emojis_to_add) - self.max_emojis, self.max_emojis) if len(emojis_to_add) > self.max_emojis else "" message = await ctx.send("Menambahkan {} emoji{}{}...".format( allowed, "" if allowed == 1 else "", omitted)) for emoji_to_add in emojis_to_add[:self.max_emojis]: # Let's try to download it emoji, e_name = emoji_to_add # Expand into the parts f = await GetImage.download(emoji) if not f: continue # Open the image file with open(f, "rb") as e: image = e.read() # Clean up GetImage.remove(f) if not e_name.replace("_", ""): continue # Create the emoji and save it try: new_emoji = await ctx.guild.create_custom_emoji( name=e_name, image=image, roles=None, reason="Added by {}#{}".format(ctx.author.name, ctx.author.discriminator)) except: continue added_emojis.append(new_emoji) msg = "Membuat {} dari {} emoji{}{}.".format( len(added_emojis), allowed, "" if allowed == 1 else "", omitted) if len(added_emojis): msg += "\n\n" emoji_text = [ "{} - `:{}:`".format(self._get_emoji_mention(x), x.name) for x in added_emojis ] msg += "\n".join(emoji_text) em = discord.Embed(color=0XFF8C00, description=msg) em.set_author( name="Berhasil menambahkan emoji", url="https://acinonyxesports.com/", icon_url= "https://cdn.discordapp.com/attachments/518118753226063887/725569194304733435/photo.jpg" ) em.set_footer(text=f"Request By : {ctx.author.name}", icon_url=f"{ctx.author.avatar_url}") await message.edit(embed=em)
async def add_to_queue(self, ctx, url, message, shuffle = False): delay = self.settings.getServerStat(ctx.guild, "MusicDeleteDelay", 20) queue = self.queue.get(str(ctx.guild.id),[]) url = url.strip('<>') # Check if url - if not, remove / urls = Utils.get_urls(url) url = urls[0] if len(urls) else "ytsearch:"+url.replace('/', '') tracks = await self.bot.wavelink.get_tracks(url) if tracks == None: return None if (url.startswith("ytsearch:") or isinstance(tracks,list)) and len(tracks): if self.settings.getServerStat(ctx.guild, "YTMultiple", False): # We want to let the user pick list_show = "Please select the number of the track you'd like to add:" index, message = await PickList.Picker( title=list_show, list=[x.info['title'] for x in tracks[:5]], ctx=ctx, message=message ).pick() if index < 0: if index == -3: await message.edit(content="Something went wrong :(",delete_after=delay) elif index == -2: await message.edit(content="Times up! We can search for music another time.",delete_after=delay) else: await message.edit(content="Aborting! We can search for music another time.",delete_after=delay) return False # Got the index of the track to add tracks = tracks[index] else: # We only want the first entry tracks = tracks[0] # tracks = tracks[0] if (url.startswith("ytsearch:") or isinstance(tracks,list)) and len(tracks) else tracks player = self.bot.wavelink.get_player(ctx.guild.id) if isinstance(tracks,wavelink.Track): # Only got one item - add it to the queue tracks.info["added_by"] = ctx.author tracks.info["ctx"] = ctx tracks.info["search"] = url # Let's also get the seek position if needed try: seek_str = next((x[2:] for x in url.split("?")[1].split("&") if x.lower().startswith("t=")),"0").lower() values = [x for x in re.split("(\\d+)",seek_str) if x] # We should have a list of numbers and non-numbers. Let's total the values total_time = 0 last_type = "s" # Assume seconds in case no value is given for x in values[::-1]: if not x.isdigit(): # Save the type last_type = x continue # We have a digit, let's calculate and add our time # Only factor hours, minutes, seconds - anything else is ignored if last_type == "h": total_time += int(x) * 3600 elif last_type == "m": total_time += int(x) * 60 elif last_type == "s": total_time += int(x) seek_pos = total_time except Exception as e: seek_pos = 0 tracks.info["seek"] = seek_pos queue.append(tracks) self.queue[str(ctx.guild.id)] = queue if not player.is_playing and not player.paused: self.bot.dispatch("next_song",ctx) return tracks # Have more than one item - iterate them tracks.search = url try: starting_index = next((int(x[6:])-1 for x in url.split("?")[1].split("&") if x.lower().startswith("index=")),0) except: starting_index = 0 starting_index = 0 if starting_index >= len(tracks.tracks) or starting_index < 0 else starting_index # Ensure we're not out of bounds tracks.tracks = tracks.tracks[starting_index:] if shuffle: random.shuffle(tracks.tracks) # Shuffle before adding for index,track in enumerate(tracks.tracks): track.info["added_by"] = ctx.author track.info["ctx"] = ctx queue.append(track) self.queue[str(ctx.guild.id)] = queue if index == 0 and not player.is_playing and not player.paused: self.bot.dispatch("next_song",ctx) return tracks