Skip to content
This repository has been archived by the owner on May 26, 2018. It is now read-only.

Commit

Permalink
Fixed the ipv6 setting on all bots so that it would actually work; ch…
Browse files Browse the repository at this point in the history
…anged the setting to "ipv6" instead of "ipv6_support". Refactored all the bots to have sane defaults management with ConfigParserPlus.
  • Loading branch information
micolous committed Jul 3, 2012
1 parent 43ecf2f commit 294c0e0
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 59 deletions.
3 changes: 3 additions & 0 deletions ethicsbot.example.ini
Expand Up @@ -10,6 +10,9 @@ channel = #ethicsbot
; NickServ password
;nickserv_pass = password

; Use an ipv6 socket rather than an ipv4 one
ipv6 = no

;; OTHER OPTIONS
; The bot has an internal "cooldown timer" which controls under what conditions
; it believes it is being flooded. If someone messages a command to regexbot
Expand Down
28 changes: 19 additions & 9 deletions ethicsbot.py
Expand Up @@ -20,7 +20,7 @@
import asyncore, random
from hashlib import sha512
from datetime import datetime, timedelta
from ConfigParser import ConfigParser
from configparser_plus import ConfigParserPlus
from sys import argv, exit
from ircasync import *
from subprocess import Popen, PIPE
Expand Down Expand Up @@ -57,7 +57,19 @@

ETHICAL_STATES_COUNT = len(ETHICAL_STATES)

config = ConfigParser()
DEFAULT_CONFIG = {
'ethicsbot': {
'server': 'localhost',
'port': DEFAULT_PORT,
'ipv6': 'no',
'nick': 'ethicsbot',
'channel': '#test',
'flood_cooldown': 5,
'version': 'ethicsbot; https://github.com/micolous/ircbots/',
}
}

config = ConfigParserPlus(DEFAULT_CONFIG)
try:
config.readfp(open(argv[1]))
except:
Expand All @@ -73,19 +85,17 @@

# read config
SERVER = config.get('ethicsbot', 'server')
try: PORT = config.getint('ethicsbot', 'port')
except: PORT = DEFAULT_PORT
try: IPV6 = ( config.getint('ethicsbot', 'ipv6_support') == "yes" )
except: IPV6 = False
PORT = config.getint('ethicsbot', 'port')
IPV6 = config.getboolean('ethicsbot', 'ipv6')
NICK = config.get('ethicsbot', 'nick')
CHANNEL = config.get('ethicsbot', 'channel')
VERSION = 'ethicsbot; https://github.com/micolous/ircbots/; %s'
VERSION = config.get('ethicsbot', 'version') + '; %s'

try: VERSION = VERSION % Popen(["git","branch","-v","--contains"], stdout=PIPE).communicate()[0].strip()
except: VERSION = VERSION % 'unknown'
del Popen, PIPE

try: FLOOD_COOLDOWN = timedelta(seconds=config.getint('ethicsbot', 'flood_cooldown'))
except: FLOOD_COOLDOWN = timedelta(seconds=5)
FLOOD_COOLDOWN = timedelta(seconds=config.getint('ethicsbot', 'flood_cooldown'))
try: NICKSERV_PASS = config.get('ethicsbot', 'nickserv_pass')
except: NICKSERV_PASS = None

Expand Down
2 changes: 1 addition & 1 deletion feedbot.example.ini
Expand Up @@ -13,7 +13,7 @@ channel = #feedbot

; Set to "yes" to use an ipv6 connection, as opposed to an ipv4 connection.
; IPv4 is the default if ipv6_support is not set.
; ipv6_support = no
ipv6 = no

[feeds]
; Pop in the name of the feed as the key, and the URL as the value.
Expand Down
32 changes: 20 additions & 12 deletions feedbot.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""
feedbot: Prints out RSS feeds periodically on IRC.
Copyright 2010 - 2011 Michael Farrell <http://micolous.id.au>
Copyright 2010 - 2012 Michael Farrell <http://micolous.id.au>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
Expand All @@ -19,13 +19,25 @@

