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/misc.py

64 lines
1.7 KiB
Python
Raw Normal View History

2011-11-20 10:23:31 +01:00
import re
import socket
import subprocess
import platform
2011-11-20 10:23:31 +01:00
import time
2012-02-02 14:05:11 +01:00
from util import hook, http
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-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):
invitejoin = conn.conf.get('invitejoin', True)
if invitejoin:
conn.join(paraml[-1])
else:
return None
2012-02-29 09:29:53 +01:00
2012-03-01 10:24:15 +01:00
# Rejoin on kick (Configurable, defaults to False)
2012-02-29 00:02:44 +01:00
@hook.event('KICK')
def rejoin(paraml, conn=None):
autorejoin = conn.conf.get('autorejoin', False)
if autorejoin:
conn.join(paraml[0])
else:
return None
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')
def onjoin(paraml, conn=None, bot=None):
nickserv_password = conn.conf.get('nickserv_password', '')
nickserv_name = conn.conf.get('nickserv_name', 'nickserv')
nickserv_command = conn.conf.get('nickserv_command', 'IDENTIFY %s')
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)
2011-11-20 10:23:31 +01:00
conn.msg(nickserv_name, nickserv_command % nickserv_password)
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
2012-02-29 00:11:30 +01:00
# HTTP Useragent
2012-03-20 07:58:04 +01:00
http.ua_cloudbot = 'CloudBot - http://git.io/cloudbotirc'
2012-02-02 14:05:11 +01:00
2012-02-29 00:11:30 +01:00
# Stay-alive code
stayalive = conn.conf.get('stayalive')
if stayalive:
2012-03-01 10:24:15 +01:00
delay = conn.conf.get('stayalive_delay', 20)
while True:
2012-03-01 10:24:15 +01:00
time.sleep(delay)
conn.cmd('PING', [conn.nick])