async def smashmain(self, ctx, *, arg): ''' Modifies the smash main of the author. Case sensitive. Use !smash characters to see the character format. Usage: !smashmain Luigi ''' await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) await jsondb.load_users(self) arg = arg.split(';') main = check_secondaries(arg) if not main: embed = create_embed( 'smashmain error: Incorrect format for main. ', 'You did not input a smash character. Try the sschar command to see correct format.', RED) await ctx.send(embed=embed, delete_after=20) return userid = str(ctx.author.id) self.users[userid]['SmashProfile']['Main'] = main await jsondb.save_users(self) await ctx.send('**{}** has modified their mains!'.format(ctx.author))
async def switchcode(self, ctx, *, arg): ''' Modifies the switchcode of the author. Requires a 12 digit switchcode. Usage: !switchcode 123412341234 ''' await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) await jsondb.load_users(self) arg = shlex.split(arg) switchcode = arg[0] if len(switchcode) != 12: embed = create_embed('smashcode error: Bad Switch Code ', 'The length of a switch code is 12 digits.', RED) await ctx.send(embed=embed, delete_after=20) return else: switchcode = fix_switch_code(switchcode) userid = str(ctx.author.id) self.users[userid]['SmashProfile']['SwitchCode'] = switchcode await jsondb.save_users(self) await ctx.send('**{}** has modified their switchcode!'.format( ctx.author))
async def shoprem(self, ctx, index: str): await jsondb.load_shop(self) await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) author = ctx.author serverid = str(ctx.guild.id) guild = ctx.guild if not author.guild_permissions.administrator: await ctx.send( 'Sorry good sir, you do not have permission to modify the database!', delete_after=10) return if serverid not in self.shop: return await ctx.send( "Sorry, there is no shop set up on this server!", delete_after=15) if index not in self.items: return await ctx.send("Sorry, that item does not exist!") if index not in self.shop[serverid]['Inventory']: return await ctx.send("This shop does not sell this item!") self.shop[serverid]['Inventory'].remove(index) await jsondb.save_shop(self) await ctx.send( "The item: **{}**, has been added to the **{}** shop!".format( self.items[index]['ItemName'], guild.name))
async def help(self, ctx, *, arg=None): """Lists all modules for the bot.""" await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) author = ctx.author if arg is None: embed = discord.Embed(title="Server Modules") list = "" for cog in self.bot.cogs: name = cog + "\n" list = list + name embed.add_field( name= "Here are the bot's server modules. Do !help modulename to get all of their commands and a description. ", value=list) return await ctx.send(embed=embed) cog = self.bot.get_cog(arg) if not cog: return await ctx.send("Module does not exist!") commands = cog.get_commands() embed = discord.Embed(title="Server Commands") i = 1 list = "" for command in commands: name = str(i) + ". **" + command.name + '** ' + "\n" list = list + name i = i + 1 embed.add_field( name="Here are the commands for the **{}** module.".format(arg), value=list) await ctx.send(embed=embed)
async def all_items(self, ctx): await jsondb.load_shop(self) await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) userid = str(ctx.message.author.id) if not userid in self.users: await ctx.send('**{}**, you do not have a profile currently!') itemnames = '' itemtypes = '' itemids = '' for item in self.items: itemids = itemids + self.items[item]['ItemID'] + '\n' itemnames = itemnames + self.items[item]['ItemName'] + '\n' itemtypes = itemtypes + self.items[item]['ItemType'] + '\n' embed = discord.Embed( title="{}'s Inventory".format(ctx.message.author.name)) embed.add_field(name='Item ID', value=itemids, inline=True) embed.add_field(name='Item Name', value=itemnames, inline=True) embed.add_field(name='Item Type', value=itemtypes, inline=True) await ctx.send(embed=embed, delete_after=20)
async def osu(self, ctx, *, arg): """ Provides basic stats of the given user, if they exist. Uses Renondedju's Osu.py library https://github.com/Renondedju/Osu.py Example: !osu Leftyy """ await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) #recent5 = await api.get_user_recents(user=arg,limit = 5) user = await api.get_user(user=arg) if not user: await ctx.send("Sorry, **{}** is not an Osu Player!".format(arg)) return playcount = str(user.playcount) pp_rank = str(user.pp_rank) level = str(user.level) accuracy = str(user.accuracy) image = 'http://s.ppy.sh/a/' + str(user.user_id) embed = discord.Embed(title="{}".format(arg), description="osu stats for this user!", color=0x008000) embed.set_thumbnail(url=image) embed.add_field(name='Level:', value=level, inline=True) embed.add_field(name='Playcount:', value=playcount, inline=True) embed.add_field(name='Rank:', value=pp_rank, inline=True) embed.add_field(name='Accuracy:', value=accuracy, inline=True) await ctx.send(embed=embed)
async def setcoins(self, ctx, member: discord.Member = None, coins: int = 0): """ Sets coins to a user. Requires admin privileges to execute this command. Use !givecoins to give coins of a specific amount to a user. Usage: !setcoins @Lefty#6430 50 !sc @Lefty#6430 50 """ jsondb.load_users(self) await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) if member is None: return await ctx.send( '**{]**, you must target a user first before using this command.', delete_after=20) userid = str(member.id) self.users[userid]['Coins'] = coins await jsondb.save_users(self) await ctx.send( "**{}**, you now have a balance of **{}** Coins!".format( member, coins))
async def shopbuy(self, ctx, index: str): await jsondb.load_shop(self) await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) author = ctx.author serverid = str(ctx.guild.id) authorid = str(ctx.author.id) if serverid not in self.shop: return await ctx.send( "Sorry, there is no shop set up on this server!", delete_after=15) if index not in self.items: return await ctx.send("Sorry, that item does not exist!") if index not in self.shop[serverid]['Inventory']: return await ctx.send("This shop does not sell this item!") if self.users[authorid]['Coins'] - int(self.items[index]['Price']) < 0: return await ctx.send( "Sorry, you do not have enough to purchase that!") self.users[authorid]['Coins'] = self.users[authorid]['Coins'] - int( self.items[index]['Price']) self.users[authorid]['Inventory'].append(index) await jsondb.save_users(self) await ctx.send("**{}** has purchased **{}** for **{}** coins.".format( author.name, self.items[index]['ItemName'], self.items[index]['Price']))
async def choose(self, ctx, *, arg): await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) choices = arg.split(';') N = randint(0, len(choices) - 1) await ctx.send(choices[N])
async def vote(self, ctx, vote: int = 0): ''' Vote on one of the poll options on the server, if the option and poll exists. Usage: !vote 1 !vote 4 ''' await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) serverid = ctx.message.guild.id authorid = ctx.message.author.id try: if self.poll[serverid] is not None: if authorid in self.pollvoters[serverid]: return await ctx.send( '**{}**, you have already voted on this poll. Please wait until the next one.' .format(ctx.message.author), delete_after=10) vote = vote - 1 try: self.pollstats[serverid][ vote] = self.pollstats[serverid][vote] + 1 self.pollvoters[serverid].append(ctx.message.author.id) return await ctx.send( 'You have voted on the option: **{}**'.format( self.poll[serverid][vote + 1])) except IndexError: return await ctx.send('That is not an option on the poll.') except KeyError: return await ctx.send("There is no poll going on right now.")
async def smash_delete(self, ctx, user: discord.Member = None): ''' Deletes the smash profile of the author. If a user is specified, then the author requires admin privileges. Usage: !deletesmash !deletesmash @Lefty#6430 ''' await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) await jsondb.load_users(self) if not ctx.author.guild_permissions.administrator: embed = create_embed( '!deletesmash error: No permission.', 'You must have admin privileges to do this command', GREEN) await ctx.send(embed=embed, delete_after=20) return if user is None: userid = ctx.author.id else: userid = user.id self.users[userid]['SmashProfile'] = { 'Name': '', 'SwitchCode': '', 'Main': '', 'Secondaries': [] } await jsondb.save_users await ctx.send("**{}**'s Smash Profile has been wiped.")
async def dota_wordcloud(self, ctx, member: discord.Member = None): await jsondb.load_users(self) await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) if member is None: userid = str(ctx.message.author.id) else: userid = str(member.id) STEAMID = self.users[userid]['DotaProfile']['Steam32id'] if not STEAMID: return await ctx.send("You do not have a STEAMID linked to you!", delete_after=10) request = requests.get( 'https://api.opendota.com/api/players/{}/wordcloud?api_key={}'. format(STEAMID, dota_api_key)) js = request.json() wordcounts = js['my_word_counts'] wordcounts = sorted(wordcounts.items(), key=operator.itemgetter(1), reverse=True) print(wordcounts) msg = '' i = 0 while i != 10: msg = msg + wordcounts[i][0] + ': ' + str(wordcounts[i][1]) + ' \n' i = i + 1 await ctx.send( 'Here are the top 10 words for **{}** \n'.format(ctx.author) + msg, delete_after=10)
async def smashbros(self, ctx, *, arg=None): await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) reddit = praw.Reddit(client_id=reddit_client, client_secret=reddit_secret, user_agent=user_agent) titles = [] links = [] if arg is None: for submission in reddit.subreddit('smashbros').hot(limit=5): titles.append(submission.title) links.append(submission.url) elif arg == 'controversial' or arg == 'contro': for submission in reddit.subreddit('smashbros').controversial( 'week', limit=5): titles.append(submission.title) links.append(submission.url) elif arg == 'gild' or arg == 'gilded': for submission in reddit.subreddit('smashbros').gilded('week', limit=5): titles.append(submission.title) links.append(submission.url) elif arg == 'hot': for submission in reddit.subreddit('smashbros').hot(limit=5): titles.append(submission.title) links.append(submission.url) elif arg == 'new': for submission in reddit.subreddit('smashbros').new('week', limit=5): titles.append(submission.title) links.append(submission.url) elif arg == 'rise' or arg == 'rising': for submission in reddit.subreddit('smashbros').rising('week', limit=5): titles.append(submission.title) links.append(submission.url) elif arg == 'top': for submission in reddit.subreddit('smashbros').top('week', limit=5): titles.append(submission.title) links.append(submission.url) else: for submission in reddit.subreddit('smashbros').hot('week', limit=5): titles.append(submission.title) links.append(submission.url) title = '' i = 0 while i != 5: title = title + '**' + titles[i] + ':** ' + links[i] + '\n' i = i + 1 title = title + "**This post will be deleted after 30 seconds.**" await ctx.send(title)
async def smashregion(self, ctx, *, arg): await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) await jsondb.load_users(self) userid = str(ctx.author.id) self.users[userid]['SmashProfile']['Region'] = arg await jsondb.save_users(self) await ctx.send('**{}** has modified their region.'.format(ctx.author))
async def flip(self, ctx): """Flips a coin.""" await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) N = randint(1, 2) if N == 1: await ctx.send("_**Heads.**_") else: await ctx.send("_**Tails.**_")
async def osu5(self, ctx, *, arg): """ Find the top 5 beatmaps of the given user. Uses Renondedju's Osu.py library https://github.com/Renondedju/Osu.py Usage: !osu5 Leftyy """ await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) user = await api.get_user(user=arg) image = 'http://s.ppy.sh/a/' + str(user.user_id) if not user: await ctx.send("Sorry, **{}** is not an Osu Player!".format(arg)) return best5 = await api.get_user_bests(user=arg, limit=5) osubest = [] for best in best5: beatmap = await api.get_beatmap(beatmap_id=best.beatmap_id) beatmap_title = beatmap.title beatmap_id = beatmap.beatmapset_id beatmap_diff = best.beatmap_id creator = beatmap.creator osutuple = [ beatmap_title, str(best.score), str(best.maxcombo), str(best.pp), str(beatmap_id), str(beatmap_diff), creator ] osubest.append(osutuple) embed = discord.Embed(title="{}".format(arg), description="Top 5 Plays!", color=0x008000) embed.set_thumbnail(url=image) for bestmap in osubest: link = "https://osu.ppy.sh/beatmapsets/" + bestmap[ 4] + "#osu/" + bestmap[5] + ')' title = bestmap[0] + ' by ' + bestmap[6] + ': ' together = title + link info = '**Score:** ' + bestmap[1] + ' **Max Combo:** ' + bestmap[ 2] + ' **PP: **' + bestmap[3] embed.add_field(name=together, value=info) await ctx.send(embed=embed)
async def viewprofiles(self, ctx): ''' Shows all of the smash profiles currently on the server. Usage: !smashprofiles ''' await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) await jsondb.load_users(self) server = ctx.message.guild members = ctx.guild.members name = "" switchcode = "" main = "" for member in members: try: memberid = str(member.id) if self.users[memberid]['SmashProfile']['Tag'] is None: continue name = name + self.users[memberid]['SmashProfile']['Tag'] + "\n" switchcode = switchcode + self.users[memberid]['SmashProfile'][ 'SwitchCode'] + "\n" mains = self.users[memberid]['SmashProfile']['Main'] #TODO Make their mains into their icons instead of just the name. try: main = main + mains[0] + "\n" except IndexError: continue except KeyError: continue if name is None: embed = create_embed('No users!', 'There are no users! Interesting..', RED) await ctx.send(embed=embed, delete_after=20) return embed = csmash_embed(name, switchcode, main, server.name) if check_embed_limits(embed): #TODO Create multiple embeds when embed limit is exceeded embed = create_embed('Embed limit exceeded!', 'There are no users! Interesting..', RED) await ctx.send(embed=embed) return else: await ctx.send(embed=embed)
async def youtube(self, ctx, *, arg): """ Searches Youtube for the given search, and returns the first video given. """ await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) yt = YouTubeDataAPI(google_key) lmao = yt.search(arg) print(lmao[0]) pog = lmao[0] link = 'https://www.youtube.com/watch?v=' + pog['video_id'] await ctx.send(link)
async def smashpocket(self, ctx, *, arg=''): await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) await jsondb.load_users(self) arg = arg.split(';') secondarylist = check_secondaries(arg) if not secondarylist: secondarylist = [''] userid = str(ctx.author.id) self.users[userid]['SmashProfile']['Pockets'] = secondarylist await jsondb.save_users(self) await ctx.send('**{}** has modified their pockets!'.format(ctx.author))
async def woof(self, ctx): """ Generate a doggo from dog.ceo """ await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) r = requests.get('https://dog.ceo/api/breeds/image/random') js = r.json() em = discord.Embed(color=GREEN) em.set_image(url=js['message']) await ctx.send(embed=em)
async def dotahelp(self, ctx): await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) author = ctx.author msg = """To setup a dota profile, you first need to link up your Steam32id. To get that, I reccommend you use https://steamid.xyz/ to get it. Then, you simply use the !setsteam command. !setsteam 97985854 Then you can see your profile as well as others with !dota. Use !help Dota to see all of the dota commands. """ await ctx.send(msg)
async def urban(self, ctx, *, arg): ''' Retrieves the first urban dictionary result for the given argument. ''' await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) query = 'http://api.urbandictionary.com/v0/define?term={}'.format( urllib.parse.quote_plus(arg)) r = requests.get(query) js = r.json() result = js['list'][0]['definition'] await ctx.send('**{}**: '.format(arg) + result)
async def get_avatar(self, ctx, member: discord.Member = None): ''' Retrieves the avatar of a user. ''' await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) if member is None: avatar_url = ctx.author.avatar_url_as(static_format='png') else: avatar_url = member.avatar_url_as(static_format='png') await ctx.send(avatar_url)
async def smashcolor(self, ctx, *, Colour): await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) await jsondb.load_users(self) colorString = Colour Colour = re.search(r'^0x(?:[0-9a-fA-F]{3}){1,2}$', Colour) if not Colour: return await ctx.send( "**{}**, you did not provide a color in hex format.".format( ctx.author)) userid = str(ctx.author.id) self.users[userid]['SmashProfile']['Colour'] = colorString await jsondb.save_users(self) await ctx.send('**{}** has modified their colour.'.format(ctx.author))
async def cat(self, ctx): """ Generate a random cat from random.cat/meow """ await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) r = requests.get('http://aws.random.cat/meow') print(r) js = r.json() print(js) em = discord.Embed(color=GREEN) em.set_image(url=js['file']) await ctx.send(embed=em)
async def time(self, ctx, *, arg): """ Retrieves the timezone for the given location. Utilizes geocoders and tzwhere. """ await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) g = geocoders.GoogleV3(api_key=google_key) place, (lat, lng) = g.geocode(arg) tz = tzwhere.tzwhere() timezone = g.timezone(lat, lng) await ctx.send('The time in **{}** is: **{}**'.format(place, timezone))
async def randommatch(self, ctx): """ Get a random match from the Dr.Wily Database. Usage: !recentmatch """ await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) await ctx.send('Invalid format. Try using an actual link.', delete_after=20) return try: response = requests.get( 'https://mm8bitdm-v2.herokuapp.com/api/randommatch') js = response.json() response.raise_for_status() except HTTPError as http_err: print(f'HTTP error occurred: {http_err}') return await ctx.send("Random match having some issue.") link = js['image'].replace(" ", "%20").replace('\\', "/") image = 'https://farisalkhat.github.io/DrWilyDB/' + link match_url = 'https://farisalkhat.github.io/DrWilyDB/matches/' + str( js['matchid']) stage = js['stage'] stageid = js['stageid'] embed = discord.Embed(title="{}".format(js['gametitle']), description='Game Mode: {}'.format( js['gamemode']), url=match_url, color=0x008000) embed.set_image(url=image) embed.add_field(name='Total Players:', value=js['totalplayers'], inline=True) embed.add_field( name='Stage:', value="[{}](https://farisalkhat.github.io/DrWilyDB/stages/{})". format(stage, stageid), inline=True) await ctx.send(embed=embed) return
async def delete_id(self, ctx): """ Delete the STEAMID associated with the author. Usage: !steamdelete """ await jsondb.load_users(self) await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) userid = str(ctx.author.id) self.users[userid]['DotaProfile'] = {'Name': '', 'Steam32id': ''} await jsondb.save_users(self) await ctx.send("**{}** has wiped their STEAMID.".format( ctx.message.author), delete_after=10)
async def drwilydb(self, ctx): """ Simply sends the link to the Dr.Wily Database site. Made by Faris Al-khatahtbeh :3 Usage: !drwilydb """ await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION, delete_after=10) await ctx.send('Invalid format. Try using an actual link.', delete_after=20) return await ctx.send(website) return
async def newbalance(self, ctx, member: discord.Member = None): await jsondb.load_users(self) await jsondb.load_servers(self) if jsondb.permission(self, ctx) is False: return await ctx.send(jsondb.NOPERMISSION) if member is None: userid = str(ctx.message.author.id) user = ctx.author else: userid = str(member.id) user = member if not userid in self.users: await ctx.send('**{}**, you do not have a profile currently!') coins = self.users[userid]['Coins'] await ctx.send('**{}** currently has **{} Coins**.'.format( user, coins), delete_after=10)