import re, asyncore, feedparser
from time import sleep
from ConfigParser import ConfigParser
from configparser_plus import ConfigParserPlus
from sys import argv, exit
from ircasync import *
from subprocess import Popen, PIPE
from thread import start_new_thread

config = ConfigParser()
DEFAULT_CONFIG = {
'feedbot': {
'server': 'localhost',
'port': DEFAULT_PORT,
'ipv6': 'no',
'nick': 'feedbot',
'channel': '#test',
'update_frequency': 300,
'version': 'feedbot; https://github.com/micolous/ircbots/',
}
}

config = ConfigParserPlus(DEFAULT_CONFIG)
try:
config.readfp(open(argv[1]))
except:
Expand All @@ -41,21 +53,17 @@

# read config
SERVER = config.get('feedbot', 'server')
try: PORT = config.getint('feedbot', 'port')
except: PORT = DEFAULT_PORT
try: IPV6 = ( config.getint('feedbot', 'ipv6_support') == "yes" )
except: IPV6 = False
PORT = config.getint('feedbot', 'port')
IPV6 = config.getboolean('feedbot', 'ipv6')
NICK = config.get('feedbot', 'nick')
CHANNEL = config.get('feedbot', 'channel')
VERSION = 'feedbot; https://github.com/micolous/ircbots/; %s'
VERSION = config.get('feedbot', 'version') + '; %s'
try: VERSION = VERSION % Popen(["git","branch","-v","--contains"], stdout=PIPE).communicate()[0].strip()
except: VERSION = VERSION % 'unknown'
del Popen, PIPE

try: NICKSERV_PASS = config.get('feedbot', 'nickserv_pass')
except: NICKSERV_PASS = None
try: UPDATE_FREQUENCY = config.getint('feedbot', 'update_frequency')
except: UPDATE_FREQUENCY = 300
NICKSERV_PASS = config.get('feedbot', 'nickserv_pass')
UPDATE_FREQUENCY = config.getint('feedbot', 'update_frequency')

feed_urls = {}
if config.has_section('feeds'):
Expand Down
6 changes: 3 additions & 3 deletions linkbot.example.ini
@@ -1,7 +1,7 @@
[linkbot]
; You can define another repository for your code and name of the bot.
; The git version string will be appended to this.
;version = regexbot; https://github.com/octocat/ircbots/
;version = linkbot; https://github.com/octocat/ircbots/

[linkbot1]
; The server to connect to.
Expand All @@ -17,8 +17,8 @@ channel = #test1

;; OTHER OPTIONS
; Set to "yes" to use an ipv6 connection, as opposed to an ipv4 connection.
; IPv4 is the default if ipv6_support is not set.
; ipv6_support = no
; IPv4 is the default if not set.
ipv6 = no

; Controls how long to wait after the last message before pulling the next one
; out of the queue. Defaults to 1 second. This is here for flood control.
Expand Down
36 changes: 32 additions & 4 deletions linkbot.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""
linkbot: IRC server linking tool
Copyright 2010 - 2011 Michael Farrell <http://micolous.id.au>
Copyright 2010 - 2012 Michael Farrell <http://micolous.id.au>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
Expand All @@ -20,15 +20,43 @@

import re, asyncore
from datetime import datetime, timedelta
from ConfigParser import ConfigParser
from configparser_plus import ConfigParserPlus
from sys import argv, exit
from ircasync import *
from subprocess import Popen, PIPE
from thread import start_new_thread
from time import sleep
from Queue import Queue, Full

config = ConfigParser()
DEFAULT_CONFIG = {
'linkbot': {
'version': 'linkbot; https://github.com/micolous/ircbots/'
},

'linkbot1': {
'server': 'localhost',
'port': DEFAULT_PORT,
'ipv6': 'no',
'nick': 'linkbot1',
'channel': '#test',
'process_every': 1,
'max_message_length': 512,
'max_messages': 25
},

'linkbot2': {
'server': 'localhost',
'port': DEFAULT_PORT,
'ipv6': 'no',
'nick': 'linkbot2',
'channel': '#test2',
'process_every': 1,
'max_message_length': 512,
'max_messages': 25
},
}

