moved support functionality to firstline bot
Signed-off-by: Marc Ahlgrim <marc@onemarcfifty.com>
This commit is contained in:
+23
-47
@@ -13,7 +13,6 @@ from discord import app_commands
|
||||
from discord.ext import tasks
|
||||
|
||||
from classes.dis_events import DiscordEvents
|
||||
from classes.support import Support
|
||||
from classes.subscribe import Subscribe
|
||||
|
||||
|
||||
@@ -25,11 +24,11 @@ from classes.subscribe import Subscribe
|
||||
class OMFClient(discord.Client):
|
||||
|
||||
channel_idle_timer: int
|
||||
asked_question = False
|
||||
last_question: discord.Message = None
|
||||
lastNotifyTimeStamp = None
|
||||
theGuild : discord.Guild = None
|
||||
|
||||
lastSentMessage:discord.Message=None
|
||||
|
||||
guildEventsList = None
|
||||
guildEventsClass: DiscordEvents = None
|
||||
|
||||
@@ -51,15 +50,6 @@ class OMFClient(discord.Client):
|
||||
|
||||
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
|
||||
# based on the scheduled events
|
||||
|
||||
@@ -153,14 +143,6 @@ class OMFClient(discord.Client):
|
||||
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
|
||||
@@ -220,7 +202,28 @@ class OMFClient(discord.Client):
|
||||
# ######################################################
|
||||
|
||||
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))
|
||||
# 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
|
||||
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
|
||||
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.
|
||||
@@ -292,22 +284,6 @@ class OMFClient(discord.Client):
|
||||
self.channel_idle_timer += 1
|
||||
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
|
||||
# if the counter is greater than CHANNEL_IDLE_INTERVAL
|
||||
|
||||
@@ -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__)
|
||||
Reference in New Issue
Block a user