Skip to content

Commit

Permalink
[Runescape] Move timestamp outside of masked link
Browse files Browse the repository at this point in the history
Reduce API calls to every 3 minutes instead of every 1 minute, the game rarely updates while you're actively playing anyways
  • Loading branch information
TrustyJAID committed May 9, 2023
1 parent 90bd24d commit 9e96261
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion runescape/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ class Activity:
@classmethod
def from_json(cls, data: dict):
tz = pytz.timezone("Europe/London")
date = datetime.strptime(data.get("date"), "%d-%b-%Y %H:%M")
date_info = data.get("date")
if date_info is not None:
date = datetime.strptime(date_info, "%d-%b-%Y %H:%M")
else:
date = datetime.now()
date = tz.localize(date, is_dst=None).astimezone(timezone.utc)
text = data.get("text")
activity_id = f"{int(date.timestamp())}-{text}"
Expand Down
14 changes: 7 additions & 7 deletions runescape/runescape.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def red_delete_data_for_user(
"""
await self.config.user_from_id(user_id).clear()

@tasks.loop(seconds=60)
@tasks.loop(seconds=180)
async def check_new_metrics(self):
for username, activities in self.metrics.items():
try:
Expand All @@ -92,9 +92,8 @@ async def check_new_metrics(self):
async def post_activity(
self, profile: Profile, channels: Dict[str, int], activity: Activity
) -> None:
timestamp = int(activity.date.timestamp())
url = f"https://apps.runescape.com/runemetrics/app/overview/player/{profile.name}"
msg = f"{profile.name}: {activity.text}\n{activity.details}\n\n<t:{timestamp}>"
msg = f"{profile.name}: {activity.text}\n{activity.details}\n\n"
image_url = None
page = None
if match := KILLED_RE.search(activity.text):
Expand Down Expand Up @@ -127,12 +126,14 @@ async def post_activity(
if not channel.permissions_for(guild.me).send_messages:
continue
if channel.permissions_for(guild.me).embed_links:
em = discord.Embed(description=f"[{msg}]({url})")
em = discord.Embed(
description=f"[{msg}]({url})\n\n" + discord.utils.format_dt(activity.date)
)
if image_url:
em.set_thumbnail(url=image_url)
await channel.send(embed=em)
else:
await channel.send(msg)
await channel.send(msg + "\n\n" + discord.utils.format_dt(activity.date))

@check_new_metrics.before_loop
async def before_checking_metrics(self):
Expand Down Expand Up @@ -185,7 +186,6 @@ async def runescape_wiki(self, ctx: commands.Context, *, search: str):
msg += f"[{title}]({base_url}{page_id})\n"
await ctx.maybe_send_embed(msg)


@runescape.command(name="vis", aliases=["viswax"])
async def runescape_viswax(self, ctx: commands.Context):
"""
Expand Down Expand Up @@ -233,7 +233,7 @@ async def runescape_viswax(self, ctx: commands.Context):
msg += f"__Combination {i+1}__: {slot_1[i]} and either {humanize_list(slot_2[i], style='or')}\n"
msg += _from + "\nhttps://runescape.wiki/w/Rune_Goldberg_Machine"
await ctx.maybe_send_embed(msg)

@runescape.command(name="nemiforest", aliases=["nemi", "forest"])
async def runescape_nemiforest(self, ctx: commands.Context):
"""Display an image of a Nemi Forest instance with all nine nodes."""
Expand Down

0 comments on commit 9e96261

Please sign in to comment.