This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/core_misc.py

78 lines
2.2 KiB
Python
Raw Normal View History

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
from util import hook
2011-11-20 10:23:31 +01:00
2014-02-14 04:36:57 +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):
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')
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:
if nickserv_password in bot.config['censored_strings']:
2012-02-29 09:29:53 +01:00
bot.config['censored_strings'].remove(nickserv_password)
if nickserv_account_name:
2013-09-05 07:51:24 +02:00
conn.msg(nickserv_name, "{} {} {}".format(nickserv_command, nickserv_account_name, nickserv_password))
else:
2013-09-05 07:51:24 +02:00
conn.msg(nickserv_name, "{} {}".format(nickserv_command, nickserv_password))
2011-11-20 10:23:31 +01:00
bot.config['censored_strings'].append(nickserv_password)
time.sleep(1)
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
print "Bot ready."
@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-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
@hook.event('004')
def keep_alive(paraml, conn=None):
keepalive = conn.conf.get('keep_alive', False)
if keepalive:
while True:
conn.cmd('PING', [conn.nick])
2012-04-25 09:59:11 +02:00
time.sleep(60)