async def add_rep(self, message, member, author): """ Adds the reputation to the file """ # Can the user rep yet? author_member = SQLFunctions.get_or_create_discord_member( author, conn=self.conn) if not self.check_valid_time(author_member): return False receiver_member = SQLFunctions.get_or_create_discord_member( member, conn=self.conn) # Format the reputation message msg_list = message.content.split(" ") if len(msg_list) > 2: msg = " ".join(msg_list[2:]) else: return False # Check if the rep is positive if msg.startswith("-"): isPositive = False msg = msg[1:].strip() else: isPositive = True # Add to DB SQLFunctions.add_reputation(author_member, receiver_member, msg, isPositive, self.conn) return True
async def on_member_join(self, member): # adds the user to the db try: SQLFunctions.get_or_create_discord_member(member, conn=self.conn) except Exception as e: print(e) if member.bot: return # if the server is the main server if member.guild.id == 747752542741725244: channel = self.bot.get_channel(815936830779555841) await self.send_welcome_message(channel, member, member.guild)
async def guess(self, ctx, number=None, confirmed_number=None): """ Daily covid cases guessing game. You guess how many covid cases will be reported by the BAG and depending \ on how close you are, you get more points. `$guess avg` to get a leaderboard with average guessing scores `$guess lb` to get the total leaderboard with all points Leaderboard aliases: `leaderboard`, `lb`, `top`, `best`, `ranking` Average aliases: `avg`, `average` """ leaderboard_aliases = ["leaderboard", "lb", "top", "best", "ranking"] average_aliases = ["avg", "average"] await ctx.message.delete() if number is None: # No values were given in the command: guesser = SQLFunctions.get_covid_guessers( self.conn, discord_user_id=ctx.message.author.id, guild_id=ctx.message.guild.id) if len(guesser) == 0: await ctx.send( f"{ctx.message.author.mention}, you have not made any guesses yet. Guess with `$guess <integer>`.", delete_after=7) return async with ctx.typing(): guesser = guesser[0] image_url = str(ctx.message.author.avatar_url_as(format="png")) try: async with aiohttp.ClientSession() as cs: async with cs.get(image_url) as r: buffer = io.BytesIO(await r.read()) color_thief = ColorThief(buffer) dominant_color = color_thief.get_palette(color_count=2, quality=10)[0] hex_color = int('0x%02x%02x%02x' % dominant_color, 0) except UnidentifiedImageError as e: hex_color = 0x808080 already_guessed = "<:xmark:776717315139698720>" if guesser.NextGuess is not None: already_guessed = "<:checkmark:776717335242211329>" embed = discord.Embed( title="Covid Guesser Profile", description=f"**User:** <@{ctx.message.author.id}>\n" f"**Total Points:** `{guesser.TotalPointsAmount}`\n" f"**Total Guesses:** `{guesser.GuessCount}`\n" f"**Average:** `{round(guesser.average, 2)}`\n" f"**Guessed:** {already_guessed}", color=hex_color) embed.set_thumbnail(url=image_url) await ctx.send(embed=embed, delete_after=15) else: try: if number.lower( ) == "confirm" and ctx.author.guild_permissions.kick_members: # if the number of cases gets confirmed if confirmed_number is None: raise ValueError self.confirmed_cases = int(confirmed_number) if self.confirm_msg is not None: # Deletes the previous confirm message if there are multiple await self.confirm_msg.delete() self.confirm_msg = None self.confirm_msg = await ctx.send( f"Confirmed cases: {self.confirmed_cases}\nA mod or higher, press the <:checkmark:769279808244809798> to verify." ) await self.confirm_msg.add_reaction( "<:checkmark:776717335242211329>") await self.confirm_msg.add_reaction( "<:xmark:776717315139698720>") elif number.lower() in leaderboard_aliases: await self.send_leaderboard(ctx) elif number.lower() in average_aliases: await self.send_leaderboard(ctx, True) else: number = int(number) if number < 0: raise ValueError if number > 1000000: number = 1000000 member = SQLFunctions.get_or_create_discord_member( ctx.message.author, conn=self.conn) SQLFunctions.insert_or_update_covid_guess(member, number, conn=self.conn) await ctx.send( f"{ctx.message.author.mention}, received your guess.", delete_after=7) except ValueError: await ctx.send( f"{ctx.message.author.mention}, no proper positive integer given.", delete_after=7) raise discord.ext.commands.errors.BadArgument
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)