Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Early-Bird Role to the Early-Bird user #29

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
1 change: 0 additions & 1 deletion .github/workflows/python-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 --volume=./:/usr/src/MorningBot/ -d morningbot:latest
Expand Down
33 changes: 30 additions & 3 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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"]
Expand All @@ -36,6 +37,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+)$"
Expand Down Expand Up @@ -87,8 +89,22 @@ 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
EARLYBIRD_ROLE = discord.utils.get(
client.get_guild(SERVER_ID).roles, name="Early Bird"
)

# 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"])
Expand All @@ -107,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

Expand All @@ -123,6 +138,11 @@ async def on_message(message):
server_leaders.add_point(message.author)
return

# Add the earlybird role to the first user to say good morning
await FIRST_GM_USER.add_roles(EARLYBIRD_ROLE)

await message.add_reaction(EARLY_EMOJI)

server_leaders.add_point(message.author)
await message.add_reaction(MORNING_EMOJI)

Expand All @@ -149,6 +169,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)
Expand All @@ -161,7 +182,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=(
Expand All @@ -180,6 +200,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
Expand All @@ -202,13 +225,17 @@ async def send_message():
color=0x00FF00,
)
embed.set_image(url=random.choice(MORNING_GIFS))

await channel.send(embed=embed)

# Reset early bird every day

FIRST_GM = False
FIRST_GM_USER = None

return
return


def sighandle_exit(sig, frame):
print(sig, frame)
Expand Down
1 change: 1 addition & 0 deletions config/configuration_data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"server_name": "CS++",
"server_id": 941006603761614868,
"timezone": "Europe/Dublin",
"channel_id": 941006604403363953,
"morning_emoji": "☀️",
Expand Down
Loading