added autorejoin, fixed bug
This commit is contained in:
parent
af97d71f33
commit
e6acc60343
2 changed files with 21 additions and 31 deletions
|
@ -20,6 +20,7 @@ if not os.path.exists('config'):
|
||||||
"realname": "CloudBot - http://git.io/cloudbot",
|
"realname": "CloudBot - http://git.io/cloudbot",
|
||||||
"nickserv_password": "",
|
"nickserv_password": "",
|
||||||
"channels": ["#channel"],
|
"channels": ["#channel"],
|
||||||
|
"autorejoin": "False",
|
||||||
"command_prefix": ".",
|
"command_prefix": ".",
|
||||||
"stayalive": "",
|
"stayalive": "",
|
||||||
"stayalive_delay": "20"
|
"stayalive_delay": "20"
|
||||||
|
|
|
@ -5,26 +5,22 @@ import time
|
||||||
|
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
|
|
||||||
socket.setdefaulttimeout(10) # global setting
|
socket.setdefaulttimeout(10)
|
||||||
|
|
||||||
|
@hook.event('KICK')
|
||||||
|
def rejoin(paraml, conn=None):
|
||||||
|
autorejoin = conn.conf.get('autorejoin', False)
|
||||||
|
if autorejoin:
|
||||||
|
conn.join(paraml[0])
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
#autorejoin channels
|
|
||||||
#@hook.event('KICK')
|
|
||||||
#def rejoin(paraml, conn=None):
|
|
||||||
# if paraml[1] == conn.nick:
|
|
||||||
# if paraml[0].lower() in conn.channels:
|
|
||||||
# conn.join(paraml[0])
|
|
||||||
|
|
||||||
|
|
||||||
#join channels when invited
|
|
||||||
@hook.event('INVITE')
|
@hook.event('INVITE')
|
||||||
def invite(paraml, conn=None):
|
def invite(paraml, conn=None):
|
||||||
conn.join(paraml[-1])
|
conn.join(paraml[-1])
|
||||||
|
|
||||||
|
|
||||||
@hook.event('004')
|
@hook.event('004')
|
||||||
def onjoin(paraml, conn=None, bot=None):
|
def onjoin(paraml, conn=None, bot=None):
|
||||||
# identify to services
|
|
||||||
nickserv_password = conn.conf.get('nickserv_password', '')
|
nickserv_password = conn.conf.get('nickserv_password', '')
|
||||||
nickserv_name = conn.conf.get('nickserv_name', 'nickserv')
|
nickserv_name = conn.conf.get('nickserv_name', 'nickserv')
|
||||||
nickserv_command = conn.conf.get('nickserv_command', 'IDENTIFY %s')
|
nickserv_command = conn.conf.get('nickserv_command', 'IDENTIFY %s')
|
||||||
|
@ -34,43 +30,36 @@ def onjoin(paraml, conn=None, bot=None):
|
||||||
conn.msg(nickserv_name, nickserv_command % nickserv_password)
|
conn.msg(nickserv_name, nickserv_command % nickserv_password)
|
||||||
bot.config['censored_strings'].append(nickserv_password)
|
bot.config['censored_strings'].append(nickserv_password)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# set mode on self
|
|
||||||
mode = conn.conf.get('mode')
|
mode = conn.conf.get('mode')
|
||||||
|
|
||||||
if mode:
|
if mode:
|
||||||
conn.cmd('MODE', [conn.nick, mode])
|
conn.cmd('MODE', [conn.nick, mode])
|
||||||
|
|
||||||
# join channels
|
|
||||||
for channel in conn.channels:
|
for channel in conn.channels:
|
||||||
conn.join(channel)
|
conn.join(channel)
|
||||||
time.sleep(1) # don't flood JOINs
|
time.sleep(1)
|
||||||
|
|
||||||
# set user-agent
|
|
||||||
|
|
||||||
http.ua_skybot = 'CloudBot - http://git.io/cloudbot'
|
http.ua_skybot = 'CloudBot - http://git.io/cloudbot'
|
||||||
|
|
||||||
# stayalive code
|
|
||||||
|
|
||||||
stayalive = conn.conf.get('stayalive')
|
stayalive = conn.conf.get('stayalive')
|
||||||
if stayalive:
|
if stayalive:
|
||||||
while True:
|
while True:
|
||||||
time.sleep(conn.conf.get('stayalive_delay', 20))
|
time.sleep(conn.conf.get('stayalive_delay', 20))
|
||||||
conn.cmd('PING', [conn.nick])
|
conn.cmd('PING', [conn.nick])
|
||||||
|
|
||||||
# CTCPs
|
|
||||||
@hook.regex(r'^\x01VERSION\x01$')
|
@hook.regex(r'^\x01VERSION\x01$')
|
||||||
def version(inp, notice=None):
|
def ctcpversion(inp, notice=None):
|
||||||
notice('\x01VERSION: CloudBot - http://git.io/cloudbot')
|
notice('\x01VERSION: CloudBot - http://git.io/cloudbot')
|
||||||
|
|
||||||
@hook.regex(r'^\x01PING\x01$')
|
@hook.regex(r'^\x01PING\x01$')
|
||||||
def ping(inp, notice=None):
|
def ctcpping(inp, notice=None):
|
||||||
notice('\x01PING: PONG')
|
notice('\x01PING: PONG')
|
||||||
@hook.regex(r'^\x01FINGER\x01$')
|
|
||||||
def finger(inp, notice=None):
|
|
||||||
notice('\x01FINGER: WHERE ARE YOU PUTTING THAT')
|
|
||||||
@hook.regex(r'^\x01TIME\x01$')
|
@hook.regex(r'^\x01TIME\x01$')
|
||||||
def time(inp, notice=None):
|
def ctcptime(inp, notice=None):
|
||||||
notice('\x01TIME: GET A WATCH')
|
notice('\x01TIME: GET A WATCH')
|
||||||
@hook.regex(r'^\x01DIE\x01$')
|
|
||||||
def die(inp, notice=None):
|
@hook.regex(r'^\x01FINGER\x01$')
|
||||||
notice('\x01DIE: IN A FIRE')
|
def ctcpfinger(inp, notice=None):
|
||||||
@hook.regex(r'^\x01VIRGIN\x01$')
|
notice('\x01FINGER: WHERE ARE YOU PUTTING THAT')
|
||||||
|
|
||||||
|
|
Reference in a new issue