2
# Copyright (c) 2005, Andrew Harvey
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions are met:
8
# * Redistributions of source code must retain the above copyright notice,
9
# this list of conditions, and the following disclaimer.
10
# * Redistributions in binary form must reproduce the above copyright notice,
11
# this list of conditions, and the following disclaimer in the
12
# documentation and/or other materials provided with the distribution.
13
# * Neither the name of the author of this software nor the name of
14
# contributors to this software may be used to endorse or promote products
15
# derived from this software without specific prior written consent.
17
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
30
import supybot.utils as utils
31
from supybot.commands import *
32
import supybot.utils.web as web
33
import supybot.plugins as plugins
34
import supybot.ircutils as ircutils
35
import supybot.callbacks as callbacks
36
import supybot.ircmsgs as ircmsgs
41
class TracBot(callbacks.Plugin):
42
"""TracBot plugin provides plugins for use with the Trac issue tracking
46
def ticket(self, irc, msg, args, channel, ticketno):
48
returns a link to that ticket on the Trac Site
50
if self.registryValue('tracBase', channel) is not "":
51
base = self.registryValue('tracBase', channel)
52
reply = '%s/ticket/%d' % (base, ticketno)
54
reply = "TracBot does not have a tracBase defined for this channel"
56
ticket = wrap(ticket,['channel', 'int'])
58
def wiki(self, irc, msg, args, channel, page):
60
returns a link to the wiki page on the Trac Site
62
if self.registryValue('tracBase', channel) is not "":
63
base = self.registryValue('tracBase', channel)
64
reply = base + '/wiki/' + page
66
reply = "TracBot does not have a tracBase defined for this channel"
68
wiki = wrap(wiki,['channel', 'somethingWithoutSpaces'])
70
def show(self, irc, msg, args, nick, page):
72
Gives <nick> the link to <page>. Acceptable values are currently
73
"bugs", "troubleshooting" and "requests"
76
reply = nick +': Learn about reporting bugs here => http://trac.adiumx.com/wiki/ReportingBugs'
77
elif page == "requests":
78
reply = nick + ': Learn about requesting features here => http://trac.adiumx.com/wiki/RequestingFeatures'
79
elif page == "troubleshooting":
80
reply = nick + ': Learn about troubleshooting AdiumX here => http://trac.adiumx.com/wiki/Troubleshooting'
82
show = wrap(show, ['nick', ("literal", ("bugs", "troubleshooting", "requests"), "The only currently available options are bugs, troubleshooting and requests")])
84
def tracsearch(self, irc, msg, args, channel, type, page):
85
"""[<type>] <searchstring>
86
returns a link to a search of the Adium Trac Site for <searchstring>
87
<type> can either be "wiki", "tickets", "changesets" or "commits"
89
if self.registryValue('tracBase', channel) is not "":
90
base = self.registryValue('tracBase', channel)
91
urlised = utils.web.urlquote(page)
93
reply = base + '/search?q=' + urlised + '&wiki=on'
94
elif type == "tickets":
95
reply = base + '/search?q=' + urlised + '&ticket=on'
96
elif type == "changesets":
97
reply = base + '/search?q=' + urlised + '&changeset=on'
98
elif type == "commits":
99
reply = base + '/search?q=' + urlised + '&changeset=on'
101
reply = base + '/search?q=' + urlised + '&wiki=on&ticket=on&changeset=on'
103
reply = "TracBot does not have a tracBase defined for this channel"
105
tracsearch = wrap(tracsearch,['channel', optional(('literal', ("wiki", "tickets", "changesets", "commits"), "Borked.")), 'text'])
107
def newticket(self, irc, msg, args, channel):
109
Gives the link to the trac ticket submission page.
111
if self.registryValue('tracBase', channel) is not "":
112
base = self.registryValue('tracBase', channel)
113
reply = base + '/newticket'
115
reply = "TracBot does not have a tracBase defined for this channel"
117
newticket = wrap(newticket, ['channel'])
120
def changeset(self, irc, msg, args, channel, changesetno):
121
"""<changeset number>
122
Returns a link to changeset <changeset number> on the Adium trac site
124
if self.registryValue('tracBase', channel) is not "":
125
base = self.registryValue('tracBase', channel)
126
reply = '%s/changeset/%d' % (base, changesetno)
128
reply = "TracBot does not have a tracBase defined for this channel"
130
changeset = wrap(changeset, ['channel', 'int'])
133
def maketicket(self, irc, msg, args, channel, optlist, summary, description):
134
"""[--type=<type>] [--reporter=<reporter>] [--component=<component>] [--owner=<owner>] \
135
[--milestone=<milestone>] [--version=<version>] "<summary>" <description>
137
Submit a new ticket with summary <summary> and description <description> with the supplied
140
if self.registryValue('tracBase', channel) is not "":
141
base = self.registryValue('tracBase', channel)
142
url = '%s/newticket' % base.rstrip('/')
143
postdata={'reporter': msg.nick,
145
'description': description,
148
for (opt, value) in optlist:
149
postdata[opt] = value
151
page = self._openUrl(url, postdata)
154
if 'id="ticket"' in page:
155
number = page.split('<title>', 1)[-1].split(' ', 1)[0]
156
number = number.strip('#')
157
reply = ('New ticket at: %s/ticket/%s' %
158
(base.rstrip('/'), number))
160
reply = 'Posting a new ticket failed.'
162
reply = 'TracBot does not have a tracBase defined for this channel.'
164
maketicket = wrap(maketicket, ['channel',
165
getopts({'type': None,
171
'something', 'text'])
173
def _openUrl(self, url, postdata={}):
174
data = urllib.urlencode(postdata)
175
request = urllib2.Request(url, data=data)
176
return web.getUrl(request)
178
def wikipedia(self, irc, msg, args, wiki_string):
180
Returns a link to the page on wikipedia for <wiki string>
182
import string, urllib
183
to_underscore = string.maketrans(' ', '_')
184
reply = "http://en.wikipedia.org/wiki/" + urllib.quote(wiki_string.translate(to_underscore))
186
wikipedia = wrap(wikipedia, ['text'])
192
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: