-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
44a7bc4
commit 2873b3b
Showing
11 changed files
with
84 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |