From d8663bed388a611e6b0e48c7a424f54e5b835b03 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Wed, 23 Dec 2020 00:18:45 +0100 Subject: [PATCH 1/7] Cooler Didier no longer spams Zandbak error logs when working on new stuff --- cogs/events.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cogs/events.py b/cogs/events.py index b6bba9f..debaac8 100644 --- a/cogs/events.py +++ b/cogs/events.py @@ -97,6 +97,10 @@ class Events(commands.Cog): :param ctx: Discord Context :param err: the error thrown """ + # Zandbak Didier shouldn't spam the error logs + if self.client.user.id == int(constants.coolerDidierId): + raise err + # Don't handle commands that have their own custom error handler if hasattr(ctx.command, 'on_error'): return From 416b13c9acadf92cdbdf1707d1987b709d9d321e Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Wed, 23 Dec 2020 00:32:33 +0100 Subject: [PATCH 2/7] Fix time formatter date string, remove useless field from whois --- cogs/modCommands.py | 8 +++----- functions/timeFormatters.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cogs/modCommands.py b/cogs/modCommands.py index 2b19d46..274d7fe 100644 --- a/cogs/modCommands.py +++ b/cogs/modCommands.py @@ -165,12 +165,12 @@ class ModCommands(commands.Cog): embed.set_author(name=user.display_name, icon_url=user.avatar_url) embed.add_field(name="Discriminator", value="#{}".format(user.discriminator)) - embed.add_field(name="Discord Id", value=user.id) + embed.add_field(name="Discord id", value=user.id) embed.add_field(name="Bot", value="Nee" if not user.bot else "Ja") created_local = timeFormatters.epochToDate(user.created_at.timestamp()) - embed.add_field(name="Account Aangemaakt", value="{}\n({} geleden)".format( + embed.add_field(name="Account aangemaakt", value="{}\n({} geleden)".format( created_local["date"], timeFormatters.diffYearBasisString(round(created_local["dateDT"].timestamp())) ), inline=False) @@ -178,12 +178,10 @@ class ModCommands(commands.Cog): if ctx.guild is not None: member_instance = ctx.guild.get_member(user.id) - embed.add_field(name="Lid van {}".format(ctx.guild.name), value="Nee" if member_instance is None else "Ja") - if member_instance is not None: joined_local = timeFormatters.epochToDate(member_instance.joined_at.timestamp()) - embed.add_field(name="Lid Geworden Op", value="{}\n({} Geleden)".format( + embed.add_field(name="Lid geworden van {} op".format(ctx.guild.name), value="{}\n({} Geleden)".format( joined_local["date"], timeFormatters.diffYearBasisString(round(joined_local["dateDT"].timestamp())) )) diff --git a/functions/timeFormatters.py b/functions/timeFormatters.py index 272c321..82b12e4 100644 --- a/functions/timeFormatters.py +++ b/functions/timeFormatters.py @@ -5,7 +5,7 @@ import dateutil.relativedelta import pytz -def epochToDate(epochTimeStamp, strFormat="%m/%d/%Y om %H:%M:%S"): +def epochToDate(epochTimeStamp, strFormat="%d/%m/%Y om %H:%M:%S"): now = dateTimeNow() updateTime = datetime.datetime.fromtimestamp(int(epochTimeStamp), pytz.timezone("Europe/Brussels")) diff = now - updateTime From f25bb468b4475ea3affc1fea3fe0badf537413ea Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Wed, 23 Dec 2020 00:35:47 +0100 Subject: [PATCH 3/7] Remove cog check from testcog --- cogs/testCog.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cogs/testCog.py b/cogs/testCog.py index 35b3cb7..5722a1a 100644 --- a/cogs/testCog.py +++ b/cogs/testCog.py @@ -7,9 +7,16 @@ class TestCog(commands.Cog): def __init__(self, client): self.client = client - # All commands in this Cog should only be accessible to me def cog_check(self, ctx): - return checks.isMe(ctx) + """ + Check executed for every command in this cog. + + If necessary, create your own check here. A check is just a function + that returns True or False, and takes ctx as an argument. A command will + only be executed when this check returns True, which is why that is the default + implementation for this function. + """ + return True @commands.command() async def test(self, ctx): From 6a946559e20260a27734452a2be08b2b6e7fb3e6 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Wed, 23 Dec 2020 00:48:43 +0100 Subject: [PATCH 4/7] Add percentage to Message counter & leaderboard --- cogs/leaderboards.py | 10 +++++++--- cogs/xp.py | 6 +++++- functions/database/stats.py | 6 ++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cogs/leaderboards.py b/cogs/leaderboards.py index b891442..1d39daf 100644 --- a/cogs/leaderboards.py +++ b/cogs/leaderboards.py @@ -10,7 +10,6 @@ import math import requests - # TODO some sort of general leaderboard because all of them are the same class Leaderboards(commands.Cog): @@ -156,15 +155,20 @@ class Leaderboards(commands.Cog): async def messages(self, ctx): s = stats.getAllRows() boardTop = [] + + message_count = stats.getTotalMessageCount() + for i, user in enumerate(sorted(s, key=lambda x: x[11], reverse=True)): if int(user[11]) == 0: break + perc = round(int(user[11]) * 100 / message_count, 2) + name = self.utilsCog.getDisplayName(ctx, user[0]) if int(user[0]) == int(ctx.author.id): - boardTop.append("**{} ({:,})**".format(name, round(int(user[11])))) + boardTop.append("**{} ({:,} | {}%)**".format(name, round(int(user[11])), perc)) else: - boardTop.append("{} ({:,})".format(name, round(int(user[11])))) + boardTop.append("{} ({:,} | {}%)".format(name, round(int(user[11])), perc)) await self.startPaginated(ctx, boardTop, "Messages Leaderboard") @leaderboard.command(name="Muttn", aliases=["M", "Mutn", "Mutten"], hidden=True) diff --git a/cogs/xp.py b/cogs/xp.py index 9d292cb..d805d65 100644 --- a/cogs/xp.py +++ b/cogs/xp.py @@ -22,9 +22,13 @@ class Xp(commands.Cog): target_stats = stats.getOrAddUser(target.id) + message_count = stats.getTotalMessageCount() + + perc = round(int(target_stats[11]) * 100/message_count, 2) + embed = discord.Embed(colour=discord.Colour.blue()) embed.set_author(name=target.display_name, icon_url=target.avatar_url) - embed.add_field(name="Aantal Berichten", value="{}".format(int(target_stats[11]))) + embed.add_field(name="Aantal Berichten", value="{} ({}%)".format(int(target_stats[11]), perc)) embed.add_field(name="Level", value=str(xp.calculate_level(target_stats[12]))) embed.add_field(name="XP", value="{:,}".format(int(target_stats[12]))) embed.set_footer(text="*Sinds Didier 2.0 Launch") diff --git a/functions/database/stats.py b/functions/database/stats.py index 43aac01..60d4685 100644 --- a/functions/database/stats.py +++ b/functions/database/stats.py @@ -107,6 +107,12 @@ def gainXp(user, user_db): update(user, "last_message", round(time.time())) +def getTotalMessageCount(): + r = getAllRows() + + return sum(user[11] for user in r) + + def getOrAddChannel(channelid: int): connection = utils.connect() cursor = connection.cursor() From cb4e67be694fa927f0d1ab862c2c4f0b69931523 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Thu, 24 Dec 2020 00:13:25 +0100 Subject: [PATCH 5/7] Make memes paginated, Fixes #14 --- cogs/fun.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cogs/fun.py b/cogs/fun.py index de38f56..f546aa6 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -1,3 +1,4 @@ +from data import paginatedLeaderboard from decorators import help import discord from discord.ext import commands @@ -162,10 +163,9 @@ class Fun(commands.Cog): memeList = [": ".join([stringFormatters.titleCase(meme[1]), str(meme[2])]) for meme in sorted(memeList, key=lambda x: x[1])] - # Add the fields into the embed - embed = discord.Embed(colour=discord.Colour.blue()) - embed.add_field(name="Meme: aantal velden", value="\n".join(memeList), inline=False) - await ctx.send(embed=embed) + pages = paginatedLeaderboard.Pages(source=paginatedLeaderboard.Source(memeList, "Memes", discord.Colour.blue()), + clear_reactions_after=True) + await pages.start(ctx) @commands.command(name="Pjoke") @help.Category(category=Category.Fun) From 81ef990e1fdd12f0841f7999234931f785816fae Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Fri, 25 Dec 2020 18:40:26 +0100 Subject: [PATCH 6/7] Make FAQ check which channel it's called in to return the appropriate FAQ --- cogs/faq.py | 8 ++++++++ data/constants.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/cogs/faq.py b/cogs/faq.py index da18a80..8817b29 100644 --- a/cogs/faq.py +++ b/cogs/faq.py @@ -1,3 +1,4 @@ +from data import constants from decorators import help import discord from discord.ext import commands @@ -20,6 +21,9 @@ class Faq(commands.Cog): """ Command group that controls the FAQ commands. When this command is invoked, it sends a list of valid categories. + + After invoking in a subject's channel (without passing a category), + it sends the FAQ for that subject instead. :param ctx: Discord Context :param args: args passed """ @@ -28,6 +32,10 @@ class Faq(commands.Cog): if len(args) != 0 and any("@" not in arg for arg in args): return await self.faqCategory(ctx, args) + # Check if the command was used in a subject's channel + if ctx.channel.id in constants.faq_channels: + return await self.faqCategory(ctx, (constants.faq_channels[ctx.channel.id],)) + # List of all categories with the first letter capitalized resp = [stringFormatters.titleCase(cat[0]) for cat in faq.getCategories()] diff --git a/data/constants.py b/data/constants.py index 09da550..af8e46b 100644 --- a/data/constants.py +++ b/data/constants.py @@ -46,6 +46,15 @@ holidayAPIKey = "af4e1ebe-465d-4b93-a828-b95df18e6424" prefixes = ["big d", "didier"] +faq_channels = { + 727876753523081216: "ad2", + 727876779481497600: "comnet", + 727876797458284584: "funcprog", + 727876819264733244: "statprob", + 727876836587208714: "sysprog", + 676713433567199232: "didier" +} + class Live(Enum): CallOfCode = "626699611192688641" From 2877def2726717ce8098806f7d7535197f7d7e9f Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Fri, 25 Dec 2020 20:07:55 +0100 Subject: [PATCH 7/7] Add more React letters --- functions/reactWord.py | 70 +++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/functions/reactWord.py b/functions/reactWord.py index 0a01214..854d96f 100644 --- a/functions/reactWord.py +++ b/functions/reactWord.py @@ -83,10 +83,10 @@ def check(content, earlier=[]): for letter in content[0]: c = content[0].count(letter) - # If a letter was added twice, but there is only one, that's an issue - if c != 1 and letter not in doubles: + # If a letter was added three times, but there is only two, that's an issue + if c > 2 and letter not in doubles: return False, ["Er zijn niet genoeg **{}**'s om dit woord te reacten.".format(letter)] - elif c > 1 and letter in doubles and len(doubles[letter]) < c: + elif c > 2 and letter in doubles and len(doubles[letter]) < c: return False, ["Er zijn niet genoeg **{}**'s om dit woord te reacten.".format(letter)] # Array of emoji's @@ -96,14 +96,24 @@ def check(content, earlier=[]): for letter in content[0]: # Letters if letter.isalpha(): + reg_ind = "regional_indicator_{}".format(letter) + zb = "zb_{}".format(letter.upper()) + # Check if this letter has not been added yet - if "regional_indicator_{}".format(letter) in unidic and unidic["regional_indicator_{}".format(letter)] not in arr: - arr.append(unidic["regional_indicator_{}".format(letter)]) + if reg_ind in unidic and unidic[reg_ind] not in arr: + arr.append(unidic[reg_ind]) # Remove this letter as an option from the list of doubles if letter in doubles: doubles[letter] = doubles[letter][1:] + # Check for Zandbak copies + elif zb in unidic and unidic[zb] not in arr: + arr.append(unidic[zb]) + + # Remove this letter as an option from the list of doubles + if letter in doubles: + doubles[letter] = doubles[letter][1:] # Letter has been added before, but there's a double for it elif letter in doubles: if len(doubles[letter]) == 0: @@ -163,15 +173,15 @@ def allowedCharacters(): def getDoubles(): doubles = { - "a": ["regional_indicator_a", "a", "four"], - "b": ["regional_indicator_b", "b"], - "o": ["regional_indicator_o", "o2", "zero"], - "i": ["regional_indicator_i", "information_source", "one"], - "p": ["regional_indicator_p", "parking"], - "m": ["regional_indicator_m", "m"], - "s": ["regional_indicator_s", "five"], - "g": ["regional_indicator_g", "six"], - "e": ["regional_indicator_e", "three"], + "a": ["regional_indicator_a", "zb_A", "a", "four"], + "b": ["regional_indicator_b", "zb_B", "b"], + "o": ["regional_indicator_o", "zb_O", "o2", "zero"], + "i": ["regional_indicator_i", "zb_I", "information_source", "one"], + "p": ["regional_indicator_p", "zb_P", "parking"], + "m": ["regional_indicator_m", "zb_M", "m"], + "s": ["regional_indicator_s", "zb_S", "five"], + "g": ["regional_indicator_g", "zb_G", "six"], + "e": ["regional_indicator_e", "zb_E", "three"], "!": ["exclamation", "grey_exclamation"], "?": ["question", "grey_question"] } @@ -235,6 +245,32 @@ def getUnicodeDict(): "regional_indicator_x": "🇽", "regional_indicator_y": "🇾", "regional_indicator_z": "🇿", + "zb_A": "<:zb_A:792094798516453387>", + "zb_B": "<:zb_B:792094798986346507>", + "zb_C": "<:zb_C:792094799724412958>", + "zb_D": "<:zb_D:792094799984984124>", + "zb_E": "<:zb_E:792094800093380649>", + "zb_F": "<:zb_F:792094799657566278>", + "zb_G": "<:zb_G:792094800014606336>", + "zb_H": "<:zb_H:792094799745908736>", + "zb_I": "<:zb_I:792094799620079626>", + "zb_J": "<:zb_J:792094799800958976>", + "zb_K": "<:zb_K:792094800069263420>", + "zb_L": "<:zb_L:792094754036383755>", + "zb_M": "<:zb_M:792094704674013234>", + "zb_N": "<:zb_N:792094660281630751>", + "zb_O": "<:zb_O:792094628848467998>", + "zb_P": "<:zb_P:792094590793940992>", + "zb_Q": "<:zb_Q:792094558417584138>", + "zb_R": "<:zb_R:792094529951498260>", + "zb_S": "<:zb_S:792094506526572564>", + "zb_T": "<:zb_T:792094451530334228>", + "zb_U": "<:zb_U:792094420195082240>", + "zb_V": "<:zb_V:792094388716437544>", + "zb_W": "<:zb_W:792094342285754378>", + "zb_X": "<:zb_X:792094308412293190>", + "zb_Y": "<:zb_Y:792094270445322270>", + "zb_Z": "<:zb_Z:792094240212779028>", "a": "🅰️", "b": "🅱️", "o2": "🅾️", @@ -270,6 +306,7 @@ def getAllVariants(char: str): reg_ind = "regional_indicator_{}".format(char) if reg_ind in getUnicodeDict(): variants.append(reg_ind) + variants.append("zb_{}".format(char.upper())) # Number elif char in getNumbers(): @@ -292,6 +329,11 @@ def getAllVariants(char: str): print(variants) for var in variants: rep = ":" + var + ":" + + # Zandbak copies are formatted differently + if var.startswith("zb_"): + rep = getUnicodeDict()[var] + if rep not in uniques: uniques.append(rep)