From 498d801e7ee3d0ca5a7825cbd3b46579c1b27c21 Mon Sep 17 00:00:00 2001 From: Sam Curran <83888868+Sam2004-2@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:18:39 +0000 Subject: [PATCH 1/8] Adding an early bird role, unsure if fully usable --- bot/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bot/__init__.py b/bot/__init__.py index f5aca49..b403bd9 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -32,6 +32,7 @@ DEBUG_MODE = configuration_data["debug_mode"] DEBUG_TIME = 9 # debug line >1 DEBUG_MINUTE = "01:00" # debug line >2 +EARLYBIRD_ROLE = None #Add Early Bird role to the server PATTERN = r"^passx debug_time = (\d+)$" PATTERN2 = r"^passx debug_minute = (\d+:\d+)$" @@ -86,6 +87,11 @@ async def on_ready(): print(f"We have logged in as {client.user}, time is {get_current_hour()}") send_message.start() + # Get the early bird role + global EARLYBIRD_ROLE + EARLYBIRD_ROLE = discord.utils.get(client.get_guild(SERVER_NAME).roles, name="Early Bird") + + FIRST_GM = False FIRST_GM_USER = None @@ -112,6 +118,10 @@ async def on_message(message): FIRST_GM_USER = message.author FIRST_GM = True + # Add the earlybird role to the first user to say good morning + if EARLYBIRD_ROLE is not None: + await FIRST_GM_USER.add_roles(EARLYBIRD_ROLE) + await message.add_reaction(EARLY_EMOJI) return await message.add_reaction(MORNING_EMOJI) From 0ce163ce5bc520a5a1c7232347f9d0f6d75fa0d1 Mon Sep 17 00:00:00 2001 From: Sam Curran <83888868+Sam2004-2@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:30:53 +0000 Subject: [PATCH 2/8] Added a check for the bot to see if the EarlyBird role exists. If it doesn't, it will create it. --- bot/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bot/__init__.py b/bot/__init__.py index b403bd9..8c58445 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -91,6 +91,10 @@ async def on_ready(): global EARLYBIRD_ROLE EARLYBIRD_ROLE = discord.utils.get(client.get_guild(SERVER_NAME).roles, name="Early Bird") + # If the early bird role does not exist, create it + if EARLYBIRD_ROLE is None: + await client.get_guild(SERVER_NAME).create_role(name="Early Bird") + FIRST_GM = False From 946006981ee7a64cc7fdbdc0438d30173d882a79 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 4 Oct 2023 15:05:10 +0100 Subject: [PATCH 3/8] formatting and small logic changes --- bot/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index 8c58445..0345a05 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -32,7 +32,7 @@ DEBUG_MODE = configuration_data["debug_mode"] DEBUG_TIME = 9 # debug line >1 DEBUG_MINUTE = "01:00" # debug line >2 -EARLYBIRD_ROLE = None #Add Early Bird role to the server +EARLYBIRD_ROLE = None # Add Early Bird role to the server PATTERN = r"^passx debug_time = (\d+)$" PATTERN2 = r"^passx debug_minute = (\d+:\d+)$" @@ -89,14 +89,15 @@ async def on_ready(): # Get the early bird role global EARLYBIRD_ROLE - EARLYBIRD_ROLE = discord.utils.get(client.get_guild(SERVER_NAME).roles, name="Early Bird") + EARLYBIRD_ROLE = discord.utils.get( + client.get_guild(SERVER_NAME).roles, name="Early Bird" + ) - # If the early bird role does not exist, create it + # If the early bird role does not exist, create it if EARLYBIRD_ROLE is None: await client.get_guild(SERVER_NAME).create_role(name="Early Bird") - FIRST_GM = False FIRST_GM_USER = None @@ -123,7 +124,7 @@ async def on_message(message): FIRST_GM = True # Add the earlybird role to the first user to say good morning - if EARLYBIRD_ROLE is not None: + if EARLYBIRD_ROLE: await FIRST_GM_USER.add_roles(EARLYBIRD_ROLE) await message.add_reaction(EARLY_EMOJI) From b42260c9106140a284b81cc801fedb220d258cf4 Mon Sep 17 00:00:00 2001 From: Sam Curran <83888868+Sam2004-2@users.noreply.github.com> Date: Tue, 10 Oct 2023 00:24:32 +0000 Subject: [PATCH 4/8] Fixes to the logic of the earlybird role + Server_ID added --- bot/__init__.py | 5 +++-- config/configuration_data.json | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index 0345a05..41fd690 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -24,6 +24,7 @@ EARLY_EMOJI = configuration_data["early_emoji"] BAD_MORNING_EMOJI = configuration_data["bad_morning_emoji"] SERVER_NAME = configuration_data["server_name"] +SERVER_ID = configuration_data["server_id"] CHANNEL_ID = configuration_data["channel_id"] MORNING_GIFS = configuration_data["good_morning_gif_urls"] WEATHER_API_KEY = configuration_data["weather_api_key"] @@ -90,12 +91,12 @@ async def on_ready(): # Get the early bird role global EARLYBIRD_ROLE EARLYBIRD_ROLE = discord.utils.get( - client.get_guild(SERVER_NAME).roles, name="Early Bird" + client.get_guild(SERVER_ID).roles, name="Early Bird" ) # If the early bird role does not exist, create it if EARLYBIRD_ROLE is None: - await client.get_guild(SERVER_NAME).create_role(name="Early Bird") + await client.get_guild(SERVER_ID).create_role(name="Early Bird") FIRST_GM = False diff --git a/config/configuration_data.json b/config/configuration_data.json index 7736db1..4280aed 100644 --- a/config/configuration_data.json +++ b/config/configuration_data.json @@ -1,5 +1,6 @@ { "server_name": "CS++", + "server_id": "941006603761614868", "timezone": "Europe/Dublin", "channel_id": 941006604403363953, "morning_emoji": "☀️", From dcbd3d0e68751a434645de095ad6d1491eb1691a Mon Sep 17 00:00:00 2001 From: Sam Curran <83888868+Sam2004-2@users.noreply.github.com> Date: Tue, 10 Oct 2023 23:57:59 +0000 Subject: [PATCH 5/8] Updated configuration_data.json --- config/configuration_data.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/configuration_data.json b/config/configuration_data.json index 4280aed..fc0cf02 100644 --- a/config/configuration_data.json +++ b/config/configuration_data.json @@ -1,6 +1,6 @@ { "server_name": "CS++", - "server_id": "941006603761614868", + "server_id": 941006603761614868, "timezone": "Europe/Dublin", "channel_id": 941006604403363953, "morning_emoji": "☀️", From 234529658547f5b3c8e79fef216078cfcb8b2490 Mon Sep 17 00:00:00 2001 From: Sam Curran <83888868+Sam2004-2@users.noreply.github.com> Date: Thu, 12 Oct 2023 00:00:31 +0100 Subject: [PATCH 6/8] Update README.md Adding bot permissions within the server --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5667761..b0d0e9a 100644 --- a/README.md +++ b/README.md @@ -31,19 +31,21 @@ pip install -r requirements.txt - The Discord channel id. This will allow MorningBot to send the 'Good morning' and send the 'Early bird' messages -5. 🚀 Run the bot. +5. Grant the Bot permission to add/update roles. This will ensure that the bot can succesfully update users roles. + +6. 🚀 Run the bot. ```bash python3 . ``` -6. 🐳 Build the image. +7. 🐳 Build the image. ```bash docker build -t morningbot . ``` -7. 🐳 Run the container. +8. 🐳 Run the container. ```bash docker run -d --name morningbot morningbot From b5689f9a3b58e46129ccb3a472003c5908f69db7 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 14 Oct 2023 22:10:05 +0100 Subject: [PATCH 7/8] some logical changes, if the role isn't found it will create it in the onready function --- bot/__init__.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index 2252d3d..896ecbf 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -89,19 +89,23 @@ def get_current_minute(): @client.event async def on_ready(): + global EARLYBIRD_ROLE + send_message.start() - print(f"We have logged in as {client.user}, time is {get_current_hour()}") # Get the early bird role - global EARLYBIRD_ROLE EARLYBIRD_ROLE = discord.utils.get( client.get_guild(SERVER_ID).roles, name="Early Bird" ) - # If the early bird role does not exist, create it + # If the early bird role does not exist, create it and write it to the global if EARLYBIRD_ROLE is None: await client.get_guild(SERVER_ID).create_role(name="Early Bird") + EARLYBIRD_ROLE = discord.utils.get( + client.get_guild(SERVER_ID).roles, name="Early Bird" + ) + server_leaders = leaderboard.Leaderboard(configuration_data["channel_id"]) FIRST_GM = False @@ -119,7 +123,6 @@ async def on_message(message): if 6 <= get_current_hour() <= 12: if "bad morning" in contents: - print("bad morning detected") await message.add_reaction(BAD_MORNING_EMOJI) return @@ -130,8 +133,7 @@ async def on_message(message): FIRST_GM = True # Add the earlybird role to the first user to say good morning - if EARLYBIRD_ROLE: - await FIRST_GM_USER.add_roles(EARLYBIRD_ROLE) + await FIRST_GM_USER.add_roles(EARLYBIRD_ROLE) await message.add_reaction(EARLY_EMOJI) server_leaders.add_point(message.author) @@ -162,6 +164,7 @@ async def on_message(message): DEBUG_MINUTE = extracted_number print(f"debug time changed to {extracted_number}") await message.channel.send(f"debug minute changed to {extracted_number}") + return @tasks.loop(seconds=60) @@ -174,7 +177,6 @@ async def send_message(): news_data = get_news() channel = client.get_channel(CHANNEL_ID) - print(channel) embed = discord.Embed( title="Good Morning," + SERVER_NAME + "!", description=( @@ -193,6 +195,9 @@ async def send_message(): embed.set_thumbnail(url=f"https:{weather_data[3]}") embed.set_image(url=random.choice(MORNING_GIFS)) await channel.send(embed=embed) + await FIRST_GM_USER.remove_roles(EARLYBIRD_ROLE) + + return if get_current_minute() == "13:00": # If theres no early bird, dont send the message @@ -215,6 +220,7 @@ async def send_message(): color=0x00FF00, ) embed.set_image(url=random.choice(MORNING_GIFS)) + await channel.send(embed=embed) # Reset early bird every day @@ -222,6 +228,9 @@ async def send_message(): FIRST_GM = False FIRST_GM_USER = None + return + return + def sighandle_exit(sig, frame): print(sig, frame) From 1188871b68826630dc770f0f052f92236962d59f Mon Sep 17 00:00:00 2001 From: David Date: Sat, 14 Oct 2023 22:14:06 +0100 Subject: [PATCH 8/8] tidying up and renaming actions (this should be it's own PR but I'm feeling bold --- .github/workflows/json-lint.yaml | 2 +- .github/workflows/python-lint.yaml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/json-lint.yaml b/.github/workflows/json-lint.yaml index 6b1635a..3cf9549 100644 --- a/.github/workflows/json-lint.yaml +++ b/.github/workflows/json-lint.yaml @@ -2,7 +2,7 @@ name: Json-Validate run-name: ${{ github.actor }} PR being linted for code cleanliness on: [pull_request] jobs: - Lint: + json-lint: runs-on: ubuntu-latest steps: - run: echo "Job triggered by ${{ github.event_name }} event." diff --git a/.github/workflows/python-lint.yaml b/.github/workflows/python-lint.yaml index 4204f6e..b7f71ea 100644 --- a/.github/workflows/python-lint.yaml +++ b/.github/workflows/python-lint.yaml @@ -2,7 +2,7 @@ name: Test-Lint run-name: ${{ github.actor }} PR being linted for code cleanliness on: [pull_request] jobs: - Lint: + python-lint: runs-on: ubuntu-latest steps: - run: echo "Job triggered by ${{ github.event_name }} event." @@ -13,6 +13,5 @@ jobs: - uses: actions/checkout@v3 - run: pip install -r requirements.txt - run: echo "Checked out into ${{ github.repository }} on branch ${{ github.ref }}" - - run: ls - run: black . --diff - run: pylint **/*.py --rcfile=.pylintrc