config = ConfigParserPlus(DEFAULT_CONFIG)
try:
config.readfp(open(argv[1]))
except:
Expand Down Expand Up @@ -60,7 +88,7 @@ def __init__(self, config, section):
self.port = DEFAULT_PORT


try: self.ipv6 = ( config.getint('linkbot', 'ipv6_support') == "yes" )
try: self.ipv6 = config.getboolean('linkbot', 'ipv6')
except: self.ipv6 = False

self.nick = config.get(section, 'nick')
Expand Down
4 changes: 2 additions & 2 deletions regexbot.example.ini
Expand Up @@ -15,8 +15,8 @@ channels = #regexbot #regexbot2

;; OTHER OPTIONS
; Set to "yes" to use an ipv6 connection, as opposed to an ipv4 connection.
; IPv4 is the default if ipv6_support is not set.
; ipv6_support = no
; IPv4 is the default if ipv6 is not set.
ipv6 = no

; The bot has an internal "cooldown timer" which controls under what conditions
; it believes it is being flooded. If someone messages a command to regexbot
Expand Down
42 changes: 25 additions & 17 deletions regexbot.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""
regexbot: IRC-based regular expression evaluation tool.
Copyright 2010 - 2011 Michael Farrell <http://micolous.id.au>
Copyright 2010 - 2012 Michael Farrell <http://micolous.id.au>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
Expand All @@ -20,14 +20,29 @@

import regex, asyncore, threading, inspect, ctypes, time
from datetime import datetime, timedelta
from ConfigParser import ConfigParser
from configparser_plus import ConfigParserPlus
from sys import argv, exit
from ircasync import *
from subprocess import Popen, PIPE
from copy import copy
from string import maketrans, translate

config = ConfigParser()
DEFAULT_CONFIG = {
'regexbot': {
'server': 'localhost',
'port': DEFAULT_PORT,
'ipv6': 'no',
'nick': 'regexbot',
'channels': '#test',
'channel_flood_cooldown': 5,
'global_flood_cooldown': 1,
'max_messages': 25,
'max_message_size': 200,
'version': 'regexbot; https://github.com/micolous/ircbots/',
}
}

config = ConfigParserPlus(DEFAULT_CONFIG)
try:
config.readfp(open(argv[1]))
except:
Expand All @@ -43,26 +58,19 @@

# read config
SERVER = config.get('regexbot', 'server')
try: PORT = config.getint('regexbot', 'port')
except: PORT = DEFAULT_PORT
try: IPV6 = ( config.getint('regexbot', 'ipv6_support') == "yes" )
except: IPV6 = False
PORT = config.getint('regexbot', 'port')
IPV6 = config.getboolean('regexbot', 'ipv6')
NICK = config.get('regexbot', 'nick')
CHANNELS = config.get('regexbot', 'channels').split()
try: VERSION = config.get('regexbot', 'version') + '; %s'
except: VERSION = 'regexbot; https://github.com/micolous/ircbots/; %s'
VERSION = config.get('regexbot', 'version') + '; %s'
try: VERSION = VERSION % Popen(["git","branch","-v","--contains"], stdout=PIPE).communicate()[0].strip()
except: VERSION = VERSION % 'unknown'
del Popen, PIPE

try: CHANNEL_FLOOD_COOLDOWN = timedelta(seconds=config.getint('regexbot', 'channel_flood_cooldown'))
except: CHANNEL_FLOOD_COOLDOWN = timedelta(seconds=5)
try: GLOBAL_FLOOD_COOLDOWN = timedelta(seconds=config.getint('regexbot', 'global_flood_cooldown'))
except: GLOBAL_FLOOD_COOLDOWN = timedelta(seconds=1)
try: MAX_MESSAGES = config.getint('regexbot', 'max_messages')
except: MAX_MESSAGES = 25
try: MAX_MESSAGE_SIZE = config.getint('regexbot', 'max_message_size')
except: MAX_MESSAGE_SIZE = 200
CHANNEL_FLOOD_COOLDOWN = timedelta(seconds=config.getint('regexbot', 'channel_flood_cooldown'))
GLOBAL_FLOOD_COOLDOWN = timedelta(seconds=config.getint('regexbot', 'global_flood_cooldown'))
MAX_MESSAGES = config.getint('regexbot', 'max_messages')
MAX_MESSAGE_SIZE = config.getint('regexbot', 'max_message_size')
try: NICKSERV_PASS = config.get('regexbot', 'nickserv_pass')
except: NICKSERV_PASS = None

