Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Merge pull request #136 from NabDev/dev
Browse files Browse the repository at this point in the history
v1.7.1
  • Loading branch information
Galarzaa90 committed Oct 13, 2018
2 parents fe4c9ae + b0e8938 commit 625d9dd
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## Version 1.7.1 (2018-10-12)
- Fixed links in `/about` command.
- Combine walks through fields and walks around fields into a single embed field.
- Added user caching to `/deaths`, `/levels` and `/timeline` because it was causing connection timeouts.

## Version 1.7.0 (2018-09-26)
- Improved death scanning times
- Server admins can bypass event limit on their servers
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ NabBot uses the following branching model:
- `feat-*` - Used to implement features that require extended development, to isolate the environment and be able to keep updating the other branches.
- `release-*` - This branch is only used to prepare for releases. Final tests, documentation and version updates are done here before merging into `master`.


![Example Brancing Model](https://nvie.com/img/git-model@2x.png)
4 changes: 2 additions & 2 deletions cogs/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, bot: NabBot):
async def about(self, ctx: NabCtx):
"""Shows basic information about the bot."""
embed = discord.Embed(description=ctx.bot.description, colour=discord.Colour.blurple())
embed.set_author(name="NabBot", url="https://github.com/Galarzaa90/NabBot",
embed.set_author(name="NabBot", url="https://github.com/NabDev/NabBot",
icon_url="https://github.com/fluidicon.png")
prefixes = list(config.command_prefix)
if ctx.guild:
Expand All @@ -46,7 +46,7 @@ async def about(self, ctx: NabCtx):
embed.add_field(name="Links", inline=False,
value=f"[Add to your server](https://dbl.nabbot.xyz/) | "
f"[Support Server](https://support.nabbot.xyz/) | "
f"[Docs](https://nabbot.xyz/) | "
f"[Docs](https://docs.nabbot.xyz/) | "
f"[Donate](https://donate.nabbot.xyz/)")
embed.set_footer(text=f"Uptime | {parse_uptime(self.bot.start_time, True)}")
await ctx.send(embed=embed)
Expand Down
46 changes: 32 additions & 14 deletions cogs/tibia.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ async def deaths(self, ctx: NabCtx, *, name: str = None):
return

if ctx.is_private:
user_guilds = self.bot.get_user_guilds(ctx.author.id)
user_servers = self.bot.get_user_guilds(ctx.author.id)
user_worlds = self.bot.get_user_worlds(ctx.author.id)
else:
user_guilds = [ctx.guild]
user_servers = [ctx.guild]
user_worlds = [self.bot.tracked_worlds.get(ctx.guild.id)]
if user_worlds[0] is None and name is None:
await ctx.send("This server is not tracking any tibia worlds.")
Expand All @@ -132,6 +132,7 @@ async def deaths(self, ctx: NabCtx, *, name: str = None):
now = time.time()
show_links = not ctx.long
per_page = 20 if ctx.long else 5
users_cache = dict()
try:
if name is None:
title = "Latest deaths"
Expand All @@ -143,11 +144,13 @@ async def deaths(self, ctx: NabCtx, *, name: str = None):
row = c.fetchone()
if row is None:
break
user = self.bot.get_member(row["user_id"], user_guilds)
if user is None:
continue
if row["world"] not in user_worlds:
continue

user = self._get_cached_user_(self, row["user_id"], users_cache, user_servers)
if user is None:
continue

count += 1
row["time"] = get_time_diff(dt.timedelta(seconds=now - row["date"]))
row["user"] = user.display_name
Expand Down Expand Up @@ -724,10 +727,10 @@ async def levels(self, ctx: NabCtx, *, name: str=None):
return

if ctx.is_private:
user_guilds = self.bot.get_user_guilds(ctx.author.id)
user_servers = self.bot.get_user_guilds(ctx.author.id)
user_worlds = self.bot.get_user_worlds(ctx.author.id)
else:
user_guilds = [ctx.guild]
user_servers = [ctx.guild]
user_worlds = [self.bot.tracked_worlds.get(ctx.guild.id)]
if user_worlds[0] is None:
await ctx.send("This server is not tracking any tibia worlds.")
Expand All @@ -741,6 +744,7 @@ async def levels(self, ctx: NabCtx, *, name: str=None):
now = time.time()
per_page = 20 if ctx.long else 5
await ctx.channel.trigger_typing()
user_cache = dict()
try:
if name is None:
title = "Latest level ups"
Expand All @@ -752,11 +756,13 @@ async def levels(self, ctx: NabCtx, *, name: str=None):
row = c.fetchone()
if row is None:
break
user = self.bot.get_member(row["user_id"], user_guilds)
if user is None:
continue
if row["world"] not in user_worlds:
continue

user = self._get_cached_user_(self, row["user_id"], user_cache, user_servers)
if user is None:
continue

count += 1
row["time"] = get_time_diff(dt.timedelta(seconds=now - row["date"]))
row["user"] = user.display_name
Expand All @@ -771,7 +777,7 @@ async def levels(self, ctx: NabCtx, *, name: str=None):
await ctx.send("I don't have a character with that name registered.")
return
# If user doesn't share a server with the owner, don't display it
owner = self.bot.get_member(result["user_id"], user_guilds)
owner = self.bot.get_member(result["user_id"], user_servers)
if owner is None:
await ctx.send("I don't have a character with that name registered.")
return
Expand Down Expand Up @@ -1288,6 +1294,7 @@ async def timeline(self, ctx: NabCtx, *, name: str = None):
now = time.time()
per_page = 20 if ctx.long else 5
await ctx.channel.trigger_typing()
user_cache = dict()
try:
if name is None:
title = "Timeline"
Expand All @@ -1303,11 +1310,13 @@ async def timeline(self, ctx: NabCtx, *, name: str = None):
row = c.fetchone()
if row is None:
break
user = self.bot.get_member(row["user_id"], user_servers)
if user is None:
continue
if row["world"] not in user_worlds:
continue

user = self._get_cached_user_(self, row["user_id"], user_cache, user_servers)
if user is None:
continue

count += 1
row["time"] = get_time_diff(dt.timedelta(seconds=now - row["date"]))
row["user"] = user.display_name
Expand Down Expand Up @@ -2055,6 +2064,15 @@ async def scan_news(self):
except Exception:
log.exception("Task: scan_news")

@staticmethod
def _get_cached_user_(self, user_id, users_cache, user_servers):
if user_id in users_cache:
return users_cache.get(user_id)
else:
member_user = self.bot.get_member(user_id, user_servers)
users_cache[user_id] = member_user
return member_user

def __unload(self):
print("cogs.tibia: Cancelling pending tasks...")
self.news_announcements_task.cancel()
Expand Down
19 changes: 14 additions & 5 deletions cogs/tibiawiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,19 @@ def get_monster_embed(ctx: NabCtx, monster, long):
TibiaWiki._set_monster_embed_elem_modifiers(embed, monster, TibiaWiki._get_monster_elemental_modifiers())
TibiaWiki._set_monster_embed_bestiary(embed, monster)
TibiaWiki._set_monster_embed_damage(embed, long, monster)
TibiaWiki._set_monster_embed_walks(embed, monster, "Walks Through", "walksthrough")
TibiaWiki._set_monster_embed_walks(embed, monster, "Walks Around", "walksaround")
TibiaWiki._set_monster_embed_walks(embed, monster)
TibiaWiki._set_monster_embed_abilities(embed, monster)
TibiaWiki._set_monster_embed_loot(embed, long, monster)
TibiaWiki._set_monster_embed_more_info(ctx, embed, long, monster)
return embed

@staticmethod
def _set_monster_embed_walks(embed, monster):
content = TibiaWiki._get_content_monster_walks(monster, "Through: ", "walksthrough")
content = TibiaWiki._get_content_monster_walks(monster, "Around: ", "walksaround", content)
if content:
embed.add_field(name="Field Walking", value=content, inline=True)

@staticmethod
def _get_monster_elemental_modifiers():
"""Returns the elemental modifiers available for monsters."""
Expand All @@ -476,11 +482,14 @@ def _set_monster_embed_more_info(ctx, embed, long, monster):
embed.set_footer(text="To see more, PM me{0}.".format(askchannel_string))

@staticmethod
def _set_monster_embed_walks(embed, monster, embed_field_name, attribute_name):
def _get_content_monster_walks(monster, walk_field_name, attribute_name, content=""):
"""Adds the embed field describing which elemnts the monster walks around or through."""
attribute_value = str(monster[attribute_name])
if attribute_value is not None and not attribute_value.lower().__contains__("none"):
content = ""
if content:
content += "\n"
content += walk_field_name

if config.use_elemental_emojis:
walks_elements = []
for element in TibiaWiki._get_elements_monster_walks():
Expand All @@ -491,7 +500,7 @@ def _set_monster_embed_walks(embed, monster, embed_field_name, attribute_name):
content += f"{config.elemental_emojis[element]}"
else:
content += attribute_value
embed.add_field(name=embed_field_name, value=content, inline=True)
return content

@staticmethod
def _set_monster_embed_abilities(embed, monster):
Expand Down
2 changes: 1 addition & 1 deletion nabbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self):
# A list version is created from the dictionary
self.tracked_worlds = {}
self.tracked_worlds_list = []
self.__version__ = "1.7.0"
self.__version__ = "1.7.1"
self.__min_discord__ = 1580

async def on_ready(self):
Expand Down
1 change: 0 additions & 1 deletion requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mkdocs
mkdocs-material
pymdown-extensions
git+https://github.com/jdittrich/figureAltCaption.git

0 comments on commit 625d9dd

Please sign in to comment.