async def History(self, ctx): # Grab the time frame that the user is trying to get their stats from reportLength = " ".join(ctx.message.content.split(" ")[1:]).lower() # grab their username from the database function username = database().searchDefault(ctx.message.author.id, ctx.message.server.id) # create the placeholder for the message that will be sent to the user msg = "" if username == "": await self.bot.say("You must be registered to use this command") return if reportLength == "": msg += "**{}**".format(date.today()) now = datetime.now() day = date.today() # Right here below me, this is where the issue is having two different time libraries is a pain in the ass # To add to that, I have a kinda bad piece of code here that only serves to find out if it is between midnight and 4am if time(0, 00) <= now.time() <= time(4, 00): day = (day - dt.timedelta(days=1)) msg = "**{}**".format(day - dt.timedelta(days=1)) dataThen = database().getStatsXP(username, day) # Week and month are essentially the same thing elif reportLength == "week": compareDate = (date.today() - dt.timedelta(days=7)) msg += "**{}**".format(compareDate) dataThen = database().getStatsXP(username, compareDate) elif reportLength == "month": compareDate = (date.today() - dt.timedelta(days=30)) msg += "**{}**".format(compareDate) dataThen = database().getStatsXP(username, compareDate) # Will just pull from the first available stats that that person has on file elif reportLength == "all": dataThen = database().firstStatsXP(username) msg += "**{}**".format(dataThen[24]) else: await self.bot.say("Accepted timeframes:\n`week`\n`month`\n`all`") return dataNow = beautInfo().userStats(username) try: for x in range(1, 24): info = dataNow[x].split(",") if int(info[2]) > dataThen[x]: msg += "\n`-" + self.labels[x] + ( "." * (20 - len(self.labels[x])) ) + "{:,}".format(int(info[2]) - dataThen[x]) + "`" except TypeError: await self.bot.say( "Your account has not collected enough data to go that far back" ) return emb = embeds.Embed(title=username, description=msg, color=0xc27c0e) discordName = await self.bot.get_user_info(ctx.message.author.id) totXP = "{:,}".format(int(dataNow[0].split(",")[2]) - dataThen[0]) emb.set_footer(text=(str(discordName) + " (" + totXP + "xp)"), icon_url=ctx.message.author.avatar_url) await self.bot.say(embed=emb) return
async def Stats(self, ctx): username = "******".join(ctx.message.content.split(" ")[1:]) if username == "": username = database().searchDefault(ctx.message.author.id,ctx.message.server.id) data = beautInfo().userStats(username) if data == "": await self.bot.say("That username could not be found") return title = "**" + username + "'s stats:**" msg = '' for x in range(0,24): info = data[x].split(",") msg += "`-" + self.labels[x] + ("."*(20-len(self.labels[x]))) + "Lvl: " + info[1] +(" "*(4-len(info[1]))) + " XP: " + "{:,}".format(int(info[2])) + "`\n" emb = embeds.Embed(title=title,description=msg, color=0x206694) await self.bot.say(embed=emb) return
async def Register(self,ctx): discMention = " ".join(ctx.message.content.split(" ")[1:]) await self.bot.say('Register ' + discMention + '?') yesOrNo = await self.bot.wait_for_message(timeout=15.0, author=ctx.message.author, channel=ctx.message.channel) if re.match('([y])|([Y])', yesOrNo.content): await self.bot.say("What is the name of the OSRS account that we are registering to " + discMention + "?") username = await self.bot.wait_for_message(timeout=15.0, author=ctx.message.author, channel=ctx.message.channel) username = username.content print(username) data = beautInfo().userStats(username) if data == "": await self.bot.say("That username could not be found") return #Checks to see if they would like to register this account name await self.bot.say("**Are you sure you would like to register the name {}**\n('yes''Yes''y''Y')".format(username)) yesOrNo = await self.bot.wait_for_message(timeout=15.0, author=ctx.message.author, channel=ctx.message.channel) #Uses regular expressions to see if their response starts with a Y or y if re.match('([y])|([Y])', yesOrNo.content): #Prints out discName = await self.bot.get_user_info(discMention[2:-1].replace("!","")) await self.bot.say("Associating Discord account: **{}**\nOldSchool RuneScape account: **{}**\n".format(discName, username)) #Inserts them into the Database if not database().newUser(discMention[2:-1],username,ctx.message.server.id): await self.bot.say("Something went wrong with registering your DiscordID to this server, contact dev") return inserter = [username] for x in range(0,24): inserter.append(data[x].split(",")[1]) inserter.append(data[x].split(",")[2]) if time(0,00) <= datetime.now().time() <= time(4,00): inserter.append(dt.date.today() - dt.timedelta(days=1)) else: inserter.append(dt.date.today()) if not database().insertStats(inserter): name = database().searchDefault(ctx.message.author.id,ctx.message.server.id) await self.bot.say("That username has been registered with the OldSchool RuneScape account: **{}** in another server\nIf this was your doing, great. If it is not, contact dev.".format(name)) return return else: await self.bot.say("Aborting...") return else: await self.bot.say("Aborting...") return
async def Pie(self,ctx): levels = [] username = "******".join(ctx.message.content.split(" ")[1:]) if username == "": username = database().searchDefault(ctx.message.author.id,ctx.message.server.id) data = beautInfo().userStats(username) if data == "": await self.bot.say("That username does not exist") return for x in range(1,24): levels.append(int(data[x].split(",")[2])) trace = go.Pie( labels=self.labels[1:], values=levels, textinfo="label", showlegend=False, marker=dict( line=dict( color='#000000', width=1.5 ) ), textposition="inside" ) #Sets the layout for the Pie chart, things like a clear background, outlines, font, etc. layout = go.Layout( paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)', width=1000, height=1000, font=dict( family='sans serif', size=26, color='#000000' ) ) #Creates the figure with the data and the layou and then saves the file in the same name as the character #that is being checked. It then submits that picture along with the proper message. #Finally it deletes the picture and returns fig = go.Figure(data=[trace], layout=layout) py.image.save_as(fig, filename=(username + '.png')) await self.bot.say("**" + username + "'s XP breakdown:**\n" ) await self.bot.upload(username + '.png') os.remove((username + '.png'))
async def Flex(self, ctx): #Gets the content after the first space which holds who we are comparing to skill = " ".join(ctx.message.content.split(" ")[1:2]).capitalize() unRec = " ".join(ctx.message.content.split(" ")[2:]) #If they are trying to use it with a default, check for their OSRS username in the database unCaller = database().searchDefault(ctx.message.author.id, ctx.message.server.id) if unCaller == "": await self.bot.say("You must be registered to use this command") return #Attempt to get both of their data from the OSRS highscores website, if either throws an error, then #we will send a message stating that one of the two usernames that was submitted was improper dataCaller = beautInfo().userStats(unCaller) dataRec = beautInfo().userStats(unRec) if dataRec == "": await self.bot.say( "One or both of the usernames provided does not have public highscore data" ) return #Continues to bother the person until they input a proper skill proceed = False while (proceed == False): try: lvlCaller = dataCaller[labels().index(skill)].split(",") proceed = True except ValueError: await self.bot.say( 'Could not find the skill "{}", try again'.format(skill)) try: skill = await self.bot.wait_for_message( timeout=4.0, author=ctx.message.author) skill = skill.content.capitalize() except AttributeError: await self.bot.say("Took too long to respond") return #Attempt to build a bar chart and a taunting message, if fail then state that the skill they input does not exist lvlCaller = dataCaller[labels().index(skill)].split(",") lvlRec = dataRec[labels().index(skill)].split(",") if int(lvlCaller[1]) > int(lvlRec[1]): await self.bot.say( "You ever show off your lvl.%d in %s just to flex on %s?\n**Flex Strength:** %d Levels %s XP" % (int(lvlCaller[1]), skill, unRec, (int(lvlCaller[1]) - int(lvlRec[1])), "{:,}".format( (int(lvlCaller[2]) - int(lvlRec[2]))))) #Traces out the bar chart trace1 = go.Bar(x=[unCaller, unRec], y=[int(lvlCaller[2]), int(lvlRec[2])], text=[ "{:,}".format(int(lvlCaller[2])), "{:,}".format(int(lvlRec[2])) ], textposition='auto', marker=dict(color=['#16a085', '#cb4335'])) #Layout for the bar chart layout = go.Layout(paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)', font=dict(family='sans serif', size=26, color='#ffffff')) #Create the chart, save as image, submit image, delete image fig = go.Figure(data=[trace1], layout=layout) py.image.save_as(fig, filename=(unCaller + '.png')) await self.bot.upload(unCaller + '.png') await self.bot.say("*Sit kid*") os.remove((unCaller + '.png')) return
async def Combat(self, ctx): username = "******".join(ctx.message.content.split(" ")[1:]) if username == "": username = database().searchDefault(ctx.message.author.id,ctx.message.server.id) data = beautInfo().userStats(username) if data == "": self.bot.say("That username was not found") return base = .25*(float(data[2].split(",")[1]) + float(data[4].split(",")[1]) + floor(float(data[6].split(",")[1])/2)) melee = .325*(float(data[1].split(",")[1]) + float(data[3].split(",")[1])) ranged = .325*(floor(float(data[5].split(",")[1])/2) + float(data[5].split(",")[1])) mage = .325*(floor(float(data[7].split(",")[1])/2) + float(data[7].split(",")[1])) comType = ["", ""] if melee > ranged and melee > mage: comType[0] = "Warrior" comType[1] = 'https://vignette.wikia.nocookie.net/2007scape/images/f/fe/Attack_icon.png/revision/latest?cb=20180424002328' base = base + melee elif mage > ranged: comType[0] = "Mage" comType[1] = 'https://vignette.wikia.nocookie.net/2007scape/images/5/5c/Magic_icon.png/revision/latest/scale-to-width-down/21?cb=20180424010803' base = base + mage else: comType[0] = "Ranger" comType[1] = 'https://vignette.wikia.nocookie.net/2007scape/images/1/19/Ranged_icon.png/revision/latest/scale-to-width-down/21?cb=20180424010745' base = base + ranged #Traces out the pie chart for combat breakdown trace = go.Pie( labels=["Attack + Strength","Ranged","Magic"], values=[melee,ranged,mage], textinfo="label", showlegend=False, marker=dict(line=dict(color='#000000', width=1.5)), textposition="inside", domain=dict(x=[0,0.5]) ) #Removing this till fixed or figured out trace1 = go.Bar( x= ["Hitpoints","Defense","Prayer"], y= [ float(data[4].split(",")[1]), float(data[2].split(",")[1]), float(data[6].split(",")[1]) ], text= [ float(data[4].split(",")[1]), float(data[2].split(",")[1]), float(data[6].split(",")[1]) ], textposition = 'auto', showlegend=False, marker=dict(color=['#8b0000','#808080',"#ffff00"]) ) #Sets the layout for the charts layout = go.Layout( paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)', width=2000, height=1000, font=dict( family='sans serif', size=50, color='#000000' ), xaxis=dict(domain=[0.55,1]) ) #Creates the figure, saves that figure as an image, submits the image along with a message about the character then returns fig = go.Figure(data=[trace,trace1], layout=layout) py.image.save_as(fig, filename=(username + '.png')) await self.bot.say("**" + username + "**\n`Combat Type: " + comType[0] + "`\n`Combat Level: " + str(base) + "`") await self.bot.upload(username + '.png') os.remove(username + '.png') return