Expand Down
3 changes: 3 additions & 0 deletions setup.py
Expand Up @@ -9,6 +9,9 @@
author="Michael Farrell",
author_email="micolous@gmail.com",
url="http://github.com/micolous/ircbots",
requires=[
'configparser_plus (>=1.0)',
]

py_modules=['ircasync'],
scripts=['%s.py' % x for x in ['ethicsbot', 'feedbot', 'gamebot', 'ircserver', 'linkbot', 'pagerbot', 'regexbot', 'twitterbot']]
Expand Down
4 changes: 2 additions & 2 deletions twitterbot.example.ini
Expand Up @@ -7,5 +7,5 @@ channel = #main
flood_cooldown = 3

; Set to "yes" to use an ipv6 connection, as opposed to an ipv4 connection.
; IPv4 is the default if ipv6_support is not set.
; ipv6_support = no
; IPv4 is the default if ipv6 is not set.
ipv6 = no
29 changes: 20 additions & 9 deletions twitterbot.py
Expand Up @@ -3,6 +3,7 @@
"""
twitterbot: Shows tweets for Twitter URLs posted on IRC.
Copyright 2011 Rob McFadzean
Copyright 2011 - 2012 Michael Farrell
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
Expand All @@ -19,7 +20,7 @@
"""

import asyncore, random, re, twitter, urllib2, exceptions
from ConfigParser import ConfigParser
from configparser_plus import ConfigParserPlus
from datetime import datetime, timedelta
from sys import argv, exit
from ircasync import *
Expand All @@ -31,7 +32,20 @@
print "geopy isn't installed, geocoder support disabled."
geocoder = None

config = ConfigParser()

DEFAULT_CONFIG = {
'twitterbot': {
'server': 'localhost',
'port': DEFAULT_PORT,
'ipv6': 'no',
'nick': 'twitterbot',
'channel': '#test',
'flood_cooldown': 5,
'version': 'twitterbot; https://github.com/micolous/ircbots/',
}
}

config = ConfigParser(DEFAULT_CONFIG)
try:
config.readfp(open(argv[1]))
except:
Expand All @@ -46,19 +60,16 @@
exit(1)

SERVER = config.get('twitterbot', 'server')
try: PORT = config.getint('twitterbot', 'port')
except: PORT = DEFAULT_PORT
try: IPV6 = ( config.getint('twitterbot', 'ipv6_support') == "yes" )
except: IPV6 = False
PORT = config.getint('twitterbot', 'port')
IPV6 = config.getboolean('twitterbot', 'ipv6')
NICK = config.get('twitterbot', 'nick')
CHANNEL = config.get('twitterbot', 'channel')
VERSION = 'twitterbot; https://github.com/micolous/ircbots/; %s'
VERSION = config.get('regexbot', 'version') + '; %s'
try: VERSION = VERSION % Popen(["git","branch","-v","--contains"], stdout=PIPE).communicate()[0].strip()
except: VERSION = VERSION % 'unknown'
del Popen, PIPE

try: FLOOD_COOLDOWN = timedelta(seconds=config.getint('twitterbot', 'flood_cooldown'))
except: FLOOD_COOLDOWN = timedelta(seconds=5)
FLOOD_COOLDOWN = timedelta(seconds=config.getint('twitterbot', 'flood_cooldown'))
try: NICKSERV_PASS = config.get('twitterbot', 'nickserv_pass')
except: NICKSERV_PASS = None

Expand Down

0 comments on commit 294c0e0

Please sign in to comment.