From 256814f63dadf8d41bb46e0bda773f106ecbb346 Mon Sep 17 00:00:00 2001 From: Juni Date: Tue, 12 Apr 2022 14:13:59 -0400 Subject: [PATCH] user specifc --- reactquote/reactquote.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/reactquote/reactquote.py b/reactquote/reactquote.py index 0bb86ac..2e02a3f 100644 --- a/reactquote/reactquote.py +++ b/reactquote/reactquote.py @@ -63,15 +63,32 @@ class ReactQuote(commands.Cog): message = await ctx.guild.get_channel(quotes[num]['channelId']).fetch_message(quotes[num]['messageId']) await ctx.send(embed=self._buildQuote(message, num+1)) elif(re.search("^\d+$", query) is not None): + """case id""" num = int(query) if num <= numQuotes: message = await ctx.guild.get_channel(quotes[num-1]['channelId']).fetch_message(quotes[num-1]['messageId']) await ctx.send(embed=self._buildQuote(message, num)) else: await ctx.send(f"There are only {numQuotes} quotes") - + elif(re.search("^@.+$", query) is not None): + """Case username""" + member: discord.Member = ctx.guild.get_member_named(query) + if member is None: + ctx.send("User not found.\nWho are you talking about? OwO") + else: + filteredQuotes = [] + for quote in quotes: + if quote["authorId"] == member.id: + filteredQuotes.append(quote) + if len(filteredQuotes) == 0: + ctx.send(f"No quotes by {member.name} found.\nSay something funny~ OwO") + else: + num = randrange(len(filteredQuotes)) + globalNum = quotes.index(filteredQuotes[num]) + message = await ctx.guild.get_channel(filteredQuotes[num]['channelId']).fetch_message(filteredQuotes[num]['messageId']) + await ctx.send(embed=self._buildQuote(message, globalNum+1)) else: - await ctx.send("No quotes added yet. Say something funny~ OwO") + await ctx.send("No quotes added yet.\nSay something funny~ OwO") @commands.admin_or_permissions(manage_guild=True) @commands.guild_only()