Skip to content

Commit

Permalink
Apply changes made in owlbotv2 (#3)
Browse files Browse the repository at this point in the history
* Added automated messaging process on member join, removed member ping before mission event as the automation will now be implemented via discord events.

* Barebones Event Functionality, specialized event warning to users using embeds on the pipeline.

Exception handling in case there's no events on the server when the bot wakes up.

* Basic event functionality implemented, still not finished.

Eventualities such as edited events are still not contemplated, and are TODO.

Event deletions, manual event starts and edits to discord events are not detected.

background task that checks if the event has started unconsistently throws Exception due to ts.ip being detected as a url.

on_message event is a test method that will be deleted later.

* Code refactor removing all event-related testing has been removed until further expansion on the OWLBOT's functions.

role and channel IDs related to the on_member_join event embed message are now environment variables.

TODO: work on a method that creates embeds to follow DRY principle.

* Fix wrong single quotes in f-string

* Remove debug print of bot token

* Update prod GitHub workflow with directory structure, remove use of  tag for now

---------

Co-authored-by: UmiLovesU2 <[email protected]>
  • Loading branch information
enrico-ghidoni and UmiLovesU2 authored Jul 14, 2024
1 parent 44a7bc4 commit 2873b3b
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 44 deletions.
5 changes: 4 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
OP_START_CHANNEL_ID=<OP_START_CHANNEL_ID>
OP_START_CHANNEL_ID=
GUILD_ID=
INTERVIEWER_ROLE_ID=
WELCOME_CHANNEL_ID=
5 changes: 3 additions & 2 deletions .github/workflows/dev-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ jobs:
name: Checkout repository
uses: actions/checkout@v4
with:
path: 'owlbot-repo'
path: 'discord-owlbot'
-
name: Build the Docker image
run: docker build . --file owlbot-repo/Dockerfile --tag cntoarma/owlbot:dev
working-directory: discord-owlbot
run: docker build . --file Dockerfile --tag cntoarma/owlbot:dev
-
name: Authenticate to CNTO DockerHub
uses: docker/login-action@v3
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/stable-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ jobs:
name: Checkout repository
uses: actions/checkout@v4
with:
path: 'owlbot-repo'
path: 'discord-owlbot'
-
name: Build the Docker image
run: docker build . --file owlbot-repo/Dockerfile --tag cntoarma/owlbot:latest
working-directory: discord-owlbot
run: docker build . --file Dockerfile --tag cntoarma/owlbot:1.0.0
-
name: Authenticate to CNTO DockerHub
uses: docker/login-action@v3
Expand All @@ -28,4 +29,4 @@ jobs:
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Publish image to DockerHub
run: docker image push cntoarma/owlbot:latest
run: docker image push cntoarma/owlbot:1.0.0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
log
*.log
.env.local*
config.henrik-test-server
discord-token.txt

# Byte-compiled / optimized / DLL files
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.19

ADD owlbot-repo /owlbot
ADD . /owlbot
WORKDIR /owlbot

RUN apk add --no-cache python3 py3-pip
Expand Down
4 changes: 4 additions & 0 deletions config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
NOTIFICATION_CHANNEL_ID=342739973923143680
WELCOME_CHANNEL_ID=814513168772628540
GUILD_ID=154907081256730624
INTERVIEWER_ROLE_ID=331492014883602433
4 changes: 4 additions & 0 deletions config.cnto-test-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
NOTIFICATION_CHANNEL_ID=1101131950745464842
WELCOME_CHANNEL_ID=1101087724007587930
GUILD_ID=1101050893526388758
INTERVIEWER_ROLE_ID=1101061472391536660
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
owlbot:
container_name: owlbot
# restart: unless-stopped
env_file: .env
env_file: ./config
image: cntoarma/owlbot:dev
secrets:
- discord_token
Expand Down
1 change: 0 additions & 1 deletion op-reminder.sh

This file was deleted.

35 changes: 0 additions & 35 deletions op-start-reminder.py

This file was deleted.

62 changes: 62 additions & 0 deletions owlbot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import sys
import discord

# Discord secret and configuration variables retrieval
BOT_SECRET = None
try:
with open('/run/secrets/discord_token', 'r') as f:
BOT_SECRET = f.read()
except FileNotFoundError:
print("No docker secret")
exit(1)

NOTIFICATION_CHANNEL_ID = os.environ['NOTIFICATION_CHANNEL_ID']
WELCOME_CHANNEL_ID= os.environ['WELCOME_CHANNEL_ID']
GUILD_ID = os.environ['GUILD_ID']
INTERVIEWER_ROLE_ID= os.environ['INTERVIEWER_ROLE_ID']

class OwlbotMemberWelcome(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args,**kwargs)

async def on_ready(self):
print('Logged on as', self.user)
guild = await self.fetch_guild(GUILD_ID)

async def on_member_join(self, member):
guild = member.guild
embed = discord.Embed(title="Welcome to CNTO!", color=0xffffff, url="https://cnto-arma.com")
embed.set_author(name="CNTO Server")
embed.set_thumbnail(url="https://forum.cnto-arma.com/uploads/default/original/1X/9e032c33053b34a2bd57d7e90ac03250c7fd3054.png")
embed.add_field(name="", value=f"Hello {member.mention}, Welcome to Carpe Noctem Tactical Operations. Feel free to message an <@&{INTERVIEWER_ROLE_ID}> or take a look at <#{WELCOME_CHANNEL_ID}> if you have any questions! ", inline=True)

# member joined_at function returns datetime object, strf formats output as follows: Day of Week, Number of day, initials of month, year, hour of day in GMT timezone
embed.set_footer(text=f"{member.joined_at.strftime('%a %d %b %Y, %I:%M%p')}")
await guild.system_channel.send(embed = embed)


class OwlbotOperationNotification(discord.Client):
async def on_ready(self):
channel = await self.fetch_channel(NOTIFICATION_CHANNEL_ID)
# TODO: remove embedded role ids and overall message to make it configurable
await channel.send("Tonight's mission will start soon. <@&220093887518081024> and <@&665323023699673108> grab a drink and join us!")
await self.close()

intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
intents.members = True

if __name__ == '__main__':
if len(sys.argv) == 1:
print("Starting member welcome workflow")
client = OwlbotMemberWelcome(intents=intents)
elif len(sys.argv) == 2 and sys.argv[1] == "operation-notification":
print("Starting operation notification workflow")
client = OwlbotOperationNotification(intents=intents)
else:
print("Invalid parameter. Only 'operation-notification' is allowed.")
exit(1)

client.run(BOT_SECRET)

0 comments on commit 2873b3b

Please sign in to comment.