119 lines
4.5 KiB
Python
119 lines
4.5 KiB
Python
|
import discord
|
||
|
from discord.ext import commands
|
||
|
import asyncio
|
||
|
import runescapeapi
|
||
|
import json
|
||
|
from concurrent.futures import ThreadPoolExecutor
|
||
|
import functools
|
||
|
|
||
|
with open('rs_emojis.json', 'r') as f:
|
||
|
emojis = json.load(f)
|
||
|
|
||
|
|
||
|
tpe = ThreadPoolExecutor()
|
||
|
|
||
|
|
||
|
async def execute(func, *args, **kwargs):
|
||
|
partial = functools.partial(func, *args, **kwargs)
|
||
|
loop = asyncio.get_event_loop()
|
||
|
return await loop.run_in_executor(tpe, partial)
|
||
|
|
||
|
|
||
|
class runescape:
|
||
|
def __init__(self, bot):
|
||
|
self.bot = bot
|
||
|
|
||
|
@commands.command(pass_context=True)
|
||
|
async def profile(self, ctx, *, rsn=""):
|
||
|
"""returns the runescape stats of a given rsn"""
|
||
|
this = runescapeapi.Player(rsn)
|
||
|
em = discord.Embed()
|
||
|
try:
|
||
|
em.set_author(name="RuneMetrics profile of: {}"
|
||
|
.format(await execute(this.rsn)))
|
||
|
except LookupError:
|
||
|
await self.bot.send_message(ctx.message.channel,
|
||
|
'No profile found')
|
||
|
return
|
||
|
levels = await execute(this.stats)
|
||
|
left = ''
|
||
|
for c, i in enumerate(levels, 1):
|
||
|
left += f"{emojis[i['name']]}{i['level']}"
|
||
|
if c % 3 == 0:
|
||
|
left += '\n'
|
||
|
em.add_field(name="Levels", value=left, inline=True)
|
||
|
q_ = await execute(this.quest_summary)
|
||
|
overalltotal = await execute(this.overall_total)
|
||
|
combat = await execute(this.combat)
|
||
|
clan = await execute(this.clan)
|
||
|
title = await execute(this.title)
|
||
|
try:
|
||
|
quest_total = sum(q_.values())
|
||
|
except TypeError:
|
||
|
quest_total = None
|
||
|
right = f'**Quests:** {q_["complete"]}/{quest_total} ' \
|
||
|
f'({q_["started"]} in progress)\n' \
|
||
|
f'**Rank:** {overalltotal["rank"]}\n' \
|
||
|
f'**Total level:** {overalltotal["level"]}\n' \
|
||
|
f'**Total xp:** {overalltotal["xp"]:,}\n' \
|
||
|
f'**Combat level:** {combat["combatlevel"]}\n' \
|
||
|
f'**Clan:** {clan}\n' \
|
||
|
f'**Title:** {title["title"]}'
|
||
|
em.add_field(name='Info', value=right, inline=True)
|
||
|
em.set_thumbnail(url=await execute(this.forum_pic))
|
||
|
await self.bot.say(embed=em)
|
||
|
activities = await execute(this.alog)
|
||
|
if activities == []:
|
||
|
return
|
||
|
act = ""
|
||
|
for a in activities[:10]:
|
||
|
act = act + f'**{a["date"]}** {a["text"]}\n' \
|
||
|
f'```{" ".join(a["details"].split())}```'
|
||
|
await self.bot.say(act)
|
||
|
act = ""
|
||
|
for a in activities[10:]:
|
||
|
act = act + f'**{a["date"]}** {a["text"]}\n' \
|
||
|
f'```{" ".join(a["details"].split())}```'
|
||
|
await self.bot.say(act)
|
||
|
|
||
|
@commands.command(pass_context=True)
|
||
|
async def map(self, ctx):
|
||
|
url = 'http://167.99.150.82/maps/tiles/2_0_{}_{}.png'
|
||
|
x = 51
|
||
|
y = 50
|
||
|
em = discord.Embed()
|
||
|
em.set_image(url=url.format(x, y))
|
||
|
msg = await self.bot.say(embed=em)
|
||
|
await self.bot.add_reaction(msg, '⬆')
|
||
|
await self.bot.add_reaction(msg, '⬇')
|
||
|
await self.bot.add_reaction(msg, '⬅')
|
||
|
await self.bot.add_reaction(msg, '➡')
|
||
|
while True:
|
||
|
r = await self.bot.wait_for_reaction(message=msg,
|
||
|
user=ctx.message.author,
|
||
|
emoji=['⬆', '⬇', '⬅', '➡'])
|
||
|
if r.reaction.emoji == '⬆':
|
||
|
y = y + 1
|
||
|
em.set_image(url=url.format(x, y))
|
||
|
await self.bot.remove_reaction(msg, '⬆', ctx.message.author)
|
||
|
await self.bot.edit_message(msg, embed=em)
|
||
|
elif r.reaction.emoji == '⬇':
|
||
|
y = y - 1
|
||
|
em.set_image(url=url.format(x, y))
|
||
|
await self.bot.remove_reaction(msg, '⬇', ctx.message.author)
|
||
|
await self.bot.edit_message(msg, embed=em)
|
||
|
elif r.reaction.emoji == '⬅':
|
||
|
x = x - 1
|
||
|
em.set_image(url=url.format(x, y))
|
||
|
await self.bot.remove_reaction(msg, '⬅', ctx.message.author)
|
||
|
await self.bot.edit_message(msg, embed=em)
|
||
|
elif r.reaction.emoji == '➡':
|
||
|
x = x + 1
|
||
|
em.set_image(url=url.format(x, y))
|
||
|
await self.bot.remove_reaction(msg, '➡', ctx.message.author)
|
||
|
await self.bot.edit_message(msg, embed=em)
|
||
|
|
||
|
|
||
|
def setup(bot):
|
||
|
bot.add_cog(runescape(bot))
|