-
Notifications
You must be signed in to change notification settings - Fork 0
/
InlineTicketHandler.py
43 lines (40 loc) · 2.21 KB
/
InlineTicketHandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import re
import snotparser.snotparser as sp
from datetime import datetime
from string import Template
import string
import CommandHandler as ch
from RedmineTicketFetcher import RedmineTicketFetcher
from shadow import chronicle
class InlineTicketHandler:
def privmsg(self, client, user, channel, msg):
inlineTicketMatch(client, user, channel, msg)
def action(self, client, nick, channel, msg):
inlineTicketMatch(client, nick, channel, msg)
def formatTicketList(ticketNumbers):
formattedTickets = map(lambda l : string.join(l, "#"), ticketNumbers)
return string.join(formattedTickets, ", ")
def inlineTicketMatch(client, user, channel, msg):
ticketNumbers = re.findall("(\w+)?#(\d+)", msg)
#print ticketNumbers
if ticketNumbers:
client.logger.write("%s requested ticket(s) %s in %s" % (user, formatTicketList(ticketNumbers), channel))
for ticket in ticketNumbers:
ticketType = ticket[0].lower()
if ticketType in ['','snot','tts']:
if int(ticket[1]) >= client.config['snot']['minimumInline']:
client.msg(channel, sp.formatTicketSmart(int(ticket[1]), client.config['snot']['formatString'], client.config['snot']['defaultCommand']))
# client.msg(channel, sp.formatTicket(int(ticket[1]), "$number (SNOT) | $from_line | $assigned_to | $subject | $flags"))
elif ticketType in ['testsnot']:
client.msg(channel, sp.formatTicket(int(ticket[1]), "$number (TESTSNOT) | $from_line | $assigned_to | $subject | $flags", 'testsnot'))
elif ticketType == 'c':
try:
d = client.redmine_instance.getTicket(int(ticket[1]))
if d['project'] != "Mentor Sessions" or channel == "#mentors":
client.msg(channel, str(Template("$id ($project) | $author | $assigned_to | $subject | $tracker | https://chronicle.cat.pdx.edu/issues/$id").safe_substitute(d)))
except Exception as e:
print "%s: %s" % (ticket[1], e)
client.msg(channel, "%s: %s" % (ticket[1], e))
else:
pass
# client.msg(channel, "Unrecognized ticket type '%s'" % ticket[0])