Skip to content

Commit 0b97c2a

Browse files
authored
Allow bot to be run on different networks (#13)
1 parent a0dcb69 commit 0b97c2a

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ This is the bot which replaces the following types of mentions with their URLs:
66
* `"!nnnn"` or `"PRnnnn"` -- Pull request nnnn submitted to the django/django GitHub repo
77
* `"hhhhhhh"` (7 or more chars) -- Commit with ID hhhhhhh in the django/django GitHub repo
88

9-
It has a registered nick in Freenode: *ticketbot*.
10-
119
## Local setup
1210

1311
1. Create a virtualenv making sure you use the same Python version as the one specified to Heroku in `runtime.txt`:
1412

1513
$ curl https://raw.githubusercontent.com/django/ticketbot/master/runtime.txt
16-
python-3.6.3
14+
python-3.7.2
1715

1816
2. Once you've created and activated the virtualenv, install project dependencies:
1917

@@ -23,13 +21,19 @@ It has a registered nick in Freenode: *ticketbot*.
2321

2422
It needs the following env vars:
2523

26-
* `NICKSERV_PASS` -- The bot's Freenode user password
24+
* `NICKSERV_PASS` -- The bot's user password
25+
* `NICKSERV_USER` -- The bot's username
26+
* `IRC_HOST` -- The IRC server hostname to connect to
27+
* `IRC_PORT` -- The IRC server port to connect to
2728
* `CHANNELS` -- A comma-separated list of channels it will auto-join to
2829

2930
Example, for running it locally:
3031

3132
$ export NICKSERV_PASS=password
32-
$ export CHANNELS=#django-social,#django,#django-dev,#django-sprint,#django-core
33+
$ export NICKSERV_USER=username
34+
$ export IRC_HOST=irc.libera.chat
35+
$ export IRC_PORT=6697
36+
$ export CHANNELS=#django-social,#django,#django-dev,#django-sprint
3337
$ python ticketbot.py
3438

3539
## Tests

ticketbot.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
The #django-dev ticket bot.
33
"""
44

5-
from collections import namedtuple
65
import os
76
import re
7+
from collections import namedtuple
88

99
import irc3
1010
import requests
1111

12-
NICK = 'ticketbot'
13-
1412
ticket_re = re.compile(r'(?<!build)(?:^|\s)#(\d+)')
1513
ticket_url = "https://code.djangoproject.com/ticket/%s"
1614

@@ -115,20 +113,23 @@ def process_msg_or_privmsg(self, mask, event, target, data, **kw):
115113

116114
def main():
117115
password = os.environ['NICKSERV_PASS']
116+
username = os.environ['NICKSERV_USER']
117+
host = os.environ['IRC_HOST']
118+
port = int(os.environ['IRC_PORT'])
118119
channels = os.environ['CHANNELS'].split(',')
119120
bot = irc3.IrcBot.from_config(dict(
120-
nick=NICK,
121-
username=NICK,
121+
nick=username,
122+
username=username,
122123
realname='Django project development helper bot',
123-
sasl_username=NICK,
124+
sasl_username=username,
124125
sasl_password=password,
125126
url='https://github.com/django/ticketbot',
126127
autojoins=channels,
127-
host='chat.freenode.net', port=6667, ssl=False,
128+
host=host, port=port, ssl=True,
128129
includes=[
129130
'irc3.plugins.core',
130131
'irc3.plugins.sasl',
131-
__name__, # this register our Plugin
132+
__name__, # this registers our plugin
132133
],
133134
# debug=True,
134135
# verbose=True,

0 commit comments

Comments
 (0)