IRC errors and shenanigans
jumped into the deep end again
edit- new code :3
Spoiler
import socket
import datetime
import ConfigParser
import re
import os
os.system('cls')
privlege_lock = False
privlege_mode = 'DISABLED'
relay_chat = False
relay_chat_mode = 'OFF'
class UnknownValue(Exception): pass
#-------------------------------------------------------------------#
#Replaces a line in setup.ini
def replace_line(old_line, new_line):
f = open("setup.ini")
for line in f:
line = os.linesep.join([s for s in line.splitlines() if s]) #Gets rid of extra, blank lines
if line == old_line:
f1 = open("setup.ini",'r')
stuff = f1.read()
f1.close()
new_stuff = re.sub(old_line,new_line,stuff)
f = open("setup.ini",'w')
f.write(new_stuff)
f.close()
#Config parser:
def get_options(filename):
"""
Gets the options from a config file.
Returns a dictionary in a dictionary.
"""
config = ConfigParser.ConfigParser()
try:
config.read(filename)
except ConfigParser.ParsingError, e:
pass
sections = config.sections()
output = {}
for section in sections:
output[section] = {}
for opt in config.options(section):
value = config.get(section, opt)
output[section][opt] = value
return output
o = get_options("setup.ini")
irc_network = o['server']['network'] #irc server adress
irc_port = o['server']['port'] #connection port
if irc_port == '5555':
irc_port = 5555
irc_nick = o['user']['nickname'] #bot nickname
irc_indent = o['user']['indent'] #bot indent
irc_password = o['password']['nickservpass'] #bot's nickserv password
irc_real_name = o['user']['real_name'] #real name
log = o['logging']['log'] #if the program will log or not
log_path = o['logpath']['path'] #path for log files
log = log.lower()
if log == 'true':
log = True
elif log == 'false':
log = False
else:
log = True
irc_ping = o['ping_setup']['ping']# if ping is on
irc_ping_colour = o['ping_setup']['ping_colour'] # the ping colour
irc_chan1 = o['channels']['c1'] #1st channel
irc_chan2 = o['channels']['c2'] #second channel
irc_chan3 = o['channels']['c3'] #third channel
relay_from = o['channels']['relay_from'] #channel for bot to relay from
relay_to = o['channels']['relay'] #channel the bot relays to
irc_theme = o['theme']['theme_use'] #if use colour themes
irc_theme_back = o['theme']['background'] #background colour
irc_theme_text = o['theme']['text'] #text colour
privlege = o['privlege']['privleges'] #if command lock is on
op1 = o['privlege_ip']['owner'] #owner 1
op2 = o['privlege_ip']['co_owner'] #owner 2
op1 = op1.lower()
op2 = op2.lower()
privlege = privlege.lower()
if privlege == 'true':
privlege = True
privlege_mode = 'OFF'
else:
privlege = False
irc_theme = irc_theme.lower()
if irc_theme == 'true':
irc_theme = True
else:
irc_theme = False
if log == True:
now = datetime.datetime.now()
t = open(log_path + 'log.txt', 'a')
t.write("\n\n\n")
t.write("****************************************************\n")
t.write('***logging started at :')
t.write(str(now))
t.write("***\n")
t.write("****************************************************\n\n\n\n")
t.close()
print "logging started on: ",
print (str(now))
def register():
irc.send('PRIVMSG NICKSERV :IDENTIFY ' + irc_password + '\r\n')
def join_channels():
irc.send ( 'JOIN ' + irc_chan1 + '\r\n' )
irc.send ( 'JOIN ' + irc_chan2 + '\r\n' )
irc.send ( 'JOIN ' + irc_chan3 + '\r\n' )
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( irc_network, irc_port ) )
print irc.recv ( 4096 )
irc.send ( 'NICK ' + irc_nick + ' \r\n' )
irc.send ( 'USER '+ irc_indent + ' ' + irc_indent + ' ' + irc_indent + ' :'+ irc_real_name +'\r\n' )
while True:
data = irc.recv ( 4096 )
if log == True:
f = open(log_path + 'log.txt', 'a')
f.write(data)
f.close()
if data.find ( 'PING' ) != -1:
irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
data = ''
print_data = data
data = data.lower()
if data.find ('nickserv!nickserv@services.esper.net' and 'this nickname is registered') != -1:
register()
join_channels()
if data.find ('*quit') != -1:
if data.find ('op1') != -1:
irc.send('QUIT\r\n')
irc.close
break
if data.find ('*quit') != -1:
if data.find('op2') != -1:
irc.send('QUIT\r\n')
break
if data.find(irc_nick) != -1:
if ping == True:
new_data = print_data
data = ''
os.system('color' + irc_theme_back + irc_ping_colour)
print (new_data)
os.system('color ' + irc_theme_back + irc_theme_text)
if data.find ('*satus') != -1:
irc.send('PRIVMSG ' + relay_to + ' :Lock mode is ' + privlege_mode + '\r\n')
if privlege_lock == False:
irc.send('PRIVMSG ' + relay_to + ' :Relay is ' + relay_chat_mode + '\r\n')
irc.send('PRIVMSG ' + relay_to + ' :Relaying from: ' + relay_from + '\r\n')
irc.send('PRIVMSG ' + relay_to + ' :Relaying to: ' + relay_to + '\r\n')
if data.find ('*relay off') != -1:
if privlege_lock == False:
relay_chat = False
relay_chat_mode = 'OFF'
irc.send('PRIVMSG ' + relay_to + ' :Relay OFF\r\n')
elif data.find(op1 or op2) != -1:
relay_chat = False
relay_chat_mode = 'OFF'
irc.send('PRIVMSG ' + relay_to + ' :Relay OFF\r\n')
else:
irc.send('PRIVMSG ' + relay_to + ' :You do not have the premmesion to use that command!\r\n')
if data.find ('*relay on') != -1:
if privlege_lock == False:
relay_chat = True
relay_chat_mode = 'ON'
irc.send('PRIVMSG ' + relay_to + ' :Relay ON\r\n')
elif data.find (op1 or op2) != -1:
relay_chat = True
relay_chat_mode = 'ON'
irc.send('PRIVMSG ' + relay_to + ' :Relay ON\r\n')
else:
irc.send('PRIVMSG ' + relay_to + ' :You do not have the premmesion to use that command!\r\n')
if relay_chat == True:
if data.find (relay_from) != -1:
irc.send('PRIVMSG ' + relay_to + ' :' + print_data + '\r\n')
if privlege == True:
if data.find('*lock') != -1:
if privlege_lock == True:
irc.send('PRIVMSG ' + relay_to + ' :Allready in locked mode!\r\n')
else:
privlege_mode = 'ON'
privlege_lock = True
irc.send('PRIVMSG ' + relay_to + ' :Locked mode is now ON, only owners may unlock|acess now.\r\n')
if privlege == True:
if data.find('*unlock') != -1:
if privlege_lock == True:
if data.find(op1 or op2) != -1:
privlege_lock = False
privlege_mode = 'OFF'
irc.send('PRIVMSG ' +relay_to + ' :Locked mode is now OFF\r\n')
else:
irc.send('PRIVMSG ' + relay_to + ' :You do not have the premmesion to use that command!\r\n')
else:
irc.send ('PRIVMSG ' + relay_to + ' :Not in locked mode!\r\n')
print print_data
irc.close()
setup.ini
Spoiler
[server] network = irc.esper.net port = 5555 [nickserv] use = True [user] nickname = Fish indent = fishy real_name = Python IRC [ping_setup] ping = False ping_colour = c [logging] log = True [password] nickservpass = -snip- [channels] c1 = #fish c2 = #fish|help c3 = # relay_from = # relay = # [theme] theme_use = True background = 0 text = 7 [privlege] privleges = True [privlege_ip] owner = -snip- co_owner = -sip- [logpath] path = I:/irc/1/logs/
current problems as stated in last post:
Quote
what i really need to do is split the variable "data" into a few strings.
returns
what i'm trrying to do is make 6 new variables from "data".
the users nickname "Midareru", their indent "androirc", ip, "@119.224.2.55", message type "PRIVMSG", channel #OT, and finally the message "Hello World".
i have been sugested to use regular expressions to extract the data types, but i don't quite get it, and as i said before, i don't have the time at the moment...
once i get that sortet, i can get this hunk of code sorted out nicely.
print (data)
returns
:Midareru!~androirc@119.224.2.55 PRIVMSG #OT :Hello World
what i'm trrying to do is make 6 new variables from "data".
the users nickname "Midareru", their indent "androirc", ip, "@119.224.2.55", message type "PRIVMSG", channel #OT, and finally the message "Hello World".
i have been sugested to use regular expressions to extract the data types, but i don't quite get it, and as i said before, i don't have the time at the moment...
once i get that sortet, i can get this hunk of code sorted out nicely.






Cartoon Clouds
Mountains
Sunrise
Clouds
Green Clouds
None


















Help