From 2d30681eb6dd2abdbd9c46e664975b3bf2a7fa06 Mon Sep 17 00:00:00 2001 From: Rodolfo Forte Date: Sat, 29 Sep 2018 19:22:20 +0200 Subject: [PATCH 1/9] Fix links on /about --- cogs/info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/info.py b/cogs/info.py index 5b6a9b1..7383348 100644 --- a/cogs/info.py +++ b/cogs/info.py @@ -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: @@ -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) From 3c51e35d9b3d6e5494ed1571252b112be7febd05 Mon Sep 17 00:00:00 2001 From: Rodolfo Forte Date: Sat, 29 Sep 2018 20:30:07 +0200 Subject: [PATCH 2/9] Merge walks around/through into one field --- cogs/tibiawiki.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/cogs/tibiawiki.py b/cogs/tibiawiki.py index 7fe8ca7..2168c13 100644 --- a/cogs/tibiawiki.py +++ b/cogs/tibiawiki.py @@ -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.""" @@ -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(): @@ -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): From d29ad86d4490a69c6a5d6047923fca504b93ac97 Mon Sep 17 00:00:00 2001 From: Rodolfo Forte Date: Tue, 9 Oct 2018 00:02:06 +0200 Subject: [PATCH 3/9] Add caching to /deaths users --- cogs/tibia.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cogs/tibia.py b/cogs/tibia.py index dcb5256..61a4d26 100644 --- a/cogs/tibia.py +++ b/cogs/tibia.py @@ -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 = dict() try: if name is None: title = "Latest deaths" @@ -143,9 +144,19 @@ 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) + + user = users.get(row["user_id"]) + if user is False: + continue if user is None: + user = self.bot.get_member(row["user_id"], user_guilds) + + if user is None: + users[row["user_id"]] = False continue + else: + users[row["user_id"]] = user + if row["world"] not in user_worlds: continue count += 1 From 348010b6f145a0af63e358065cf240173cfcd9c5 Mon Sep 17 00:00:00 2001 From: Rodolfo Forte Date: Tue, 9 Oct 2018 19:40:12 +0200 Subject: [PATCH 4/9] Enhance caching of users on /deaths --- cogs/tibia.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/cogs/tibia.py b/cogs/tibia.py index 61a4d26..d68a72b 100644 --- a/cogs/tibia.py +++ b/cogs/tibia.py @@ -132,7 +132,8 @@ 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 = dict() + users_cache = dict() + user_unknown = "unknown" try: if name is None: title = "Latest deaths" @@ -144,21 +145,13 @@ async def deaths(self, ctx: NabCtx, *, name: str = None): row = c.fetchone() if row is None: break - - user = users.get(row["user_id"]) - if user is False: + if row["world"] not in user_worlds: continue - if user is None: - user = self.bot.get_member(row["user_id"], user_guilds) - if user is None: - users[row["user_id"]] = False + user = self._get_cached_user_(self, row["user_id"], user_unknown, users_cache, user_guilds) + if user == user_unknown: continue - else: - users[row["user_id"]] = user - if row["world"] not in user_worlds: - continue count += 1 row["time"] = get_time_diff(dt.timedelta(seconds=now - row["date"])) row["user"] = user.display_name @@ -232,6 +225,15 @@ async def deaths(self, ctx: NabCtx, *, name: str = None): except CannotPaginate as e: await ctx.send(e) + @staticmethod + def _get_cached_user_(self, user_id, user_unknown, users_cache, user_guilds): + cached_user = users_cache.get(user_id) + if cached_user is None: + member_user = self.bot.get_member(user_id, user_guilds) + cached_user = user_unknown if member_user is None else member_user + users_cache[user_id] = cached_user + return cached_user + @deaths.command(name="monster", aliases=["mob", "killer"]) @checks.is_in_tracking_world() async def deaths_monsters(self, ctx: NabCtx, *, name: str): From a946b2b91cd634356dac52cfb405c53750f9dfc8 Mon Sep 17 00:00:00 2001 From: Rodolfo Forte Date: Tue, 9 Oct 2018 20:41:26 +0200 Subject: [PATCH 5/9] Add the same caching to both /timeline and /levels --- cogs/tibia.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/cogs/tibia.py b/cogs/tibia.py index d68a72b..6e77b49 100644 --- a/cogs/tibia.py +++ b/cogs/tibia.py @@ -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.") @@ -148,7 +148,7 @@ async def deaths(self, ctx: NabCtx, *, name: str = None): if row["world"] not in user_worlds: continue - user = self._get_cached_user_(self, row["user_id"], user_unknown, users_cache, user_guilds) + user = self._get_cached_user_(self, row["user_id"], user_unknown, users_cache, user_servers) if user == user_unknown: continue @@ -226,10 +226,10 @@ async def deaths(self, ctx: NabCtx, *, name: str = None): await ctx.send(e) @staticmethod - def _get_cached_user_(self, user_id, user_unknown, users_cache, user_guilds): + def _get_cached_user_(self, user_id, user_unknown, users_cache, user_servers): cached_user = users_cache.get(user_id) if cached_user is None: - member_user = self.bot.get_member(user_id, user_guilds) + member_user = self.bot.get_member(user_id, user_servers) cached_user = user_unknown if member_user is None else member_user users_cache[user_id] = cached_user return cached_user @@ -737,10 +737,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.") @@ -754,6 +754,8 @@ 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() + user_unknown = "unknown" try: if name is None: title = "Latest level ups" @@ -765,11 +767,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_unknown, user_cache, user_servers) + if user == user_unknown: + continue + count += 1 row["time"] = get_time_diff(dt.timedelta(seconds=now - row["date"])) row["user"] = user.display_name @@ -784,7 +788,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 @@ -1301,6 +1305,8 @@ 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() + user_unknown = "unknown" try: if name is None: title = "Timeline" @@ -1316,11 +1322,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_unknown, user_cache, user_servers) + if user == user_unknown: + continue + count += 1 row["time"] = get_time_diff(dt.timedelta(seconds=now - row["date"])) row["user"] = user.display_name From ebfc19da391005fc4691c7fcffaf16c397023a74 Mon Sep 17 00:00:00 2001 From: Rodolfo Forte Date: Wed, 10 Oct 2018 09:12:46 +0200 Subject: [PATCH 6/9] Implement PR suggestions --- cogs/tibia.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/cogs/tibia.py b/cogs/tibia.py index 6e77b49..354a9ab 100644 --- a/cogs/tibia.py +++ b/cogs/tibia.py @@ -133,7 +133,6 @@ async def deaths(self, ctx: NabCtx, *, name: str = None): show_links = not ctx.long per_page = 20 if ctx.long else 5 users_cache = dict() - user_unknown = "unknown" try: if name is None: title = "Latest deaths" @@ -148,8 +147,8 @@ async def deaths(self, ctx: NabCtx, *, name: str = None): if row["world"] not in user_worlds: continue - user = self._get_cached_user_(self, row["user_id"], user_unknown, users_cache, user_servers) - if user == user_unknown: + user = self._get_cached_user_(self, row["user_id"], users_cache, user_servers) + if user is None: continue count += 1 @@ -225,15 +224,6 @@ async def deaths(self, ctx: NabCtx, *, name: str = None): except CannotPaginate as e: await ctx.send(e) - @staticmethod - def _get_cached_user_(self, user_id, user_unknown, users_cache, user_servers): - cached_user = users_cache.get(user_id) - if cached_user is None: - member_user = self.bot.get_member(user_id, user_servers) - cached_user = user_unknown if member_user is None else member_user - users_cache[user_id] = cached_user - return cached_user - @deaths.command(name="monster", aliases=["mob", "killer"]) @checks.is_in_tracking_world() async def deaths_monsters(self, ctx: NabCtx, *, name: str): @@ -755,7 +745,6 @@ async def levels(self, ctx: NabCtx, *, name: str=None): per_page = 20 if ctx.long else 5 await ctx.channel.trigger_typing() user_cache = dict() - user_unknown = "unknown" try: if name is None: title = "Latest level ups" @@ -770,8 +759,8 @@ async def levels(self, ctx: NabCtx, *, name: str=None): if row["world"] not in user_worlds: continue - user = self._get_cached_user_(self, row["user_id"], user_unknown, user_cache, user_servers) - if user == user_unknown: + user = self._get_cached_user_(self, row["user_id"], user_cache, user_servers) + if user is None: continue count += 1 @@ -1306,7 +1295,6 @@ async def timeline(self, ctx: NabCtx, *, name: str = None): per_page = 20 if ctx.long else 5 await ctx.channel.trigger_typing() user_cache = dict() - user_unknown = "unknown" try: if name is None: title = "Timeline" @@ -1325,8 +1313,8 @@ async def timeline(self, ctx: NabCtx, *, name: str = None): if row["world"] not in user_worlds: continue - user = self._get_cached_user_(self, row["user_id"], user_unknown, user_cache, user_servers) - if user == user_unknown: + user = self._get_cached_user_(self, row["user_id"], user_cache, user_servers) + if user is None: continue count += 1 @@ -2076,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() From 98ae4ebc0472d06ed1963da78e375e590a1d5b24 Mon Sep 17 00:00:00 2001 From: Allan Galarza Date: Wed, 10 Oct 2018 08:08:50 -0700 Subject: [PATCH 7/9] Removed figureAltCaption dependency figureAltCaption is no longer compatible with the latest version of Markdown, causing a big dependency hell --- requirements-docs.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements-docs.txt b/requirements-docs.txt index a9dae54..f79c751 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -1,4 +1,3 @@ mkdocs mkdocs-material pymdown-extensions -git+https://github.com/jdittrich/figureAltCaption.git \ No newline at end of file From d782ee3fd1c1f95b8df8ae462046c3929630617c Mon Sep 17 00:00:00 2001 From: Allan Galarza Date: Fri, 12 Oct 2018 20:52:09 -0700 Subject: [PATCH 8/9] Added example image to branching model --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0eef5d4..11162ee 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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) From b0e8938cc65fe30bc17cebbaa024b08d5dd1ada3 Mon Sep 17 00:00:00 2001 From: Allan Galarza Date: Fri, 12 Oct 2018 21:43:56 -0700 Subject: [PATCH 9/9] Bumped to 1.7.1 --- CHANGELOG.md | 5 +++++ nabbot.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31a6b94..9d4ae75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/nabbot.py b/nabbot.py index 4f0da69..d4cc83e 100644 --- a/nabbot.py +++ b/nabbot.py @@ -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):