logo

scripts

A bunch of scripts, some to be moved to their own repository
commit: 08cbd0e0d39acf46a497cc8ed3648960ee2cc9e5
parent: fae99eee60b827bfc48ad54c85448ee0851c00a6
Author: lanodan <lanodan.delta@free.fr>
Date:   Fri, 11 Apr 2014 21:54:10 +0200

Improve link finder

Diffstat:

MIRCBot/IRCBot.py25++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/IRCBot/IRCBot.py b/IRCBot/IRCBot.py @@ -3,14 +3,7 @@ #Author: Haelwenn Monnier (lanodan) <haelwenn.monnier@gmail.com> #License: CC-BY-SA -import socket -import sys -import re -import time -import urllib -import subprocess -import ConfigParser -import os +import socket, sys, re, time, urllib, subprocess, ConfigParser, os def get_element(textInput, elem): idx1=textInput.find('<'+elem+'>') @@ -28,6 +21,8 @@ def log(line): log.write(line+'\n') log.close() +httpRegex = re.compile('https?://+') + config = ConfigParser.ConfigParser() if (config.read('config.ini')): botnick = config.get('Config', 'nick') @@ -68,7 +63,7 @@ while 1: #puts it in a loop t = text.split(':!action') #you can change t and to :) out = t[1].strip() #this code is for getting the first word after !hi printIrc('\x01ACTION '+out+'\x01') - if text.find('http') != -1: + if httpRegex.search(text) is not None: parse = re.findall('https?://[^\"\'\(\)\[\]\{\}\<\>\ ]+', text) try: url = str(parse[0]).rstrip() #took the first link and remove newline and whitespaces @@ -100,9 +95,13 @@ while 1: #puts it in a loop printIrc(source) #if text.find(':!'+nick+' help') != -1: # asker = - if text.find(' JOIN ') != -1: - + #if text.find(' JOIN ') != -1: + if text.find('KICK '+channel) != -1: + time.sleep(1) + irc.send('JOIN '+ channel +'\n') #join the chan if text.find(':!stop in the name of sey') != -1: irc.send('QUIT : '+quitMsg+'\n') - time.sleep(1) - sys.exit(0) + irc.close() + break + +sys.exit()