From 83d9173cdcd8671dedf5400dde81caac21e37634 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Tue, 7 Apr 2020 11:57:13 +0300 Subject: (Constants, TicTacToe): Added number emojis that will be shown in board and in reactions. --- bot/constants.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index ca9bb94a..0135124b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -118,6 +118,19 @@ class Emojis: pull_request_closed = "<:PRClosed:629695470519713818>" merge = "<:PRMerged:629695470570176522>" + # TicTacToe Emojis + number_emojis = { + 1: "\u0031", + 2: "\u0032", + 3: "\u0033", + 4: "\u0034", + 5: "\u0035", + 6: "\u0036", + 7: "\u0037", + 8: "\u0038", + 9: "\u0039" + } + class Hacktoberfest(NamedTuple): voice_id = 514420006474219521 -- cgit v1.2.3 From 1abec1772f140f886b84fb43c394527553cb271a Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Tue, 7 Apr 2020 11:59:12 +0300 Subject: (Constants, TicTacToe): Added confirmation and declining emojis. --- bot/constants.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 0135124b..a23c6bcc 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -130,6 +130,8 @@ class Emojis: 8: "\u0038", 9: "\u0039" } + confirmation = "\u2705" + decline = "\u274c" class Hacktoberfest(NamedTuple): -- cgit v1.2.3 From fb9523b9c5e93ff30cdc58ac451e807da323c8b4 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Tue, 7 Apr 2020 12:01:26 +0300 Subject: (Constants, TicTacToe): Added X and O emojis. --- bot/constants.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index a23c6bcc..d43cf4d3 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -132,6 +132,8 @@ class Emojis: } confirmation = "\u2705" decline = "\u274c" + x = "\U0001f1fd" + o = "\U0001f1f4" class Hacktoberfest(NamedTuple): -- cgit v1.2.3 From 7a7385bf222c24f78356ea46331ae5d4abddb65a Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Tue, 7 Apr 2020 19:33:05 +0300 Subject: (Constants, TicTacToe): Fixed number emojis contants, created helper function `send_board` to `Game` class. --- bot/constants.py | 18 +++++++++--------- bot/exts/evergreen/tic_tac_toe.py | 23 +++++++++++++++++++++-- 2 files changed, 30 insertions(+), 11 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index d43cf4d3..a8dd03e6 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -120,15 +120,15 @@ class Emojis: # TicTacToe Emojis number_emojis = { - 1: "\u0031", - 2: "\u0032", - 3: "\u0033", - 4: "\u0034", - 5: "\u0035", - 6: "\u0036", - 7: "\u0037", - 8: "\u0038", - 9: "\u0039" + 1: "\u0031\ufe0f\u20e3", + 2: "\u0032\ufe0f\u20e3", + 3: "\u0033\ufe0f\u20e3", + 4: "\u0034\ufe0f\u20e3", + 5: "\u0035\ufe0f\u20e3", + 6: "\u0036\ufe0f\u20e3", + 7: "\u0037\ufe0f\u20e3", + 8: "\u0038\ufe0f\u20e3", + 9: "\u0039\ufe0f\u20e3" } confirmation = "\u2705" decline = "\u274c" diff --git a/bot/exts/evergreen/tic_tac_toe.py b/bot/exts/evergreen/tic_tac_toe.py index 1a906535..55bbb7be 100644 --- a/bot/exts/evergreen/tic_tac_toe.py +++ b/bot/exts/evergreen/tic_tac_toe.py @@ -28,6 +28,11 @@ class Game: self.channel = channel self.players = players self.ctx = ctx + self.board = [ + [Emojis.number_emojis[1], Emojis.number_emojis[2], Emojis.number_emojis[3]], + [Emojis.number_emojis[4], Emojis.number_emojis[5], Emojis.number_emojis[6]], + [Emojis.number_emojis[7], Emojis.number_emojis[8], Emojis.number_emojis[9]] + ] self.current = self.players[0] self.next = self.players[1] @@ -74,9 +79,18 @@ class Game: async def add_reactions(self, msg: discord.Message) -> None: """Add number emojis to message.""" - for nr in Emojis.number_emojis: + for nr in Emojis.number_emojis.values(): await msg.add_reaction(nr) + async def send_board(self) -> discord.Message: + """Send board and return it's message.""" + msg = "" + for line in self.board: + msg += " ".join(line) + msg += "\n" + message = await self.ctx.send(msg) + return message + def is_channel_free() -> t.Callable: """Check is channel where command will be invoked free.""" @@ -113,7 +127,12 @@ class TicTacToe(Cog): ctx ) self.games.append(game) - await game.get_confirmation() + confirmed, msg = await game.get_confirmation() + + if not confirmed: + if msg: + await ctx.send(msg) + return def setup(bot: SeasonalBot) -> None: -- cgit v1.2.3 From a7ffa0926b47bf40cd034eeb2b5e9d5dcd04798f Mon Sep 17 00:00:00 2001 From: Shivansh-007 Date: Wed, 27 Jan 2021 10:43:19 +0530 Subject: Add check for in category and in remove overide_channel check and do it without decorator --- bot/constants.py | 8 ++++++++ bot/exts/evergreen/issues.py | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 1d41a53e..ce1ca29a 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -9,6 +9,7 @@ __all__ = ( "AdventOfCode", "Branding", "Channels", + "Categories", "Client", "Colours", "Emojis", @@ -100,6 +101,7 @@ class Channels(NamedTuple): big_brother_logs = 468507907357409333 bot = 267659945086812160 checkpoint_test = 422077681434099723 + organisation = 551789653284356126 devalerts = 460181980097675264 devlog = int(environ.get("CHANNEL_DEVLOG", 622895325144940554)) dev_contrib = 635950537262759947 @@ -128,6 +130,12 @@ class Channels(NamedTuple): voice_chat_1 = 799647045886541885 +class Categories(NamedTuple): + development = 411199786025484308 + devprojects = 787641585624940544 + media = 799054581991997460 + + class Client(NamedTuple): name = "Sir Lancebot" guild = int(environ.get("BOT_GUILD", 267624335836053506)) diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index d2c70d4b..4ab3df2c 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -7,8 +7,7 @@ from enum import Enum import discord from discord.ext import commands, tasks -from bot.constants import Channels, Colours, ERROR_REPLIES, Emojis, Tokens, WHITELISTED_CHANNELS -from bot.utils.decorators import override_in_channel +from bot.constants import Categories, Channels, Colours, ERROR_REPLIES, Emojis, Tokens, WHITELISTED_CHANNELS log = logging.getLogger(__name__) @@ -16,13 +15,19 @@ BAD_RESPONSE = { 404: "Issue/pull request not located! Please enter a valid number!", 403: "Rate limit has been hit! Please try again later!" } + MAX_REQUESTS = 10 REQUEST_HEADERS = dict() -PYTHON_DISCORD_REPOS = "https://api.github.com/orgs/{repo}/repos" +PYTHON_DISCORD_REPOS = "https://api.github.com/orgs/{repo}/repos" if GITHUB_TOKEN := Tokens.github: REQUEST_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}" +WHITELISTED_CATEGORIES = ( + Categories.devprojects, Categories.media, Categories.development +) +WHITELISTED_CHANNELS += (Channels.organisation) + CODE_BLOCK_RE = re.compile( r"^`([^`\n]+)`" # Inline codeblock r"|```(.+?)```", # Multiline codeblock @@ -135,7 +140,6 @@ class Issues(commands.Cog): return resp @commands.command(aliases=("pr",)) - @override_in_channel(WHITELISTED_CHANNELS + (Channels.dev_contrib, Channels.dev_branding)) async def issue( self, ctx: commands.Context, @@ -144,6 +148,9 @@ class Issues(commands.Cog): user: str = "python-discord" ) -> None: """Command to retrieve issue(s) from a GitHub repository.""" + if ctx.channel.category not in WHITELISTED_CATEGORIES or ctx.channel.category in WHITELISTED_CHANNELS: + return + result = await self.fetch_issues(set(numbers), repository, user) if result == FetchIssueErrors.value_error: @@ -166,9 +173,11 @@ class Issues(commands.Cog): await ctx.send(result) @commands.Cog.listener() - @override_in_channel(WHITELISTED_CHANNELS + (Channels.dev_contrib, Channels.dev_branding)) async def on_message(self, message: discord.Message) -> None: """Command to retrieve issue(s) from a GitHub repository using automatic linking if matching #.""" + if message.channel.category not in WHITELISTED_CATEGORIES or message.channel.category in WHITELISTED_CHANNELS: + return + message_repo_issue_map = re.findall(fr".+?({self.repo_regex})#(\d+)", message.content) links = [] -- cgit v1.2.3 From 45af7ff6803e75d70be8d78e232b3d30803ae65d Mon Sep 17 00:00:00 2001 From: Shivansh-007 Date: Sun, 31 Jan 2021 05:13:35 +0530 Subject: Add mod_meta and mod_tools channels to whitelisted --- bot/constants.py | 2 ++ bot/exts/evergreen/issues.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index ce1ca29a..1234ef3b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -116,6 +116,8 @@ class Channels(NamedTuple): 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 diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 72d88d04..f24e0717 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -26,7 +26,7 @@ if GITHUB_TOKEN := Tokens.github: WHITELISTED_CATEGORIES = ( Categories.devprojects, Categories.media, Categories.development ) -WHITELISTED_CHANNELS_ON_MESSAGE = (Channels.organisation,) +WHITELISTED_CHANNELS_ON_MESSAGE = (Channels.organisation, Channels.mod_meta, Channels.mod_tools) CODE_BLOCK_RE = re.compile( r"^`([^`\n]+)`" # Inline codeblock -- cgit v1.2.3 From 3e884eaa43b78b433a470aaff39b03a0f6c2b3c2 Mon Sep 17 00:00:00 2001 From: Shivansh-007 Date: Tue, 2 Feb 2021 06:05:46 +0530 Subject: Allow cht.sh command to be used in occupied help channels --- bot/constants.py | 11 +++++------ bot/exts/evergreen/cheatsheet.py | 13 +++++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 1d41a53e..23865272 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -104,12 +104,6 @@ class Channels(NamedTuple): devlog = int(environ.get("CHANNEL_DEVLOG", 622895325144940554)) dev_contrib = 635950537262759947 dev_branding = 753252897059373066 - help_0 = 303906576991780866 - help_1 = 303906556754395136 - help_2 = 303906514266226689 - help_3 = 439702951246692352 - help_4 = 451312046647148554 - help_5 = 454941769734422538 helpers = 385474242440986624 message_log = 467752170159079424 mod_alerts = 473092532147060736 @@ -128,6 +122,10 @@ class Channels(NamedTuple): voice_chat_1 = 799647045886541885 +class Categories(NamedTuple): + help_in_use = 696958401460043776 + + class Client(NamedTuple): name = "Sir Lancebot" guild = int(environ.get("BOT_GUILD", 267624335836053506)) @@ -249,6 +247,7 @@ class Roles(NamedTuple): rockstars = 458226413825294336 core_developers = 587606783669829632 events_lead = 778361735739998228 + everyone = 267624335836053506 class Tokens(NamedTuple): diff --git a/bot/exts/evergreen/cheatsheet.py b/bot/exts/evergreen/cheatsheet.py index c83af839..83098c76 100644 --- a/bot/exts/evergreen/cheatsheet.py +++ b/bot/exts/evergreen/cheatsheet.py @@ -3,13 +3,13 @@ import re import typing as t from urllib.parse import quote_plus -from discord import Embed +from discord import Embed, utils from discord.ext import commands from discord.ext.commands import BucketType, Context from bot import constants -from bot.constants import Channels, Colours, ERROR_REPLIES, WHITELISTED_CHANNELS -from bot.utils.decorators import override_in_channel +from bot.constants import Categories, Channels, Colours, ERROR_REPLIES, Roles, WHITELISTED_CHANNELS +from bot.utils.decorators import with_role ERROR_MESSAGE = f""" Unknown cheat sheet. Please try to reformulate your query. @@ -72,8 +72,8 @@ class CheatSheet(commands.Cog): name="cheat", aliases=("cht.sh", "cheatsheet", "cheat-sheet", "cht"), ) - @override_in_channel(WHITELISTED_CHANNELS) @commands.cooldown(1, 10, BucketType.user) + @with_role(Roles.everyone) async def cheat_sheet(self, ctx: Context, *search_terms: str) -> None: """ Search cheat.sh. @@ -82,6 +82,11 @@ class CheatSheet(commands.Cog): Usage: --> .cht read json """ + category = utils.get(ctx.message.guild.categories, id=Categories.help_in_use) + all_allowed_channels = WHITELISTED_CHANNELS + tuple(category.channels) + if ctx.channel not in all_allowed_channels: + return + async with self.bot.http_session.get( URL.format(search=quote_plus(" ".join(search_terms))) ) as response: -- cgit v1.2.3 From 5190f5b8576267807dd6a4920964d684f0d572a4 Mon Sep 17 00:00:00 2001 From: Shivansh-007 Date: Tue, 2 Feb 2021 06:17:58 +0530 Subject: everyone -> everyone_role and remove developers role --- bot/constants.py | 3 +-- bot/exts/evergreen/cheatsheet.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 23865272..8e210ad3 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -236,7 +236,6 @@ class Roles(NamedTuple): announcements = 463658397560995840 champion = 430492892331769857 contributor = 295488872404484098 - developer = 352427296948486144 devops = 409416496733880320 jammer = 423054537079783434 moderator = 267629731250176001 @@ -247,7 +246,7 @@ class Roles(NamedTuple): rockstars = 458226413825294336 core_developers = 587606783669829632 events_lead = 778361735739998228 - everyone = 267624335836053506 + everyone_role = 267624335836053506 class Tokens(NamedTuple): diff --git a/bot/exts/evergreen/cheatsheet.py b/bot/exts/evergreen/cheatsheet.py index abc5306b..f650e3b0 100644 --- a/bot/exts/evergreen/cheatsheet.py +++ b/bot/exts/evergreen/cheatsheet.py @@ -73,7 +73,7 @@ class CheatSheet(commands.Cog): aliases=("cht.sh", "cheatsheet", "cheat-sheet", "cht"), ) @commands.cooldown(1, 10, BucketType.user) - @with_role(Roles.everyone) + @with_role(Roles.everyone_role) async def cheat_sheet(self, ctx: Context, *search_terms: str) -> None: """ Search cheat.sh. -- cgit v1.2.3 From 86dc294eb22f233ccd381529a8191d2285889784 Mon Sep 17 00:00:00 2001 From: Shivansh-007 Date: Mon, 22 Feb 2021 20:40:56 +0530 Subject: Goodbye Wikipedia Class, no need of you anymore --- bot/constants.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index bb538487..c31cd958 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -281,10 +281,6 @@ class RedisConfig(NamedTuple): use_fakeredis = environ.get("USE_FAKEREDIS", "false").lower() == "true" -class Wikipedia: - total_chance = 3 - - class Source: github = "https://github.com/python-discord/sir-lancebot" github_avatar_url = "https://avatars1.githubusercontent.com/u/9919" -- 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 13dad6bf796a6009db4ff768795a3d45d044ff0e Mon Sep 17 00:00:00 2001 From: Shivansh-007 Date: Tue, 23 Feb 2021 16:46:08 +0530 Subject: Fix pipfile conflicts, and add/use emojis from constants.py --- Pipfile.lock | 21 +++++++++++++++------ bot/constants.py | 5 ++++- bot/exts/evergreen/connect_four.py | 37 +++++++++---------------------------- 3 files changed, 28 insertions(+), 35 deletions(-) (limited to 'bot/constants.py') diff --git a/Pipfile.lock b/Pipfile.lock index bd894ffa..ec801979 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "9be419062bd9db364ac9dddfcd50aef9c932384b45850363e482591fe7d12403" + "sha256": "b4aaaacbab13179145e36d7b86c736db512286f6cce8e513cc30c48d68fe3810" }, "pipfile-spec": 6, "requires": { @@ -161,6 +161,14 @@ "index": "pypi", "version": "==1.5.1" }, + "emojis": { + "hashes": [ + "sha256:7da34c8a78ae262fd68cef9e2c78a3c1feb59784489eeea0f54ba1d4b7111c7c", + "sha256:bf605d1f1a27a81cd37fe82eb65781c904467f569295a541c33710b97e4225ec" + ], + "index": "pypi", + "version": "==0.6.0" + }, "fakeredis": { "hashes": [ "sha256:01cb47d2286825a171fb49c0e445b1fa9307087e07cbb3d027ea10dbff108b6a", @@ -406,10 +414,11 @@ }, "sentry-sdk": { "hashes": [ - "sha256:3693cb47ba8d90c004ac002425770b32aaf0c83a846ec48e2d1364e7db1d072d" + "sha256:4ae8d1ced6c67f1c8ea51d82a16721c166c489b76876c9f2c202b8a50334b237", + "sha256:e75c8c58932bda8cd293ea8e4b242527129e1caaec91433d21b8b2f20fee030b" ], "index": "pypi", - "version": "==0.20.1" + "version": "==0.20.3" }, "six": { "hashes": [ @@ -576,11 +585,11 @@ }, "identify": { "hashes": [ - "sha256:70b638cf4743f33042bebb3b51e25261a0a10e80f978739f17e7fd4837664a66", - "sha256:9dfb63a2e871b807e3ba62f029813552a24b5289504f5b071dea9b041aee9fe4" + "sha256:de7129142a5c86d75a52b96f394d94d96d497881d2aaf8eafe320cdbe8ac4bcc", + "sha256:e0dae57c0397629ce13c289f6ddde0204edf518f557bfdb1e56474aa143e77c3" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.5.13" + "version": "==1.5.14" }, "mccabe": { "hashes": [ diff --git a/bot/constants.py b/bot/constants.py index bb538487..682ccf6f 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -165,6 +165,7 @@ class Emojis: envelope = "\U0001F4E8" trashcan = "<:trashcan:637136429717389331>" ok_hand = ":ok_hand:" + hand_raised = "\U0001f64b" dice_1 = "<:dice_1:755891608859443290>" dice_2 = "<:dice_2:755891608741740635>" @@ -179,7 +180,6 @@ class Emojis: pull_request_closed = "<:PRClosed:629695470519713818>" merge = "<:PRMerged:629695470570176522>" - # TicTacToe Emojis number_emojis = { 1: "\u0031\ufe0f\u20e3", 2: "\u0032\ufe0f\u20e3", @@ -191,8 +191,11 @@ class Emojis: 8: "\u0038\ufe0f\u20e3", 9: "\u0039\ufe0f\u20e3" } + confirmation = "\u2705" decline = "\u274c" + incident_unactioned = "<:incident_unactioned:719645583245180960>" + x = "\U0001f1fd" o = "\U0001f1f4" diff --git a/bot/exts/evergreen/connect_four.py b/bot/exts/evergreen/connect_four.py index 02e876f4..65458dbc 100644 --- a/bot/exts/evergreen/connect_four.py +++ b/bot/exts/evergreen/connect_four.py @@ -7,30 +7,11 @@ import discord import emojis from discord.ext import commands -NUMBERS = [ - ":one:", - ":two:", - ":three:", - ":four:", - ":five:", - ":six:", - ":seven:", - ":eight:", - ":nine:" -] -UNICODE_NUMBERS = [ - "\u0031\u20e3", - "\u0032\u20e3", - "\u0033\u20e3", - "\u0034\u20e3", - "\u0035\u20e3", - "\u0036\u20e3", - "\u0037\u20e3", - "\u0038\u20e3", - "\u0039\u20e3", -] -CROSS_EMOJI = "\u274e" -HAND_RAISED_EMOJI = "\U0001f64b" +from bot.constants import Emojis + +NUMBERS = list(Emojis.number_emojis.values()) +CROSS_EMOJI = Emojis.incident_unactioned + Coordinate = typing.Optional[typing.Tuple[int, int]] EMOJI_CHECK = typing.Union[discord.Emoji, str] @@ -57,7 +38,7 @@ class Game: self.grid = self.generate_board(size) self.grid_size = size - self.unicode_numbers = UNICODE_NUMBERS[:self.grid_size] + self.unicode_numbers = NUMBERS[:self.grid_size] self.message = None @@ -313,7 +294,7 @@ class ConnectFour(commands.Cog): if ( user.id not in (ctx.me.id, ctx.author.id) - and str(reaction.emoji) == HAND_RAISED_EMOJI + and str(reaction.emoji) == Emojis.hand_raised and reaction.message.id == announcement.id ): if self.already_playing(user): @@ -406,11 +387,11 @@ class ConnectFour(commands.Cog): announcement = await ctx.send( "**Connect Four**: A new game is about to start!\n" - f"Press {HAND_RAISED_EMOJI} to play against {ctx.author.mention}!\n" + f"Press {Emojis.hand_raised} to play against {ctx.author.mention}!\n" f"(Cancel the game with {CROSS_EMOJI}.)" ) self.waiting.append(ctx.author) - await announcement.add_reaction(HAND_RAISED_EMOJI) + await announcement.add_reaction(Emojis.hand_raised) await announcement.add_reaction(CROSS_EMOJI) try: -- cgit v1.2.3 From f429ce6aaa57d680893be0cbd5a7760de947aac6 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 28 Feb 2021 19:48:13 +0000 Subject: Add issue cog to staff channels. --- bot/constants.py | 2 ++ bot/exts/evergreen/issues.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 682ccf6f..9b7e37f8 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -124,6 +124,7 @@ class Channels(NamedTuple): hacktoberfest_2020 = 760857070781071431 voice_chat_0 = 412357430186344448 voice_chat_1 = 799647045886541885 + staff_voice = 541638762007101470 class Categories(NamedTuple): @@ -131,6 +132,7 @@ class Categories(NamedTuple): development = 411199786025484308 devprojects = 787641585624940544 media = 799054581991997460 + staff = 364918151625965579 class Client(NamedTuple): diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 73ebe547..03d0a86b 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -24,9 +24,11 @@ if GITHUB_TOKEN := Tokens.github: REQUEST_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}" WHITELISTED_CATEGORIES = ( - Categories.devprojects, Categories.media, Categories.development + Categories.devprojects, Categories.media, Categories.development, Categories.staff +) +WHITELISTED_CHANNELS_ON_MESSAGE = ( + Channels.organisation, Channels.mod_meta, Channels.mod_tools, Channels.staff_voice ) -WHITELISTED_CHANNELS_ON_MESSAGE = (Channels.organisation, Channels.mod_meta, Channels.mod_tools) CODE_BLOCK_RE = re.compile( r"^`([^`\n]+)`" # Inline codeblock -- 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