From d764720481136f786593a67f152ac876ef7b151d Mon Sep 17 00:00:00 2001 From: Rohan Date: Wed, 2 Dec 2020 21:52:10 +0530 Subject: Add Reddit class and emojis to constants file. --- bot/constants.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 6999f321..d1ffd30f 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -17,6 +17,7 @@ __all__ = ( "Roles", "Tokens", "Wolfram", + "Reddit", "RedisConfig", "MODERATION_ROLES", "STAFF_ROLES", @@ -144,6 +145,15 @@ class Emojis: status_dnd = "<:status_dnd:470326272082313216>" status_offline = "<:status_offline:470326266537705472>" + # Reddit emojis + reddit = "<:reddit:676030265734332427>" + reddit_post_text = "<:reddit_post_text:676030265910493204>" + reddit_post_video = "<:reddit_post_video:676030265839190047>" + reddit_post_photo = "<:reddit_post_photo:676030265734201344>" + reddit_upvote = "<:reddit_upvote:755845219890757644>" + reddit_comments = "<:reddit_comments:755845255001014384>" + reddit_users = "<:reddit_users:755845303822974997>" + class Icons: questionmark = "https://cdn.discordapp.com/emojis/512367613339369475.png" @@ -231,6 +241,14 @@ class Source: github_avatar_url = "https://avatars1.githubusercontent.com/u/9919" +class Reddit: + subreddits = ["r/Python"] + + client_id = environ.get("REDDIT_CLIENT_ID") + secret = environ.get("REDDIT_SECRET") + webhook = int(environ.get("REDDIT_WEBHOOK", 635408384794951680)) + + # Default role combinations MODERATION_ROLES = Roles.moderator, Roles.admin, Roles.owner STAFF_ROLES = Roles.helpers, Roles.moderator, Roles.admin, Roles.owner -- cgit v1.2.3 From 16476ab7b4d5efe36a9e101b382f7be24888dec5 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon Date: Mon, 22 Feb 2021 11:13:01 -0800 Subject: Switch to itertools.cycle and add colors to constants.py --- bot/constants.py | 2 ++ bot/exts/evergreen/pythonfacts.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index bb538487..3aec6ba3 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -156,6 +156,8 @@ class Colours: soft_orange = 0xf9cb54 soft_red = 0xcd6d6d yellow = 0xf9f586 + python_blue = 0x4B8BBE + python_yellow = 0xFFD43B class Emojis: diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index 734782b8..8e6d300b 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -1,13 +1,16 @@ -import random +import itertools import discord from discord.ext import commands +from bot.constants import Colours with open('bot/resources/evergreen/python_facts.txt') as file: FACTS = list(file) + FACT_CYCLE = itertools.cycle(FACTS) -COLORS = [0x4B8BBE, 0xFFD43B, ] +COLORS = [Colours.python_blue, Colours.python_yellow] +COLOR_CYCLE = itertools.cycle(COLORS) class PythonFacts(commands.Cog): @@ -19,7 +22,7 @@ class PythonFacts(commands.Cog): @commands.command(name='pythonfact', aliases=['pyfact']) async def get_python_fact(self, ctx: commands.Context) -> None: """Sends a Random fun fact about Python.""" - embed = discord.Embed(title='Python Facts', description=random.choice(FACTS), colour=random.choice(COLORS)) + embed = discord.Embed(title='Python Facts', description=next(FACT_CYCLE), colour=next(COLOR_CYCLE)) await ctx.send(embed=embed) -- cgit v1.2.3 From 0260ad04af6e98c7fd804c58913412b6b936eb73 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Tue, 2 Mar 2021 21:39:01 -0600 Subject: finished function --- Pipfile | 1 + Pipfile.lock | 26 +++++++++++++++++--------- bot/constants.py | 1 + bot/exts/easter/earth_photos.py | 35 +++++++++++++++++++---------------- 4 files changed, 38 insertions(+), 25 deletions(-) (limited to 'bot/constants.py') diff --git a/Pipfile b/Pipfile index e7e01a31..1a2d464e 100644 --- a/Pipfile +++ b/Pipfile @@ -15,6 +15,7 @@ PyYAML = "~=5.3.1" "discord.py" = {extras = ["voice"], version = "~=1.5.1"} async-rediscache = {extras = ["fakeredis"], version = "~=0.1.4"} emojis = "~=0.6.0" +requests = "~=2.25.1" [dev-packages] flake8 = "~=3.8" diff --git a/Pipfile.lock b/Pipfile.lock index ec801979..34cd08cf 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b4aaaacbab13179145e36d7b86c736db512286f6cce8e513cc30c48d68fe3810" + "sha256": "53409f1c6726e95cf348740b1dc55124b77a1f327aea273dce041b5056270b2e" }, "pipfile-spec": 6, "requires": { @@ -238,11 +238,11 @@ }, "idna": { "hashes": [ - "sha256:5205d03e7bcbb919cc9c19885f9920d622ca52448306f2377daede5cf3faac16", - "sha256:c5b02147e01ea9920e6b0a3f1f7bb833612d507592c837a6c49552768f4054e1" + "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6", + "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0" ], - "markers": "python_version >= '3.4'", - "version": "==3.1" + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.10" }, "multidict": { "hashes": [ @@ -412,6 +412,14 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", "version": "==3.5.3" }, + "requests": { + "hashes": [ + "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804", + "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e" + ], + "index": "pypi", + "version": "==2.25.1" + }, "sentry-sdk": { "hashes": [ "sha256:4ae8d1ced6c67f1c8ea51d82a16721c166c489b76876c9f2c202b8a50334b237", @@ -585,11 +593,11 @@ }, "identify": { "hashes": [ - "sha256:de7129142a5c86d75a52b96f394d94d96d497881d2aaf8eafe320cdbe8ac4bcc", - "sha256:e0dae57c0397629ce13c289f6ddde0204edf518f557bfdb1e56474aa143e77c3" + "sha256:9cdd81e5d2b6e76c3006d5226316dd947bd6324fbeebb881bec489202fa09d3a", + "sha256:b99aa309329c4fea679463eb35d169f3fbe13e66e9dd6162ad1856cbeb03dcbd" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.5.14" + "markers": "python_full_version >= '3.6.1'", + "version": "==2.0.0" }, "mccabe": { "hashes": [ diff --git a/bot/constants.py b/bot/constants.py index db34b55a..f8ea5743 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -271,6 +271,7 @@ class Tokens(NamedTuple): igdb_client_id = environ.get("IGDB_CLIENT_ID") igdb_client_secret = environ.get("IGDB_CLIENT_SECRET") github = environ.get("GITHUB_TOKEN") + unsplash_key = environ.get("UNSPLASH_KEY") class Wolfram(NamedTuple): diff --git a/bot/exts/easter/earth_photos.py b/bot/exts/easter/earth_photos.py index 436b39a7..478502eb 100644 --- a/bot/exts/easter/earth_photos.py +++ b/bot/exts/easter/earth_photos.py @@ -1,8 +1,5 @@ -import asyncio import logging -import random -from unsplash.api import Api as uApi -from unsplash.auth import Auth as uAuth +import requests import discord from discord.ext import commands @@ -11,27 +8,33 @@ from bot.constants import Tokens log = logging.getLogger(__name__) -UnClient_id = Tokens.UNSPLASH_API +UnClient_id = Tokens.unsplash_key -UnClient_secret = Tokens.UNSPLASH_SECRET - -redirect_uri = "urn:ietf:wg:oauth:2.0:oob" - -unsplash_auth = uAuth(client_id, class EarthPhotos(commands.Cog): """This cog contains the command for earth photos.""" - + def init(self, bot: commands.Bot): self.bot = bot self.current_channel = None - + @commands.command(aliases=["earth"]) async def earth_photos(self, ctx: commands.Context): """ Returns a random photo of earth, sourced from Unsplash. """ - - - - + photorequest = requests.get("https://api.unsplash.com/photos/random?query=earth&client_id=" + UnClient_id) + photojson = photorequest.json() + photourls = photojson.get('urls') + urltosend = photourls.get('regular') + userjson = photojson.get('user') + userName = userjson.get('name') + embed = discord.Embed(title="Earth Photo", description="A photo of Earth from Unsplash.", color=0x66ff00) + embed.set_image(url=urltosend) + embed.set_footer(text="Image by " + userName + " on Unsplash.") + await ctx.send(embed=embed) + + +def setup(bot: commands.Bot) -> None: + """Cog load""" + bot.add_cog(EarthPhotos(bot)) -- cgit v1.2.3 From b2ee1b9e79766b8cfe7b45670f6c86e7166ee84f Mon Sep 17 00:00:00 2001 From: Kronifer Date: Wed, 3 Mar 2021 20:20:22 +0000 Subject: fstrings, colours, and self.bot --- Pipfile | 2 -- bot/constants.py | 1 + bot/exts/easter/earth_photos.py | 48 ++++++++++++++++++++--------------------- 3 files changed, 25 insertions(+), 26 deletions(-) (limited to 'bot/constants.py') diff --git a/Pipfile b/Pipfile index 1d1df3d7..e7e01a31 100644 --- a/Pipfile +++ b/Pipfile @@ -15,8 +15,6 @@ PyYAML = "~=5.3.1" "discord.py" = {extras = ["voice"], version = "~=1.5.1"} async-rediscache = {extras = ["fakeredis"], version = "~=0.1.4"} emojis = "~=0.6.0" -requests = "~=2.25.1" -pre-commit = "*" [dev-packages] flake8 = "~=3.8" diff --git a/bot/constants.py b/bot/constants.py index f8ea5743..c570b17f 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -158,6 +158,7 @@ class Colours: soft_orange = 0xf9cb54 soft_red = 0xcd6d6d yellow = 0xf9f586 + grass_green = 0x66ff00 class Emojis: diff --git a/bot/exts/easter/earth_photos.py b/bot/exts/easter/earth_photos.py index 0ac470ce..a49e666c 100644 --- a/bot/exts/easter/earth_photos.py +++ b/bot/exts/easter/earth_photos.py @@ -1,8 +1,8 @@ -import aiohttp import discord from discord.ext import commands from bot.constants import Tokens +from bot.constants import Colours UnClient_id = Tokens.unsplash_key @@ -10,35 +10,35 @@ UnClient_id = Tokens.unsplash_key class EarthPhotos(commands.Cog): """This cog contains the command for earth photos.""" - def __init__(self, bot: commands.Bot) -> None: + def __init__(self, bot: commands.Bot): self.bot = bot - self.current_channel = None @commands.command(aliases=["earth"]) async def earth_photos(self, ctx: commands.Context) -> None: """Returns a random photo of earth, sourced from Unsplash.""" async with ctx.typing(): - async with aiohttp.ClientSession() as session: - async with session.get( - 'https://api.unsplash.com/photos/random?query=earth&client_id=' + UnClient_id) as r: - jsondata = await r.json() - linksdata = jsondata.get("urls") - embedlink = linksdata.get("full") - downloadlinksdata = jsondata.get("links") - userdata = jsondata.get("user") - username = userdata.get("name") - userlinks = userdata.get("links") - profile = userlinks.get("html") - async with session.get( - downloadlinksdata.get("download_location") + "?client_id=" + UnClient_id) as er: - er.status - embed = discord.Embed( - title="Earth Photo", - description="A photo of earth from Unsplash.", - color=0x66ff00) - embed.set_image(url=embedlink) - embed.add_field(title="Author", value="Made by [" + username + "](" + profile + ") on Unsplash.") - await ctx.send(embed=embed) + async with self.bot.http_session.get( + 'https://api.unsplash.com/photos/random', + params={"query": "planet_earth", "client_id": UnClient_id}) as r: + jsondata = await r.json() + linksdata = jsondata.get("urls") + embedlink = linksdata.get("full") + downloadlinksdata = jsondata.get("links") + userdata = jsondata.get("user") + username = userdata.get("name") + userlinks = userdata.get("links") + profile = userlinks.get("html") + async with self.bot.http_session.get( + downloadlinksdata.get("download_location"), + params={"client_id": UnClient_id}) as er: + er.status + embed = discord.Embed( + title="Earth Photo", + description="A photo of earth from Unsplash.", + color=Colours.grass_green) + embed.set_image(url=embedlink) + embed.add_field(name="Author", value=f"Made by [{username}]({profile}) on Unsplash.") + await ctx.send(embed=embed) def setup(bot: commands.Bot) -> None: -- cgit v1.2.3 From 512a5b3f085510d5862589ecc21bd253cb219207 Mon Sep 17 00:00:00 2001 From: Kronifer <44979306+Kronifer@users.noreply.github.com> Date: Thu, 4 Mar 2021 10:37:53 -0600 Subject: Changes requested by @ChrisLovering --- bot/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index c570b17f..721defc8 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -272,7 +272,7 @@ class Tokens(NamedTuple): igdb_client_id = environ.get("IGDB_CLIENT_ID") igdb_client_secret = environ.get("IGDB_CLIENT_SECRET") github = environ.get("GITHUB_TOKEN") - unsplash_key = environ.get("UNSPLASH_KEY") + unsplash_access_key = environ.get("UNSPLASH_KEY") class Wolfram(NamedTuple): -- cgit v1.2.3 From bd49374ca6efad79b97d891882b05b8568f10fb4 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon <74436682+MrKomodoDragon@users.noreply.github.com> Date: Thu, 4 Mar 2021 14:39:47 -0800 Subject: Remove arrows (whoopsies)! --- bot/constants.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index f6e09ae7..b8e30a7c 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -158,12 +158,9 @@ class Colours: soft_orange = 0xf9cb54 soft_red = 0xcd6d6d yellow = 0xf9f586 -<<<<<<< master python_blue = 0x4B8BBE python_yellow = 0xFFD43B -======= grass_green = 0x66ff00 ->>>>>>> master class Emojis: -- cgit v1.2.3 From 2ff509601fb97466ba6d980d226f6c0e481a1961 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 10 Mar 2021 19:31:37 +0000 Subject: Move colours to constants --- bot/constants.py | 16 ++++++++++++++++ bot/exts/evergreen/profile_pic_modification/_effects.py | 8 ++------ 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index b8e30a7c..5c95d9c1 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -162,6 +162,22 @@ class Colours: python_yellow = 0xFFD43B grass_green = 0x66ff00 + easter_like_colours = [ + (255, 247, 0), + (255, 255, 224), + (0, 255, 127), + (189, 252, 201), + (255, 192, 203), + (255, 160, 122), + (181, 115, 220), + (221, 160, 221), + (200, 162, 200), + (238, 130, 238), + (135, 206, 235), + (0, 204, 204), + (64, 224, 208), + ] + class Emojis: star = "\u2B50" diff --git a/bot/exts/evergreen/profile_pic_modification/_effects.py b/bot/exts/evergreen/profile_pic_modification/_effects.py index dda58006..b0d50f4b 100644 --- a/bot/exts/evergreen/profile_pic_modification/_effects.py +++ b/bot/exts/evergreen/profile_pic_modification/_effects.py @@ -5,11 +5,7 @@ from pathlib import Path import discord from PIL import Image, ImageDraw, ImageOps -EASTER_COLOURS = [ - (255, 247, 0), (255, 255, 224), (0, 255, 127), (189, 252, 201), (255, 192, 203), - (255, 160, 122), (181, 115, 220), (221, 160, 221), (200, 162, 200), (238, 130, 238), - (135, 206, 235), (0, 204, 204), (64, 224, 208) -] # Pastel colours - Easter-like +from bot.constants import Colours class PfpEffects: @@ -46,7 +42,7 @@ class PfpEffects: r2, g2, b2 = point return (r1 - r2) ** 2 + (g1 - g2) ** 2 + (b1 - b2) ** 2 - closest_colours = sorted(EASTER_COLOURS, key=lambda point: distance(point)) + closest_colours = sorted(Colours.easter_like_colours, key=lambda point: distance(point)) r2, g2, b2 = closest_colours[0] r = (r1 + r2) // 2 g = (g1 + g2) // 2 -- cgit v1.2.3 From 0e074b798dd8b47c86043f85b8fac71b76cb8d1b Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Sat, 13 Mar 2021 23:26:24 +0300 Subject: Removes Unused Roles & Channels Removes roles and channels from constants.py that are not used anywhere in the project. Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- bot/constants.py | 25 ------------------------- bot/exts/christmas/advent_of_code/_cog.py | 2 +- 2 files changed, 1 insertion(+), 26 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index b8e30a7c..416dd0e7 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -94,33 +94,18 @@ class Branding: class Channels(NamedTuple): - admins = 365960823622991872 advent_of_code = int(environ.get("AOC_CHANNEL_ID", 782715290437943306)) advent_of_code_commands = int(environ.get("AOC_COMMANDS_CHANNEL_ID", 607247579608121354)) - announcements = int(environ.get("CHANNEL_ANNOUNCEMENTS", 354619224620138496)) - big_brother_logs = 468507907357409333 bot = 267659945086812160 - checkpoint_test = 422077681434099723 organisation = 551789653284356126 - devalerts = 460181980097675264 devlog = int(environ.get("CHANNEL_DEVLOG", 622895325144940554)) dev_contrib = 635950537262759947 - dev_branding = 753252897059373066 - helpers = 385474242440986624 - message_log = 467752170159079424 - mod_alerts = 473092532147060736 - modlog = 282638479504965634 mod_meta = 775412552795947058 mod_tools = 775413915391098921 off_topic_0 = 291284109232308226 off_topic_1 = 463035241142026251 off_topic_2 = 463035268514185226 - python = 267624335836053506 - reddit = 458224812528238616 community_bot_commands = int(environ.get("CHANNEL_COMMUNITY_BOT_COMMANDS", 607247579608121354)) - staff_lounge = 464905259261755392 - verification = 352442727016693763 - python_discussion = 267624335836053506 hacktoberfest_2020 = 760857070781071431 voice_chat_0 = 412357430186344448 voice_chat_1 = 799647045886541885 @@ -248,20 +233,10 @@ if Client.month_override is not None: class Roles(NamedTuple): admin = int(environ.get("BOT_ADMIN_ROLE_ID", 267628507062992896)) - announcements = 463658397560995840 - champion = 430492892331769857 - contributor = 295488872404484098 - devops = 409416496733880320 - jammer = 423054537079783434 moderator = 267629731250176001 - muted = 277914926603829249 owner = 267627879762755584 - verified = 352427296948486144 helpers = int(environ.get("ROLE_HELPERS", 267630620367257601)) - rockstars = 458226413825294336 core_developers = 587606783669829632 - events_lead = 778361735739998228 - everyone_role = 267624335836053506 class Tokens(NamedTuple): diff --git a/bot/exts/christmas/advent_of_code/_cog.py b/bot/exts/christmas/advent_of_code/_cog.py index dc3d7616..8376987d 100644 --- a/bot/exts/christmas/advent_of_code/_cog.py +++ b/bot/exts/christmas/advent_of_code/_cog.py @@ -244,7 +244,7 @@ class AdventOfCode(commands.Cog): info_embed = _helpers.get_summary_embed(leaderboard) await ctx.send(f"```\n{table}\n```", embed=info_embed) - @with_role(Roles.admin, Roles.events_lead) + @with_role(Roles.admin) @adventofcode_group.command( name="refresh", aliases=("fetch",), -- cgit v1.2.3 From 09eeac31df1fd9138d81d057829dd20cb8504ef9 Mon Sep 17 00:00:00 2001 From: Shivansh-007 Date: Sat, 3 Apr 2021 11:18:38 +0530 Subject: Use constants for delete delay and remove redundant f-string. --- bot/constants.py | 5 +++++ bot/exts/evergreen/error_handler.py | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 416dd0e7..ba4345bc 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -20,6 +20,7 @@ __all__ = ( "Tokens", "Wolfram", "RedisConfig", + "RedirectOutput", "MODERATION_ROLES", "STAFF_ROLES", "WHITELISTED_CHANNELS", @@ -270,6 +271,10 @@ class Source: github_avatar_url = "https://avatars1.githubusercontent.com/u/9919" +class RedirectOutput: + delete_delay: int = 10 + + # Default role combinations MODERATION_ROLES = Roles.moderator, Roles.admin, Roles.owner STAFF_ROLES = Roles.helpers, Roles.moderator, Roles.admin, Roles.owner diff --git a/bot/exts/evergreen/error_handler.py b/bot/exts/evergreen/error_handler.py index 3d056f81..f74218b7 100644 --- a/bot/exts/evergreen/error_handler.py +++ b/bot/exts/evergreen/error_handler.py @@ -8,7 +8,7 @@ from discord import Embed, Message from discord.ext import commands from sentry_sdk import push_scope -from bot.constants import Channels, Colours, ERROR_REPLIES, NEGATIVE_REPLIES +from bot.constants import Channels, Colours, ERROR_REPLIES, NEGATIVE_REPLIES, RedirectOutput from bot.utils.decorators import InChannelCheckFailure, InMonthCheckFailure from bot.utils.exceptions import UserNotPlayingError @@ -159,8 +159,8 @@ class CommandErrorHandler(commands.Cog): misspelled_content = ctx.message.content e = Embed() e.set_author(name="Did you mean:", icon_url=QUESTION_MARK_ICON) - e.description = f"{misspelled_content.replace(command_name, similar_command_name, 1)}" - await ctx.send(embed=e, delete_after=10.0) + e.description = misspelled_content.replace(command_name, similar_command_name, 1) + await ctx.send(embed=e, delete_after=RedirectOutput.delete_delay) def setup(bot: commands.Bot) -> None: -- cgit v1.2.3 From 2ad7b496c742d275d717b2de410caebdbeaa50d4 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 5 Apr 2021 17:16:52 +0100 Subject: Fetch member before modifying their pfp We do this as the member cache may have an outdated version of their pfp, which can lead to errors if it's removed from the Discord CDN. Co-authored-by: vcokltfre --- bot/constants.py | 1 + .../profile_pic_modification/pfp_modify.py | 65 +++++++++++++++++----- 2 files changed, 52 insertions(+), 14 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 3ca2cda9..853ea340 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -165,6 +165,7 @@ class Colours: class Emojis: + cross_mark = "\u274C" star = "\u2B50" christmas_tree = "\U0001F384" check = "\u2611" diff --git a/bot/exts/evergreen/profile_pic_modification/pfp_modify.py b/bot/exts/evergreen/profile_pic_modification/pfp_modify.py index 9242ff0c..c4b74d04 100644 --- a/bot/exts/evergreen/profile_pic_modification/pfp_modify.py +++ b/bot/exts/evergreen/profile_pic_modification/pfp_modify.py @@ -9,7 +9,7 @@ from aiohttp import client_exceptions from discord.ext import commands from discord.ext.commands.errors import BadArgument -from bot.constants import Colours +from bot.constants import Client, Colours, Emojis from bot.exts.evergreen.profile_pic_modification._effects import PfpEffects from bot.utils.extensions import invoke_help_command from bot.utils.halloween import spookifications @@ -42,6 +42,24 @@ class PfpModify(commands.Cog): def __init__(self, bot: commands.Bot) -> None: self.bot = bot + async def _fetch_member(self, member_id: int) -> t.Optional[discord.Member]: + """ + Fetches a member and handles errors. + + This helper funciton is required as the member cache doesn't always have the most up to date + profile picture. THis can lead to errors if the image is delted from the Discord CDN. + """ + try: + member = await self.bot.get_guild(Client.guild).fetch_member(member_id) + except discord.errors.NotFound: + log.debug(f"Member {member_id} left the guild before we could get their pfp.") + return None + except discord.HTTPException: + log.exception(f"Exception while trying to retrieve member {member_id} from Discord.") + return None + + return member + @commands.group() async def pfp_modify(self, ctx: commands.Context) -> None: """Groups all of the pfp modifying commands to allow a single concurrency limit.""" @@ -52,10 +70,15 @@ class PfpModify(commands.Cog): async def eightbit_command(self, ctx: commands.Context) -> None: """Pixelates your avatar and changes the palette to an 8bit one.""" async with ctx.typing(): - image_bytes = await ctx.author.avatar_url.read() + member = await self._fetch_member(ctx.author.id) + if not member: + ctx.send(f"{Emojis.cross_mark} Could not get member info.") + return + + image_bytes = await member.avatar_url.read() file_name = FILENAME_STRING.format( effect="eightbit_avatar", - author=ctx.author.display_name + author=member.display_name ) file = await in_executor( @@ -71,7 +94,7 @@ class PfpModify(commands.Cog): ) embed.set_image(url=f"attachment://{file_name}") - embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=ctx.author.avatar_url) + embed.set_footer(text=f"Made by {member.display_name}.", icon_url=member.avatar_url) await ctx.send(embed=embed, file=file) @@ -96,6 +119,11 @@ class PfpModify(commands.Cog): return args[0] async with ctx.typing(): + member = await self._fetch_member(ctx.author.id) + if not member: + ctx.send(f"{Emojis.cross_mark} Could not get member info.") + return + egg = None if colours: send_message = ctx.send @@ -106,10 +134,10 @@ class PfpModify(commands.Cog): return ctx.send = send_message # Reassigns ctx.send - image_bytes = await ctx.author.avatar_url_as(size=256).read() + image_bytes = await member.avatar_url_as(size=256).read() file_name = FILENAME_STRING.format( effect="easterified_avatar", - author=ctx.author.display_name + author=member.display_name ) file = await in_executor( @@ -125,7 +153,7 @@ class PfpModify(commands.Cog): description="Here is your lovely avatar, all bright and colourful\nwith Easter pastel colours. Enjoy :D" ) embed.set_image(url=f"attachment://{file_name}") - embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=ctx.author.avatar_url) + embed.set_footer(text=f"Made by {member.display_name}.", icon_url=member.avatar_url) await ctx.send(file=file, embed=embed) @@ -183,7 +211,11 @@ class PfpModify(commands.Cog): return async with ctx.typing(): - image_bytes = await ctx.author.avatar_url.read() + member = await self._fetch_member(ctx.author.id) + if not member: + ctx.send(f"{Emojis.cross_mark} Could not get member info.") + return + image_bytes = await member.avatar_url.read() await self.send_pride_image(ctx, image_bytes, pixels, flag, option) @prideavatar.command() @@ -235,17 +267,22 @@ class PfpModify(commands.Cog): root_aliases=('spookyavatar', 'spookify', 'savatar'), brief='Spookify an user\'s avatar.' ) - async def spooky_avatar(self, ctx: commands.Context, user: discord.Member = None) -> None: + async def spooky_avatar(self, ctx: commands.Context, member: discord.Member = None) -> None: """This "spookifies" the given user's avatar, with a random *spooky* effect.""" - if user is None: - user = ctx.message.author + if member is None: + member = ctx.author + + member = await self._fetch_member(member.id) + if not member: + ctx.send(f"{Emojis.cross_mark} Could not get member info.") + return async with ctx.typing(): - image_bytes = await user.avatar_url.read() + image_bytes = await member.avatar_url.read() file_name = FILENAME_STRING.format( effect="spooky_avatar", - author=user.display_name + author=member.display_name ) file = await in_executor( PfpEffects.apply_effect, @@ -258,7 +295,7 @@ class PfpModify(commands.Cog): title="Is this you or am I just really paranoid?", colour=Colours.soft_red ) - embed.set_author(name=user.name, icon_url=user.avatar_url) + embed.set_author(name=member.name, icon_url=member.avatar_url) embed.set_image(url=f"attachment://{file_name}") embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=ctx.author.avatar_url) -- cgit v1.2.3 From c94a45a10bac63eff1ce066707fe2df0b1243daa Mon Sep 17 00:00:00 2001 From: ToxicKidz <78174417+ToxicKidz@users.noreply.github.com> Date: Thu, 8 Apr 2021 12:37:14 -0400 Subject: Use PRDraft emoji when the pr is a draft pr for the .issue|.pr command --- bot/constants.py | 1 + bot/exts/evergreen/issues.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 416dd0e7..e59fa641 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -168,6 +168,7 @@ class Emojis: issue_closed = "<:IssueClosed:629695470570307614>" pull_request = "<:PROpen:629695470175780875>" pull_request_closed = "<:PRClosed:629695470519713818>" + pull_request_draft = "<:PRDraft:829755345425399848>" merge = "<:PRMerged:629695470570176522>" number_emojis = { diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 4a73d20b..e83f1a3e 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -100,7 +100,7 @@ class Issues(commands.Cog): for number in numbers: url = f"https://api.github.com/repos/{user}/{repository}/issues/{number}" - merge_url = f"https://api.github.com/repos/{user}/{repository}/pulls/{number}/merge" + pulls_url = f"https://api.github.com/repos/{user}/{repository}/pulls/{number}" log.trace(f"Querying GH issues API: {url}") async with self.bot.http_session.get(url, headers=REQUEST_HEADERS) as r: json_data = await r.json() @@ -123,12 +123,15 @@ class Issues(commands.Cog): # we know that a PR has been requested and a call to the pulls API endpoint is necessary # to get the desired information for the PR. else: - log.trace(f"PR provided, querying GH pulls API for additional information: {merge_url}") - async with self.bot.http_session.get(merge_url) as m: - if json_data.get("state") == "open": + log.trace(f"PR provided, querying GH pulls API for additional information: {pulls_url}") + async with self.bot.http_session.get(pulls_url) as p: + pull_data = await p.json() + if pull_data["draft"]: + icon_url = Emojis.pull_request_draft + elif pull_data["state"] == "open": icon_url = Emojis.pull_request # When the status is 204 this means that the state of the PR is merged - elif m.status == 204: + elif pull_data["merged_at"] is not None: icon_url = Emojis.merge else: icon_url = Emojis.pull_request_closed -- cgit v1.2.3 From 17cf2b391df6d02083386a450c0f4569ba421762 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 11 Apr 2021 16:21:44 +0100 Subject: Add env var for trashcan eomji override --- bot/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 416dd0e7..1d35b3f1 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -153,7 +153,7 @@ class Emojis: christmas_tree = "\U0001F384" check = "\u2611" envelope = "\U0001F4E8" - trashcan = "<:trashcan:637136429717389331>" + trashcan = environ.get("TRASHCAN_EMOJI", "<:trashcan:637136429717389331>") ok_hand = ":ok_hand:" hand_raised = "\U0001f64b" -- cgit v1.2.3 From a6e3343b4ca1b2d7833953228c52b9a4bba73867 Mon Sep 17 00:00:00 2001 From: Vivaan Parashar Date: Tue, 13 Apr 2021 18:11:42 +0530 Subject: use emojis and limit tags to 3 --- bot/constants.py | 5 +++++ bot/exts/evergreen/stackoverflow.py | 40 +++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 17 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index bb538487..6c114180 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -201,6 +201,11 @@ class Emojis: status_dnd = "<:status_dnd:470326272082313216>" status_offline = "<:status_offline:470326266537705472>" + stackoverflow_upvote = environ.get('stack_upvote', "<:stack_upvote:831468823320330270>") + stackoverflow_tag = environ.get('stack_tag', "<:stack_tag:831468691647889419> ") + stackoverflow_views = environ.get('stack_views', "<:stack_eye:831455489040318464>") + stackoverflow_ans = environ.get('stack_ans', "<:stack_ans:831455489195638784>") + class Icons: questionmark = "https://cdn.discordapp.com/emojis/512367613339369475.png" diff --git a/bot/exts/evergreen/stackoverflow.py b/bot/exts/evergreen/stackoverflow.py index 721f31f4..316c1ad7 100644 --- a/bot/exts/evergreen/stackoverflow.py +++ b/bot/exts/evergreen/stackoverflow.py @@ -6,12 +6,20 @@ from discord import Embed from discord.errors import HTTPException from discord.ext import commands -from bot.constants import Colours +from bot.constants import Colours, Emojis logger = logging.getLogger(__name__) BASE_URL = "https://api.stackexchange.com/2.2/search/advanced?order=desc&sort=activity&site=stackoverflow&q={query}" SEARCH_URL = "https://stackoverflow.com/search?q={query}" +ERR_EMBED = Embed( + title="Error in fetching results from Stackoverflow", + description=( + "Sorry, there was en error while trying to fetch data from the Stackoverflow website. Please try again in some " + "time. If this issue persists, please contact the mods or send a message in #dev-contrib." + ), + color=Colours.soft_red +) class Stackoverflow(commands.Cog): @@ -35,21 +43,14 @@ class Stackoverflow(commands.Cog): logger.error(f'Status code is not 200, it is {response.status}') continue if response.status != 200: # If the status is still not 200 after the 3 tries - err_embed = Embed( - title="Error in fetching results from Stackoverflow", - description=("Sorry, there was en error while trying to fetch data from the Stackoverflow website. " - "Please try again in some time. If this issue persists, please contact the mods or send a " - "message in #dev-contrib."), - color=Colours.soft_red - ) - await ctx.send(embed=err_embed) + await ctx.send(embed=ERR_EMBED) return elif not data['items']: - err_embed = Embed( + no_search_result = Embed( title=f"No search results found for {search_query!r}", color=Colours.soft_red ) - await ctx.send(embed=err_embed) + await ctx.send(embed=no_search_result) return top5 = data["items"][:5] @@ -60,23 +61,28 @@ class Stackoverflow(commands.Cog): for item in top5: embed.add_field( name=f"{unescape(item['title'])}", - value=(f"[{item['score']} upvote{'s' if item['score'] != 1 else ''} ┃ " - f"{item['view_count']} view{'s' if item['view_count'] != 1 else ''} ┃ " - f"{item['answer_count']} answer{'s' if item['answer_count'] != 1 else ''} ┃ " - f"Tags: {', '.join(item['tags'])}]" + value=(f"[{Emojis.stackoverflow_upvote} {item['score']} " + f"{Emojis.stackoverflow_views} {item['view_count']} " + f"{Emojis.stackoverflow_ans} {item['answer_count']} " + f"{Emojis.stackoverflow_tag} {', '.join(item['tags'][:3])}]" f"({item['link']})"), inline=False) embed.set_footer(text="View the original link for more results.") try: await ctx.send(embed=embed) except HTTPException: - err_embed = Embed( + search_query_too_long = Embed( title="Your search query is too long, please try shortening your search query", color=Colours.soft_red ) - await ctx.send(embed=err_embed) + await ctx.send(embed=search_query_too_long) def setup(bot: commands.Bot) -> None: """Loads Stackoverflow Cog.""" bot.add_cog(Stackoverflow(bot)) + +# View icon made by Gregor Cresnar (https://www.flaticon.com/authors/gregor-cresnar) from www.flaticon.com, and edited +# by me +# Answer icon made by Prosymbols (https://www.flaticon.com/authors/prosymbols) from www.flaticon.com, and edited by me +# Tag icon made by Freepik (https://www.flaticon.com/authors/freepik) from www.flaticon.com, and edited by me -- cgit v1.2.3 From 7a22098801065d8ffcc5ea38d854ebaff0965b52 Mon Sep 17 00:00:00 2001 From: Vivaan Parashar Date: Tue, 13 Apr 2021 18:28:20 +0530 Subject: Update emojis --- bot/constants.py | 8 ++++---- bot/exts/evergreen/stackoverflow.py | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 6c114180..05eea474 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -201,10 +201,10 @@ class Emojis: status_dnd = "<:status_dnd:470326272082313216>" status_offline = "<:status_offline:470326266537705472>" - stackoverflow_upvote = environ.get('stack_upvote', "<:stack_upvote:831468823320330270>") - stackoverflow_tag = environ.get('stack_tag', "<:stack_tag:831468691647889419> ") - stackoverflow_views = environ.get('stack_views', "<:stack_eye:831455489040318464>") - stackoverflow_ans = environ.get('stack_ans', "<:stack_ans:831455489195638784>") + stackoverflow_upvote = environ.get('stack_upvote', "<:stack_upvote:*>") # TODO: Fill in numbers (ids) + stackoverflow_tag = environ.get('stack_tag', "<:stack_tag:*> ") + stackoverflow_views = environ.get('stack_views', "<:stack_eye:*>") + stackoverflow_ans = environ.get('stack_ans', "<:stack_ans:*>") class Icons: diff --git a/bot/exts/evergreen/stackoverflow.py b/bot/exts/evergreen/stackoverflow.py index 316c1ad7..04126d9c 100644 --- a/bot/exts/evergreen/stackoverflow.py +++ b/bot/exts/evergreen/stackoverflow.py @@ -82,7 +82,5 @@ def setup(bot: commands.Bot) -> None: """Loads Stackoverflow Cog.""" bot.add_cog(Stackoverflow(bot)) -# View icon made by Gregor Cresnar (https://www.flaticon.com/authors/gregor-cresnar) from www.flaticon.com, and edited -# by me -# Answer icon made by Prosymbols (https://www.flaticon.com/authors/prosymbols) from www.flaticon.com, and edited by me +# Upvote and Comment icon taken from Reddit bot # Tag icon made by Freepik (https://www.flaticon.com/authors/freepik) from www.flaticon.com, and edited by me -- cgit v1.2.3 From 1670e5a48efb50324096df859e673d30528380e4 Mon Sep 17 00:00:00 2001 From: Rohan Date: Thu, 15 Apr 2021 20:39:50 +0530 Subject: Add reddit channel ID to constants. --- bot/constants.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index dfb39364..f5baec35 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -111,6 +111,7 @@ class Channels(NamedTuple): voice_chat_0 = 412357430186344448 voice_chat_1 = 799647045886541885 staff_voice = 541638762007101470 + reddit = int(environ.get("CHANNEL_REDDIT", 458224812528238616)) class Categories(NamedTuple): -- cgit v1.2.3 From 9524620ddbb7d3e707258e1ba3b84b23b5e3b54a Mon Sep 17 00:00:00 2001 From: Dillon Runke <44979306+Kronifer@users.noreply.github.com> Date: Tue, 20 Apr 2021 11:12:17 -0500 Subject: Add Catify command (#694) Co-authored-by: Joe Banks Co-authored-by: hypergamer80 <79152594+hypergamer80@users.noreply.github.com> --- bot/constants.py | 5 +++ bot/exts/evergreen/catify.py | 78 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 bot/exts/evergreen/catify.py (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index a64882db..bcbdcba0 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -8,6 +8,7 @@ from typing import Dict, NamedTuple __all__ = ( "AdventOfCode", "Branding", + "Cats", "Channels", "Categories", "Client", @@ -93,6 +94,10 @@ class Branding: cycle_frequency = int(environ.get("CYCLE_FREQUENCY", 3)) # 0: never, 1: every day, 2: every other day, ... +class Cats: + cats = ["ᓚᘏᗢ", "ᘡᘏᗢ", "🐈", "ᓕᘏᗢ", "ᓇᘏᗢ", "ᓂᘏᗢ", "ᘣᘏᗢ", "ᕦᘏᗢ", "ᕂᘏᗢ"] + + class Channels(NamedTuple): advent_of_code = int(environ.get("AOC_CHANNEL_ID", 782715290437943306)) advent_of_code_commands = int(environ.get("AOC_COMMANDS_CHANNEL_ID", 607247579608121354)) diff --git a/bot/exts/evergreen/catify.py b/bot/exts/evergreen/catify.py new file mode 100644 index 00000000..a0121403 --- /dev/null +++ b/bot/exts/evergreen/catify.py @@ -0,0 +1,78 @@ +import random +from typing import Optional + +from discord import AllowedMentions, Embed +from discord.ext import commands + +from bot.constants import Cats, Colours, NEGATIVE_REPLIES + + +class Catify(commands.Cog): + """Cog for the catify command.""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + + @commands.command(aliases=["ᓚᘏᗢify", "ᓚᘏᗢ"]) + async def catify(self, ctx: commands.Context, *, text: Optional[str]) -> None: + """ + Convert the provided text into a cat themed sentence by interspercing cats throughout text. + + If no text is given then the users nickname is edited. + """ + if not text: + display_name = ctx.author.display_name + + if len(display_name) > 26: + embed = Embed( + title=random.choice(NEGATIVE_REPLIES), + description="Your nickname is too long to be catified! Please change it to be under 26 characters.", + color=Colours.soft_red + ) + await ctx.send(embed=embed) + return + + else: + display_name += f" | {random.choice(Cats.cats)}" + await ctx.send(f"Your catified username is: `{display_name}`") + await ctx.author.edit(nick=display_name) + else: + if len(text) >= 1500: + embed = Embed( + title=random.choice(NEGATIVE_REPLIES), + description="Submitted text was too large! Please submit something under 1500 characters.", + color=Colours.soft_red + ) + await ctx.send(embed=embed) + return + + string_list = text.split() + for index, name in enumerate(string_list): + if "cat" in name: + if random.randint(0, 5) == 5: + string_list[index] = string_list[index].replace("cat", f"**{random.choice(Cats.cats)}**") + else: + string_list[index] = string_list[index].replace("cat", random.choice(Cats.cats)) + for element in Cats.cats: + if element in name: + string_list[index] = string_list[index].replace(element, "cat") + + string_len = len(string_list) // 3 or len(string_list) + + for _ in range(random.randint(1, string_len)): + # insert cat at random index + if random.randint(0, 5) == 5: + string_list.insert(random.randint(0, len(string_list)), f"**{random.choice(Cats.cats)}**") + else: + string_list.insert(random.randint(0, len(string_list)), random.choice(Cats.cats)) + + text = " ".join(string_list) + await ctx.send( + f">>> {text}", + allowed_mentions=AllowedMentions.none() + ) + + +def setup(bot: commands.Bot) -> None: + """Loads the catify cog.""" + bot.add_cog(Catify(bot)) -- cgit v1.2.3 From 1f0231d725deb44b3d1ab603448680228b1942a2 Mon Sep 17 00:00:00 2001 From: Objectivitix <79152594+Objectivitix@users.noreply.github.com> Date: Sun, 9 May 2021 20:13:53 -0300 Subject: add gold colour --- bot/constants.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 6cbfa8db..884cf3a8 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -151,6 +151,7 @@ class Colours: python_blue = 0x4B8BBE python_yellow = 0xFFD43B grass_green = 0x66ff00 + gold = 0xE6C200 easter_like_colours = [ (255, 247, 0), -- cgit v1.2.3 From 358e5641d16ac27ca68c73f52cbccf12299818d6 Mon Sep 17 00:00:00 2001 From: Objectivitix <79152594+Objectivitix@users.noreply.github.com> Date: Wed, 12 May 2021 10:56:18 -0300 Subject: fix inconsistency of hexadecimal letter cases in Colours class --- bot/constants.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 9b45b89a..28ec477d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -140,19 +140,19 @@ class Client(NamedTuple): class Colours: - blue = 0x0279fd - bright_green = 0x01d277 - dark_green = 0x1f8b4c - orange = 0xe67e22 - pink = 0xcf84e0 - purple = 0xb734eb - soft_green = 0x68c290 - soft_orange = 0xf9cb54 - soft_red = 0xcd6d6d - yellow = 0xf9f586 + blue = 0x0279FD + bright_green = 0x01D277 + dark_green = 0x1F8B4C + orange = 0xE67E22 + pink = 0xCF84E0 + purple = 0xB734EB + soft_green = 0x68C290 + soft_orange = 0xF9CB54 + soft_red = 0xCD6D6D + yellow = 0xF9F586 python_blue = 0x4B8BBE python_yellow = 0xFFD43B - grass_green = 0x66ff00 + grass_green = 0x66FF00 gold = 0xE6C200 easter_like_colours = [ @@ -180,7 +180,7 @@ class Emojis: envelope = "\U0001F4E8" trashcan = environ.get("TRASHCAN_EMOJI", "<:trashcan:637136429717389331>") ok_hand = ":ok_hand:" - hand_raised = "\U0001f64b" + hand_raised = "\U0001F64B" dice_1 = "<:dice_1:755891608859443290>" dice_2 = "<:dice_2:755891608741740635>" -- cgit v1.2.3 From c6544d0fdc71be42a816c33971b19485137afcc8 Mon Sep 17 00:00:00 2001 From: Shivansh Date: Sat, 15 May 2021 09:26:43 +0530 Subject: (tic-tac-toe): Update x and o emoji --- bot/constants.py | 3 +++ bot/exts/evergreen/tic_tac_toe.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 549d01b6..d50dcc6e 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -214,6 +214,9 @@ class Emojis: x = "\U0001f1fd" o = "\U0001f1f4" + x_square = "<:x_square:632278427260682281>" + o_square = "<:o_square:632278452413661214>" + status_online = "<:status_online:470326272351010816>" status_idle = "<:status_idle:470326266625785866>" status_dnd = "<:status_dnd:470326272082313216>" diff --git a/bot/exts/evergreen/tic_tac_toe.py b/bot/exts/evergreen/tic_tac_toe.py index 6e21528e..5d0f15b4 100644 --- a/bot/exts/evergreen/tic_tac_toe.py +++ b/bot/exts/evergreen/tic_tac_toe.py @@ -79,7 +79,7 @@ class AI: """Get move from AI. AI use Minimax strategy.""" possible_moves = [i for i, emoji in board.items() if emoji in list(Emojis.number_emojis.values())] - for symbol in (Emojis.o, Emojis.x): + for symbol in (Emojis.o_square, Emojis.x_square): for move in possible_moves: board_copy = board.copy() board_copy[move] = symbol @@ -266,12 +266,12 @@ class TicTacToe(Cog): return if opponent is None: game = Game( - [Player(ctx.author, ctx, Emojis.x), AI(Emojis.o)], + [Player(ctx.author, ctx, Emojis.x_square), AI(Emojis.o_square)], ctx ) else: game = Game( - [Player(ctx.author, ctx, Emojis.x), Player(opponent, ctx, Emojis.o)], + [Player(ctx.author, ctx, Emojis.x_square), Player(opponent, ctx, Emojis.o_square)], ctx ) self.games.append(game) -- cgit v1.2.3 From 8e03537ba2c9fea98cab7645a985fc80a867da9f Mon Sep 17 00:00:00 2001 From: Shivansh-007 Date: Thu, 20 May 2021 18:32:10 +0530 Subject: Remove trailing space --- bot/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 24dd42a2..28103022 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -309,7 +309,7 @@ class Source: class RedirectOutput: delete_delay: int = 10 - + class Reddit: subreddits = ["r/Python"] -- cgit v1.2.3 From 9e89102f7061e0645563de7333fd162e431e53ef Mon Sep 17 00:00:00 2001 From: Vivaan Parashar Date: Mon, 7 Jun 2021 20:52:23 +0530 Subject: Use reddit emojis for upvote and answers --- bot/constants.py | 4 ++-- bot/exts/evergreen/stackoverflow.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index aa26be83..1c62e78b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -222,10 +222,10 @@ class Emojis: status_offline = "<:status_offline:470326266537705472>" - stackoverflow_upvote = environ.get('stack_upvote', "<:stack_upvote:*>") # TODO: Fill in numbers (ids) + # stackoverflow_upvote = environ.get('stack_upvote', "<:stack_upvote:*>") # TODO: Fill in numbers (ids) stackoverflow_tag = environ.get('stack_tag', "<:stack_tag:*> ") stackoverflow_views = environ.get('stack_views', "<:stack_eye:*>") - stackoverflow_ans = environ.get('stack_ans', "<:sta + # stackoverflow_ans = environ.get('stack_ans', "<:sta") # Reddit emojis reddit = "<:reddit:676030265734332427>" diff --git a/bot/exts/evergreen/stackoverflow.py b/bot/exts/evergreen/stackoverflow.py index e97e0318..45dcb62a 100644 --- a/bot/exts/evergreen/stackoverflow.py +++ b/bot/exts/evergreen/stackoverflow.py @@ -64,9 +64,9 @@ class Stackoverflow(commands.Cog): embed.add_field( name=unescape(item['title']), value=( - f"[{Emojis.stackoverflow_upvote} {item['score']} " + f"[{Emojis.reddit_upvote} {item['score']} " f"{Emojis.stackoverflow_views} {item['view_count']} " - f"{Emojis.stackoverflow_ans} {item['answer_count']} " + f"{Emojis.reddit_comments} {item['answer_count']} " f"{Emojis.stackoverflow_tag} {', '.join(item['tags'][:3])}]" f"({item['link']})" ), -- cgit v1.2.3 From 4374931d78dc1e3c8a6a361c6f78da4a9237a20d Mon Sep 17 00:00:00 2001 From: Vivaan Parashar Date: Wed, 9 Jun 2021 22:16:12 +0530 Subject: Remove commented emojis --- bot/constants.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index fa5dc2bc..25545c04 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -225,10 +225,8 @@ class Emojis: status_offline = "<:status_offline:470326266537705472>" - # stackoverflow_upvote = environ.get('stack_upvote', "<:stack_upvote:*>") # TODO: Fill in numbers (ids) stackoverflow_tag = environ.get('stack_tag', "<:stack_tag:*> ") stackoverflow_views = environ.get('stack_views', "<:stack_eye:*>") - # stackoverflow_ans = environ.get('stack_ans', "<:sta") # Reddit emojis reddit = "<:reddit:676030265734332427>" -- cgit v1.2.3 From 32a4b6ac1c52381520de9dbf36be7f2f2be95bec Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 9 Jun 2021 22:24:18 +0100 Subject: Update Github emoji to new icons Github updated their icons, so we should update ours too. Co-authored-by: GDWR --- bot/constants.py | 14 ++++++++------ bot/exts/evergreen/issues.py | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index f7fe216b..798cb950 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -190,12 +190,14 @@ class Emojis: dice_5 = "<:dice_5:755891608091885627>" dice_6 = "<:dice_6:755891607680843838>" - issue = "<:IssueOpen:629695470327037963>" - issue_closed = "<:IssueClosed:629695470570307614>" - pull_request = "<:PROpen:629695470175780875>" - pull_request_closed = "<:PRClosed:629695470519713818>" - pull_request_draft = "<:PRDraft:829755345425399848>" - merge = "<:PRMerged:629695470570176522>" + # These icons are from Github's repo https://github.com/primer/octicons/ + issue_opened = "<:IssueOpen:852294683731165184>" + issue_closed = "<:IssueClosed:852294683723694140>" + issue_draft = "<:IssueDraft:852294683592884284>" # Not currently used by Github, but here for future. + pull_request_open = "<:PROpen:629695470175780875>" + pull_request_closed = "<:PRClosed:852294683194294304>" + pull_request_draft = "<:PRDraft:852294683861712916>" + pull_request_merge = "<:PRMerged:629695470570176522>" number_emojis = { 1: "\u0031\ufe0f\u20e3", diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index b67aa4a6..da10047e 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -135,7 +135,7 @@ class Issues(commands.Cog): # need from the initial API call. if "issues" in json_data["html_url"]: if json_data.get("state") == "open": - emoji = Emojis.issue + emoji = Emojis.issue_opened else: emoji = Emojis.issue_closed @@ -149,10 +149,10 @@ class Issues(commands.Cog): if pull_data["draft"]: emoji = Emojis.pull_request_draft elif pull_data["state"] == "open": - emoji = Emojis.pull_request + emoji = Emojis.pull_request_open # When 'merged_at' is not None, this means that the state of the PR is merged elif pull_data["merged_at"] is not None: - emoji = Emojis.merge + emoji = Emojis.pull_request_merge else: emoji = Emojis.pull_request_closed -- cgit v1.2.3 From 07a8f19be4f1178cca26330d68c778717d267415 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 9 Jun 2021 23:03:55 +0100 Subject: Update tense of icon constants This is so the name of the constants describe the state in the correct tense Co-authored-by: Numerlor --- bot/constants.py | 4 ++-- bot/exts/evergreen/issues.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 798cb950..2c18f6e7 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -191,13 +191,13 @@ class Emojis: dice_6 = "<:dice_6:755891607680843838>" # These icons are from Github's repo https://github.com/primer/octicons/ - issue_opened = "<:IssueOpen:852294683731165184>" + issue_open = "<:IssueOpen:852294683731165184>" issue_closed = "<:IssueClosed:852294683723694140>" issue_draft = "<:IssueDraft:852294683592884284>" # Not currently used by Github, but here for future. pull_request_open = "<:PROpen:629695470175780875>" pull_request_closed = "<:PRClosed:852294683194294304>" pull_request_draft = "<:PRDraft:852294683861712916>" - pull_request_merge = "<:PRMerged:629695470570176522>" + pull_request_merged = "<:PRMerged:629695470570176522>" number_emojis = { 1: "\u0031\ufe0f\u20e3", diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index da10047e..00810de8 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -135,7 +135,7 @@ class Issues(commands.Cog): # need from the initial API call. if "issues" in json_data["html_url"]: if json_data.get("state") == "open": - emoji = Emojis.issue_opened + emoji = Emojis.issue_open else: emoji = Emojis.issue_closed @@ -152,7 +152,7 @@ class Issues(commands.Cog): emoji = Emojis.pull_request_open # When 'merged_at' is not None, this means that the state of the PR is merged elif pull_data["merged_at"] is not None: - emoji = Emojis.pull_request_merge + emoji = Emojis.pull_request_merged else: emoji = Emojis.pull_request_closed -- cgit v1.2.3 From dce6930c8be76c1f236247f41ca55ed07f590147 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 10 Jun 2021 18:25:54 +0100 Subject: Add transparent border to new Github octicons --- bot/constants.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 2c18f6e7..7bd10b5f 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -191,13 +191,13 @@ class Emojis: dice_6 = "<:dice_6:755891607680843838>" # These icons are from Github's repo https://github.com/primer/octicons/ - issue_open = "<:IssueOpen:852294683731165184>" - issue_closed = "<:IssueClosed:852294683723694140>" - issue_draft = "<:IssueDraft:852294683592884284>" # Not currently used by Github, but here for future. - pull_request_open = "<:PROpen:629695470175780875>" - pull_request_closed = "<:PRClosed:852294683194294304>" - pull_request_draft = "<:PRDraft:852294683861712916>" - pull_request_merged = "<:PRMerged:629695470570176522>" + issue_open = "<:IssueOpen:852596024777506817>" + issue_closed = "<:IssueClosed:852596024739758081>" + issue_draft = "<:IssueDraft:852596025147523102>" # Not currently used by Github, but here for future. + pull_request_open = "<:PROpen:852596471505223781>" + pull_request_closed = "<:PRClosed:852596024732286976>" + pull_request_draft = "<:PRDraft:852596025045680218>" + pull_request_merged = "<:PRMerged:852596100301193227>" number_emojis = { 1: "\u0031\ufe0f\u20e3", -- cgit v1.2.3 From ce355662afd55a5adf95335bbb50058b3eeb7891 Mon Sep 17 00:00:00 2001 From: wookie184 Date: Tue, 6 Jul 2021 17:11:41 +0100 Subject: Allow commands in code jam team channels --- bot/constants.py | 1 + bot/utils/checks.py | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 7bd10b5f..3b3d7711 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -127,6 +127,7 @@ class Categories(NamedTuple): media = 799054581991997460 staff = 364918151625965579 +codejam_categories_name = "Code Jam" # Name of the codejam team categories class Client(NamedTuple): name = "Sir Lancebot" diff --git a/bot/utils/checks.py b/bot/utils/checks.py index c06b6870..438ec750 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -75,6 +75,11 @@ def in_whitelist_check( log.trace(f"{ctx.author} may use the `{ctx.command.name}` command as they are in a whitelisted category.") return True + category = getattr(ctx.channel, "category", None) + if category and category.name == constants.codejam_categories_name: + log.trace(f"{ctx.author} may use the `{ctx.command.name}` command as they are in a codejam team channel.") + return True + # Only check the roles whitelist if we have one and ensure the author's roles attribute returns # an iterable to prevent breakage in DM channels (for if we ever decide to enable commands there). if roles and any(r.id in roles for r in getattr(ctx.author, "roles", ())): -- cgit v1.2.3 From 198d22cba0a641f96bd8d1e95a28205cf7df40de Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 6 Jul 2021 21:51:24 +0100 Subject: Remove hacktoberfest channel overrides The hacktoberfest channel has now been removed, so these overrides can also be removed. The commands may still be useful in future, and can be used in lancebot's playground. --- bot/constants.py | 1 - bot/exts/halloween/hacktoberstats.py | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 3b3d7711..ff901c8e 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -113,7 +113,6 @@ class Channels(NamedTuple): off_topic_1 = 463035241142026251 off_topic_2 = 463035268514185226 community_bot_commands = int(environ.get("CHANNEL_COMMUNITY_BOT_COMMANDS", 607247579608121354)) - hacktoberfest_2020 = 760857070781071431 voice_chat_0 = 412357430186344448 voice_chat_1 = 799647045886541885 staff_voice = 541638762007101470 diff --git a/bot/exts/halloween/hacktoberstats.py b/bot/exts/halloween/hacktoberstats.py index b74e680b..50d3aaf6 100644 --- a/bot/exts/halloween/hacktoberstats.py +++ b/bot/exts/halloween/hacktoberstats.py @@ -10,15 +10,14 @@ from async_rediscache import RedisCache from discord.ext import commands from bot.bot import Bot -from bot.constants import Channels, Colours, Month, NEGATIVE_REPLIES, Tokens, WHITELISTED_CHANNELS -from bot.utils.decorators import in_month, whitelist_override +from bot.constants import Colours, Month, NEGATIVE_REPLIES, Tokens +from bot.utils.decorators import in_month log = logging.getLogger(__name__) CURRENT_YEAR = datetime.now().year # Used to construct GH API query PRS_FOR_SHIRT = 4 # Minimum number of PRs before a shirt is awarded REVIEW_DAYS = 14 # number of days needed after PR can be mature -HACKTOBER_WHITELIST = WHITELISTED_CHANNELS + (Channels.hacktoberfest_2020,) REQUEST_HEADERS = {"User-Agent": "Python Discord Hacktoberbot"} # using repo topics API during preview period requires an accept header @@ -44,7 +43,6 @@ class HacktoberStats(commands.Cog): @in_month(Month.SEPTEMBER, Month.OCTOBER, Month.NOVEMBER) @commands.group(name="hacktoberstats", aliases=("hackstats",), invoke_without_command=True) - @whitelist_override(channels=HACKTOBER_WHITELIST) async def hacktoberstats_group(self, ctx: commands.Context, github_username: str = None) -> None: """ Display an embed for a user's Hacktoberfest contributions. @@ -72,7 +70,6 @@ class HacktoberStats(commands.Cog): @in_month(Month.SEPTEMBER, Month.OCTOBER, Month.NOVEMBER) @hacktoberstats_group.command(name="link") - @whitelist_override(channels=HACKTOBER_WHITELIST) async def link_user(self, ctx: commands.Context, github_username: str = None) -> None: """ Link the invoking user's Github github_username to their Discord ID. @@ -96,7 +93,6 @@ class HacktoberStats(commands.Cog): @in_month(Month.SEPTEMBER, Month.OCTOBER, Month.NOVEMBER) @hacktoberstats_group.command(name="unlink") - @whitelist_override(channels=HACKTOBER_WHITELIST) async def unlink_user(self, ctx: commands.Context) -> None: """Remove the invoking user's account link from the log.""" author_id, author_mention = self._author_mention_from_context(ctx) -- cgit v1.2.3 From 38add14229548d423d643d828063039010d00f80 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Tue, 3 Aug 2021 14:31:59 -0700 Subject: Added emoji IDs to constants.py --- bot/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 0a3b874a..bb602361 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -227,8 +227,8 @@ class Emojis: status_offline = "<:status_offline:470326266537705472>" - stackoverflow_tag = environ.get('stack_tag', "<:stack_tag:*> ") - stackoverflow_views = environ.get('stack_views', "<:stack_eye:*>") + stackoverflow_tag = "<:stack_tag:870926975307501570>" + stackoverflow_views = "<:stack_eye:870926992692879371>" # Reddit emojis reddit = "<:reddit:676030265734332427>" -- cgit v1.2.3 From d2e9bfb79010a6b3eb9fe5656334b7a703d4123c Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 11:57:11 +0100 Subject: Move lemojis into constants.py --- bot/constants.py | 3 +++ bot/exts/evergreen/coinflip.py | 9 +++------ 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index bb602361..b5097601 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -239,6 +239,9 @@ class Emojis: reddit_comments = "<:reddit_comments:755845255001014384>" reddit_users = "<:reddit_users:755845303822974997>" + lemon_hyperpleased = "<:lemon_hyperpleased:754441879822663811>" + lemon_pensive = "<:lemon_pensive:754441880246419486>" + class Icons: questionmark = "https://cdn.discordapp.com/emojis/512367613339369475.png" diff --git a/bot/exts/evergreen/coinflip.py b/bot/exts/evergreen/coinflip.py index 7ec5b5b9..2f9bf38b 100644 --- a/bot/exts/evergreen/coinflip.py +++ b/bot/exts/evergreen/coinflip.py @@ -4,10 +4,7 @@ from typing import Optional, Tuple from discord.ext import commands from bot.bot import Bot - - -LEMON_HYPERPLEASED = "<:lemon_hyperpleased:754441879822663811>" -LEMON_PENSIVE = "<:lemon_pensive:754441880246419486>" +from bot.constants import Emojis class CoinSide(commands.Converter): @@ -46,9 +43,9 @@ class CoinFlip(commands.Cog): message = f"{ctx.author.mention} flipped **{flipped_side}**. " if side == flipped_side: - message += f"You guessed correctly! {LEMON_HYPERPLEASED}" + message += f"You guessed correctly! {Emojis.lemon_hyperpleased}" else: - message += f"You guessed incorrectly. {LEMON_PENSIVE}" + message += f"You guessed incorrectly. {Emojis.lemon_pensive}" await ctx.send(message) -- cgit v1.2.3 From 0df47ccbfc3b399376de1f82e0ee09e96a98f76c Mon Sep 17 00:00:00 2001 From: wookie184 Date: Thu, 26 Aug 2021 13:54:17 +0100 Subject: Make bot debug constant default to true --- bot/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index bb602361..6323af80 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -134,7 +134,7 @@ class Client(NamedTuple): prefix = environ.get("PREFIX", ".") token = environ.get("BOT_TOKEN") sentry_dsn = environ.get("BOT_SENTRY_DSN") - debug = environ.get("BOT_DEBUG", "").lower() == "true" + debug = environ.get("BOT_DEBUG", "true").lower() == "true" github_bot_repo = "https://github.com/python-discord/sir-lancebot" # Override seasonal locks: 1 (January) to 12 (December) month_override = int(environ["MONTH_OVERRIDE"]) if "MONTH_OVERRIDE" in environ else None -- cgit v1.2.3