forked from micolous/ircbots
-
Notifications
You must be signed in to change notification settings - Fork 1
/
riebot.py
84 lines (72 loc) · 2.52 KB
/
riebot.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import re, asyncore
from datetime import datetime, timedelta
from ConfigParser import ConfigParser
from sys import argv, exit
from ircasync import *
from subprocess import Popen, PIPE
config = ConfigParser()
try:
config.readfp(open(argv[1]))
except:
try:
config.readfp(open('riebot.ini'))
except:
print "Syntax:"
print " %s [config]" % argv[0]
print ""
print "If no configuration file is specified or there was an error, it will default to `regexbot.ini'."
print "If there was a failure reading the configuration, it will display this message."
exit(1)
# read config
SERVER = config.get('riebot', 'server')
try: PORT = config.getint('riebot', 'port')
except: PORT = DEFAULT_PORT
NICK = config.get('riebot', 'nick')
CHANNEL = config.get('riebot', 'channel')
except: VERSION = 'riebot; https://github.com/peerau/ircbots/; %s'
try: VERSION = VERSION % Popen(["git","branch","-v","--contains"], stdout=PIPE).communicate()[0].strip()
except: VERSION = VERSION % 'unknown'
try: TEXT_TIME = timedelta(minutes=config.getint('riebot', 'text_timeout'))
except: TEXT_TIME = timedelta(minutes=60)
try: FROM_HOST = config.getint('riebot', 'from_host')
except: FROM_HOST = '@defocus/regular/crazycatlady'
try: NICKSERV_PASS = config.get('riebot', 'nickserv_pass')
except: NICKSERV_PASS = None
try: BAN_HOST = config.get('riebot', 'ban_host')
except: BAN_HOST = '*!*@unaffiliated/sabian'
message_buffer = []
last_message = datetime.now()
flooders = []
BAN_ACTIVE = False
# main code
def handle_msg(event, match):
global last_message, flooders, CHANNEL, TEXT_TIME, FROM_HOST, BAN_HOST, BAN_ACTIVE
msg = event.text
if event.channel.lower() == CHANNEL.lower():
if FROM_HOST in event.origin:
delta = event.when - last_message
if delta < TEXT_TIME:
last_message = event.when
print "RESET COUNTER"
return
if BAN_ACTIVE:
print "BAN OFF"
event.connection.todo(['MODE', CHANNEL, '-j', BAN_HOST])
BAN_ACTIVE = False
else:
if (delta > TEXT_TIME) and not BAN_ACTIVE:
print "BAN ON"
BAN_ACTIVE = True
event.connection.todo(['MODE', CHANNEL, '+j', BAN_HOST])
def handle_welcome(event, match):
global NICKSERV_PASS
# Compliance with most network's rules to set this mode on connect.
event.connection.usermode("+B")
if NICKSERV_PASS != None:
event.connection.todo(['NickServ', 'identify', NICKSERV_PASS])
irc = IRC(nick=NICK, start_channels=[CHANNEL], version=VERSION)
irc.bind(handle_msg, PRIVMSG)
irc.bind(handle_welcome, RPL_WELCOME)
irc.bind(handle_ctcp, CTCP_REQUEST)
irc.make_conn(SERVER, PORT)
asyncore.loop()