Skip to content

Commit

Permalink
Merge pull request #17 from Local-Connectivity-Lab/ticket-601
Browse files Browse the repository at this point in the history
Ticket 601
  • Loading branch information
philion authored Apr 4, 2024
2 parents 8aa577f + cca9b17 commit 78c450b
Show file tree
Hide file tree
Showing 15 changed files with 814 additions and 458 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.DS_Store
pyrightconfig.json
27 changes: 0 additions & 27 deletions cog_scn.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class SCNCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.redmine: Client = bot.redmine
self.sync_all_threads.start() # pylint: disable=no-member

# see https://github.com/Pycord-Development/pycord/blob/master/examples/app_commands/slash_cog_groups.py

Expand Down Expand Up @@ -110,32 +109,6 @@ async def sync_thread(self, thread:discord.Thread):
return None


@tasks.loop(minutes=1.0) # FIXME to 5.0 minutes. set to 1 min for testing
async def sync_all_threads(self):
"""
Configured to run every minute using the tasks.loop annotation.
Get all Threads and sync each one.
"""
log.info(f"sync_all_threads: starting for {self.bot.guilds}")

# get all threads
for guild in self.bot.guilds:
for thread in guild.threads:
try:
# try syncing each thread. if there's no ticket found, there's no thread to sync.
ticket = await self.sync_thread(thread)
if ticket:
# successful sync
log.debug(f"SYNC complete for ticket #{ticket.id} to {thread.name}")
#else:
#log.debug(f"no ticket found for {thread.name}")
except NetbotException as ex:
# ticket is locked.
# skip gracefully
log.debug(f"Ticket locked, sync in progress: {thread}: {ex}")
except Exception:
log.exception(f"Error syncing {thread}")

@scn.command()
async def sync(self, ctx:discord.ApplicationContext):
"""syncronize an existing ticket thread with redmine"""
Expand Down
21 changes: 3 additions & 18 deletions cog_tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,14 @@
import discord

from discord.commands import option
from discord.ext import commands
from discord.ext import commands, tasks

from model import Message
from tickets import Ticket
from model import Message, Ticket
from redmine import Client


log = logging.getLogger(__name__)

# scn add redmine_login - setup discord userid in redmine
# scn sync - manually sychs the current thread, or replies with warning
# scn sync

# scn join teamname - discord user joins team teamname (and maps user id)
# scn leave teamname - discord user leaves team teamname (and maps user id)

# scn reindex

def setup(bot):
bot.add_cog(TicketsCog(bot))
Expand All @@ -35,16 +26,9 @@ class TicketsCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.redmine: Client = bot.redmine
log.debug(f"Initialized with {self.redmine}")

# see https://github.com/Pycord-Development/pycord/blob/master/examples/app_commands/slash_cog_groups.py

#tickets - all the queries

#ticket # show (default) - show ticket info
#ticket # notes - show ticket will all notes (in a decent format)
#ticket # note - add a note to the specific ticket. same as commenting in the ticket thread (if there is one, works without)
#ticket # sync - creates new synced thread for ticket in the current text channel, or errors

# figure out what the term refers to
# could be ticket#, team name, user name or search term
Expand All @@ -62,6 +46,7 @@ def resolve_query_term(self, term):
# assume a search term
return self.redmine.search_tickets(term)


@commands.slash_command() # guild_ids=[...] # Create a slash command for the supplied guilds.
async def tickets(self, ctx: discord.ApplicationContext, params: str = ""):
"""List tickets for you, or filtered by parameter"""
Expand Down
14 changes: 13 additions & 1 deletion formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import discord

from tickets import Ticket, TicketManager
from model import Ticket
from tickets import TicketManager
from session import RedmineSession
import synctime

Expand Down Expand Up @@ -129,6 +130,17 @@ def format_ticket_details(self, ticket:Ticket) -> str:
return details


def format_expiration_notification(self, ticket:Ticket):
# format an alert.
# https://discord.com/developers/docs/interactions/message-components#action-rows
# action row with what options?
# :warning:
# ⚠️
# [icon] **Alert** [Ticket x](link) will expire in x hours, as xyz.
return f"ALERT: Expiring ticket: {ticket}" #FIXME
# return self.format_alert(message)


def main():
ticket_manager = TicketManager(RedmineSession.fromenvfile())

Expand Down
Loading

0 comments on commit 78c450b

Please sign in to comment.