moved support functionality to firstline bot

Signed-off-by: Marc Ahlgrim <marc@onemarcfifty.com>
This commit is contained in:
Marc Ahlgrim
2022-07-23 18:29:21 +02:00
parent d113d50967
commit 2e25186e96
6 changed files with 44 additions and 129 deletions
+4 -1
View File
@@ -2,12 +2,15 @@
R.A.L.F. (short for Responsive Artificial Lifeform ;-) ) is the "housekeeping" bot on the oneMarcFifty Discord Server R.A.L.F. (short for Responsive Artificial Lifeform ;-) ) is the "housekeeping" bot on the oneMarcFifty Discord Server
It can do the following things (release version 0.3): It can do the following things (release version 0.2):
- reply with "pong" to a "ping" (WHOA!!!) - reply with "pong" to a "ping" (WHOA!!!)
- Send out configurable random messages when the server is idle (like "Did you know...") - Send out configurable random messages when the server is idle (like "Did you know...")
- automatically create Events (we have Sunday video sessions at 9 AM and 6 PM) - automatically create Events (we have Sunday video sessions at 9 AM and 6 PM)
- remind subscribers of upcoming events - remind subscribers of upcoming events
Planned (release 0.3)
- Help the user create a support thread with a modal view - Help the user create a support thread with a modal view
- let the user subscribe / unsubscribe to notification messages with a modal view - let the user subscribe / unsubscribe to notification messages with a modal view
+1 -1
View File
@@ -1,5 +1,5 @@
Hi, this is R.A.L.F., your assistant bot. Hi, this is R.A.L.F., your assistant bot.
Please check in every now and then to the <#866779182293057566> channel. Please check in every now and then to the <#954732247909552149> channel.
This is where folks here on the server ask for help. This is where folks here on the server ask for help.
Maybe **** YOU **** can help someone there ? Maybe **** YOU **** can help someone there ?
+23 -47
View File
@@ -13,7 +13,6 @@ from discord import app_commands
from discord.ext import tasks from discord.ext import tasks
from classes.dis_events import DiscordEvents from classes.dis_events import DiscordEvents
from classes.support import Support
from classes.subscribe import Subscribe from classes.subscribe import Subscribe
@@ -25,11 +24,11 @@ from classes.subscribe import Subscribe
class OMFClient(discord.Client): class OMFClient(discord.Client):
channel_idle_timer: int channel_idle_timer: int
asked_question = False
last_question: discord.Message = None
lastNotifyTimeStamp = None lastNotifyTimeStamp = None
theGuild : discord.Guild = None theGuild : discord.Guild = None
lastSentMessage:discord.Message=None
guildEventsList = None guildEventsList = None
guildEventsClass: DiscordEvents = None guildEventsClass: DiscordEvents = None
@@ -51,15 +50,6 @@ class OMFClient(discord.Client):
self.tree = app_commands.CommandTree(self) self.tree = app_commands.CommandTree(self)
# The support command will ask for a thread title and description
# and create a support thread for us
@self.tree.command(name="support", description="Create a support thread")
async def support(interaction: discord.Interaction):
x : Support
x= Support()
await interaction.response.send_modal(x)
# The subscribe command will add/remove the notification roles # The subscribe command will add/remove the notification roles
# based on the scheduled events # based on the scheduled events
@@ -153,14 +143,6 @@ class OMFClient(discord.Client):
self.daily_tasks.start() self.daily_tasks.start()
# ######################################################
# handle_ping is called when a user sends ping
# (case sensitive, exact phrase)
# it just replies with pong
# ######################################################
async def handle_ping (self,message : discord.Message):
await message.channel.send('pong', reference=message)
# ###################################################### # ######################################################
# create_events will create the Sunday Funday events # create_events will create the Sunday Funday events
@@ -220,7 +202,28 @@ class OMFClient(discord.Client):
# ###################################################### # ######################################################
async def on_message(self, message : discord.Message ): async def on_message(self, message : discord.Message ):
# ignore ephemeral messages
if message.flags.ephemeral:
return
print("{} has just sent {}".format(message.author, message.content)) print("{} has just sent {}".format(message.author, message.content))
# if the author of the previously last sent message and
# the new message is ourselves, then delete the
# previous message
if (int(f'{config.CONFIG["AVOID_SPAM"]}') == 1) and (self.lastSentMessage is not None):
if ((message.author == self.user) and
(self.lastSentMessage.author == self. user) and
(int(f"{self.lastSentMessage.channel.id}") == (int(config.CONFIG["IDLE_MESSAGE_CHANNEL_ID"])))):
try:
await self.lastSentMessage.delete()
except Exception as e:
print(f"delete lastmessage error: {e}")
self.lastSentMessage = message
# don't respond to ourselves # don't respond to ourselves
if message.author == self.user: if message.author == self.user:
@@ -229,17 +232,6 @@ class OMFClient(discord.Client):
# reset the idle timer if a message has been sent or received # reset the idle timer if a message has been sent or received
self.channel_idle_timer = 0 self.channel_idle_timer = 0
# reply to ping
if message.content == 'ping':
await self.handle_ping(message)
# check if there is a question
if "?" in message.content:
self.asked_question = True
self.last_question = message
else:
self.asked_question = False
self.last_question = None
# ###################################################### # ######################################################
# on_typing detects if a user types. # on_typing detects if a user types.
@@ -292,22 +284,6 @@ class OMFClient(discord.Client):
self.channel_idle_timer += 1 self.channel_idle_timer += 1
print("SCHEDULE") print("SCHEDULE")
# #####################################
# See if there are unanswered questions
# #####################################
try:
if(self.asked_question):
print("scheduler: Question")
print(self.last_question.created_at)
# TODO - we need to send out a message to the @here role
# asking users to help if the question had not been answered
# Also - if the message is a reply then we should not post into the channel
if self.channel_idle_timer > config.CONFIG["QUESTION_SLEEPING_TIME"]:
print("QUESTION WITHOUT REPLY")
self.asked_question = False
except Exception as e:
print(f"Scheduler question failed: {e}")
# ##################################### # #####################################
# see if we need to send a random message # see if we need to send a random message
# if the counter is greater than CHANNEL_IDLE_INTERVAL # if the counter is greater than CHANNEL_IDLE_INTERVAL
-79
View File
@@ -1,79 +0,0 @@
import discord
import traceback
import config
# ############################################
# the Support() class is a modal ui dialog
# that helps you create a thread in a
# selected channel. It asks for a title
# and a description and then creates
# a Thread in the config.CONFIG["SUPPORT_CHANNEL_ID"]
# channel. It also sends a message to the
# config.CONFIG["IDLE_MESSAGE_CHANNEL_ID"]
# in order to notify everyone that a
# new support message has been created
# ############################################
class Support(discord.ui.Modal, title='Open a support thread'):
# This will be a short input, where the user can enter a title
# for the new thread
theTitle = discord.ui.TextInput(
label='Title',
placeholder='a catchy title for the issue',
)
# This is a longer, paragraph style input, where user can submit
# a description of the problem
theDescription = discord.ui.TextInput(
label='Describe the problem',
style=discord.TextStyle.long,
placeholder='Type in what the problem is...',
required=False,
max_length=300,
)
# ############################################
# on_submit is called when the user submits the
# Modal. This is where we create the thread
# and send all related messages
# ############################################
async def on_submit(self, interaction: discord.Interaction):
# first let's find out which channel we will create the thread in
theGuild = interaction.guild
theChannel : discord.TextChannel
theChannel = theGuild.get_channel(config.CONFIG["SUPPORT_CHANNEL_ID"])
if not (theChannel is None):
try:
# we send a message into that channel that serves as "hook" for the thread
# (if we didn't have a message to hook then the thread would be created
# as private which requires a boost level)
xMsg= await theChannel.send (f"Support Thread for <@{interaction.user.id}>")
newThread=await theChannel.create_thread(name=f"{self.theTitle.value}",message=xMsg,auto_archive_duration=1440)
# next we want to post about the new "ticket" in the IDLE_MESSAGE_CHANNEL
theChannel = theGuild.get_channel(config.CONFIG["IDLE_MESSAGE_CHANNEL_ID"])
if (not (theChannel is None)) and (not (newThread is None)):
xMsg= await theChannel.send (f'I have created a **Support Thread** on behalf of <@{interaction.user.id}> :\n\n <#{newThread.id}> in the <#{config.CONFIG["SUPPORT_CHANNEL_ID"]}>\n\nMaybe you could check in and see if **you** can help ??? \nMany thanks !')
xMsg= await newThread.send (f'<@{interaction.user.id}> describes the problem as follows: \n{self.theDescription.value} \n \n please tag the user on your reply - thank you!' )
except Exception as e:
print(f"Support Error: {e}")
# last but not least we send an ephemeral message to the user
# linking to the created thread
await interaction.response.send_message(f'Your Support Thread has been created here: <#{newThread.id}> Please check if everything is correct.\nThank you for using my services!', ephemeral=True)
async def on_error(self, interaction: discord.Interaction, error: Exception) -> None:
await interaction.response.send_message('Oops! Something went wrong.', ephemeral=True)
# Make sure we know what the error actually is
traceback.print_tb(error.__traceback__)
+14
View File
@@ -0,0 +1,14 @@
[Unit]
Description=discord-ralf
After=multi-user.target
[Service]
WorkingDirectory=/home/discord/discord-ralf
User=tin
Group=tin
ExecStart=/usr/bin/python3 /home/discord/discord-ralf/main.py
Type=idle
Restart=always
RestartSec=15
[Install]
WantedBy=multi-user.target
+2 -1
View File
@@ -3,7 +3,8 @@
{ {
"BOT_TOKEN" : "YOURBOTTOKEN", "BOT_TOKEN" : "YOURBOTTOKEN",
"GUILD_ID" : "YOURGUILDID", "GUILD_ID" : "YOURGUILDID",
"CLIENT_ID" : "YOURCLIENTID" "CLIENT_ID" : "YOURCLIENTID",
"AVOID_SPAM" : 1
}, },
"config" : "config" :
{ {