def check_valid_time(self, member: SQLFunctions.DiscordMember): result = SQLFunctions.get_most_recent_time(member, self.conn) if result is None: return True time_sent = datetime.datetime.fromisoformat(result) if time.time() - time_sent.timestamp() > self.time_to_wait: return True return False
async def rep(self, ctx, user_mention=None, *, rep=None): """ Can be used to commend another user for doing something you found nice. Can also be used to give negative reps if the rep message starts with a \ minus sign: `{prefix}rep <user> -doesn't like chocolate` `{prefix}rep <user>` lists the reputation messages of a user. """ if ctx.message.author.id in self.ignored_users: await ctx.send( f"{ctx.message.author.mention} this discord account is blocked from using +rep." ) if user_mention is None: # If there's only the command: await self.send_reputations(ctx.message, ctx.message.author) return if rep is None: # If there's only the command a mention u_id = user_mention.replace("<@", "").replace(">", "").replace("!", "") member = ctx.message.guild.get_member(int(u_id)) await self.send_reputations(ctx.message, member) return # If the message is long enough, add it as a reputation # check if it is a mention u_id = user_mention.replace("<@", "").replace(">", "").replace("!", "") member = ctx.message.guild.get_member(int(u_id)) if member.id == ctx.message.author.id: embed = discord.Embed(title="Error", description="You can't rep yourself.", color=discord.Color.red()) await ctx.send(embed=embed, delete_after=10) raise discord.ext.commands.BadArgument # checks if the message chars are valid if not await valid_chars_checker(ctx.message.content): embed = discord.Embed( title="Error", description= "You can only use printable ascii characters in reputation messages.", color=discord.Color.red()) await ctx.send(embed=embed, delete_after=10) raise discord.ext.commands.BadArgument # Add reputation to user time_valid = await self.add_rep(ctx.message, member, ctx.message.author) # Send return message if time_valid: display_name = member.display_name.replace("*", "").replace( "_", "").replace("~", "").replace("\\", "").replace( "`", "").replace("||", "").replace("@", "") embed = discord.Embed(title="Added rep", description=f"Added rep to {display_name}", color=discord.Color.green()) embed.add_field(name="Comment:", value=f"```{rep}```") embed.set_author(name=str(ctx.message.author)) await ctx.send(embed=embed) else: discord_member = SQLFunctions.get_or_create_discord_member( ctx.message.author, conn=self.conn) last_sent_time = SQLFunctions.get_most_recent_time( discord_member, self.conn) if last_sent_time is not None: seconds = datetime.datetime.fromisoformat( last_sent_time).timestamp() + self.time_to_wait next_time = datetime.datetime.fromtimestamp(seconds).strftime( "%A at %H:%M") embed = discord.Embed( title="Error", description= f"You've repped too recently. You can rep again on {next_time}.", color=discord.Color.red()) await ctx.send(embed=embed, delete_after=10) else: embed = discord.Embed( title="Error", description= "Had problems parsing something. Tbh this error shouldn't show up...", color=discord.Color.red()) await ctx.send(embed=embed, delete_after=10)