2011-11-20 10:23:31 +01:00
|
|
|
import socket
|
2012-04-25 09:59:11 +02:00
|
|
|
import time
|
2012-10-12 10:56:09 +02:00
|
|
|
import re
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-04-04 00:28:59 +02:00
|
|
|
from util import hook
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-29 00:02:44 +01:00
|
|
|
socket.setdefaulttimeout(10)
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-10-12 10:56:09 +02:00
|
|
|
nick_re = re.compile(":(.+?)!")
|
|
|
|
|
2012-02-29 09:29:53 +01:00
|
|
|
|
2012-03-01 09:57:38 +01:00
|
|
|
# Auto-join on Invite (Configurable, defaults to True)
|
2012-02-29 00:11:30 +01:00
|
|
|
@hook.event('INVITE')
|
|
|
|
def invite(paraml, conn=None):
|
2012-04-27 07:47:18 +02:00
|
|
|
invite_join = conn.conf.get('invite_join', True)
|
|
|
|
if invite_join:
|
2012-02-29 00:11:30 +01:00
|
|
|
conn.join(paraml[-1])
|
|
|
|
|
2012-02-29 09:29:53 +01:00
|
|
|
|
2012-03-01 09:57:38 +01:00
|
|
|
# Identify to NickServ (or other service)
|
2011-11-20 10:23:31 +01:00
|
|
|
@hook.event('004')
|
2013-09-04 12:59:58 +02:00
|
|
|
def onjoin(paraml, conn=None, bot=None):
|
2011-11-20 10:23:31 +01:00
|
|
|
nickserv_password = conn.conf.get('nickserv_password', '')
|
|
|
|
nickserv_name = conn.conf.get('nickserv_name', 'nickserv')
|
2013-09-05 01:28:47 +02:00
|
|
|
nickserv_account_name = conn.conf.get('nickserv_user', '')
|
|
|
|
nickserv_command = conn.conf.get('nickserv_command', 'IDENTIFY')
|
2011-11-20 10:23:31 +01:00
|
|
|
if nickserv_password:
|
2013-09-05 01:28:47 +02:00
|
|
|
print "Found a password..."
|
2011-11-20 10:23:31 +01:00
|
|
|
if nickserv_password in bot.config['censored_strings']:
|
2012-02-29 09:29:53 +01:00
|
|
|
bot.config['censored_strings'].remove(nickserv_password)
|
2013-09-05 01:28:47 +02:00
|
|
|
if nickserv_account_name:
|
|
|
|
print "Found an account name..."
|
|
|
|
print "Sending"," ".join([nickserv_command, nickserv_account_name, nickserv_password]),"to",nickserv_name
|
|
|
|
conn.msg(nickserv_name, " ".join([nickserv_command, nickserv_account_name, nickserv_password]))
|
|
|
|
else:
|
|
|
|
print "Sending"," ".join([nickserv_command, nickserv_password]),"to",nickserv_name
|
|
|
|
conn.msg(nickserv_name, " ".join([nickserv_command, nickserv_password]))
|
2011-11-20 10:23:31 +01:00
|
|
|
bot.config['censored_strings'].append(nickserv_password)
|
|
|
|
time.sleep(1)
|
2012-04-25 09:48:14 +02:00
|
|
|
|
2012-02-29 00:11:30 +01:00
|
|
|
# Set bot modes
|
2012-02-29 09:29:53 +01:00
|
|
|
mode = conn.conf.get('mode')
|
2011-11-20 10:23:31 +01:00
|
|
|
if mode:
|
|
|
|
conn.cmd('MODE', [conn.nick, mode])
|
|
|
|
|
2012-02-29 00:11:30 +01:00
|
|
|
# Join config-defined channels
|
2011-11-20 10:23:31 +01:00
|
|
|
for channel in conn.channels:
|
|
|
|
conn.join(channel)
|
2012-02-29 09:29:53 +01:00
|
|
|
time.sleep(1)
|
2012-02-02 14:05:11 +01:00
|
|
|
|
2012-09-11 14:16:06 +02:00
|
|
|
print "Bot ready."
|
2012-04-25 09:48:14 +02:00
|
|
|
|
|
|
|
|
2012-04-27 07:47:18 +02:00
|
|
|
@hook.event("KICK")
|
|
|
|
def onkick(paraml, conn=None, chan=None):
|
|
|
|
# if the bot has been kicked, remove from the channel list
|
|
|
|
if paraml[1] == conn.nick:
|
|
|
|
conn.channels.remove(chan)
|
2012-04-27 17:12:00 +02:00
|
|
|
auto_rejoin = conn.conf.get('auto_rejoin', False)
|
|
|
|
if auto_rejoin:
|
|
|
|
conn.join(paraml[0])
|
2012-09-11 14:16:06 +02:00
|
|
|
|
2012-04-27 07:47:18 +02:00
|
|
|
|
2012-10-12 10:56:09 +02:00
|
|
|
@hook.event("NICK")
|
|
|
|
def onnick(paraml, conn=None, raw=None):
|
|
|
|
old_nick = nick_re.search(raw).group(1)
|
|
|
|
new_nick = str(paraml[0])
|
|
|
|
if old_nick == conn.nick:
|
|
|
|
conn.nick = new_nick
|
|
|
|
print "Bot nick changed from '{}' to '{}'.".format(old_nick, new_nick)
|
|
|
|
|
|
|
|
|
2012-04-25 09:59:11 +02:00
|
|
|
@hook.singlethread
|
2012-04-25 09:48:14 +02:00
|
|
|
@hook.event('004')
|
|
|
|
def keep_alive(paraml, conn=None):
|
|
|
|
keepalive = conn.conf.get('keep_alive', False)
|
|
|
|
if keepalive:
|
2012-02-17 01:32:27 +01:00
|
|
|
while True:
|
|
|
|
conn.cmd('PING', [conn.nick])
|
2012-04-25 09:59:11 +02:00
|
|
|
time.sleep(60)
|