Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #25 from indivisible-irl/master

Added nick logon ability
  • Loading branch information...
commit 17deed8e126cd6dc3ba62557aa9d0ad110b49768 2 parents 3bddf30 + 0948fba
@Qasaur Qasaur authored
Showing with 21 additions and 17 deletions.
  1. +1 −1  commands/irc.py
  2. +16 −9 core.py
  3. +4 −1 settings.py
  4. +0 −6 settings.txt
View
2  commands/irc.py
@@ -7,6 +7,6 @@ def __init__(self):
self.channel = ircHelpers.getChannel()
def onRun(self, arguments, messageInfo):
- command = 'PRIVMSG %s :%s\r\n' % (self.channel, "server: irc.freenode.net, channel: #progether")
+ command = 'PRIVMSG %s :%s\r\n' % (self.channel, "server: irc.freenode.net, channel: #reddit-progether")
ircHelpers.send(command)
View
25 core.py
@@ -12,6 +12,7 @@ def __init__(self, tempCacheSize=4096):
self.port = int(conf['port'])
self.channel = conf['channel']
self.nickname = conf['nick']
+ self.password = conf['password']
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.tempCacheSize = tempCacheSize
@@ -20,7 +21,7 @@ def __init__(self, tempCacheSize=4096):
self.commandModule = CommandModule()
self.regexIsCommand = re.compile(r"(?P<command>!!..+)")
- self.regexIsChat = re.compile(r":(?P<user>\w+)!~(?P<isp>.+)\sPRIVMSG\s(?P<channel>[\w#]+)\s:(?P<message>.+)")
+ self.regexIsChat = re.compile(r":(?P<user>\w+)!~(?P<isp>.+)\sPRIVMSG\s(?P<channel>[#\w-]+)\s:(?P<message>.+)")
def run(self):
self.socket.connect((self.network, self.port))
@@ -28,15 +29,18 @@ def run(self):
self.socket.send('NICK %s \r\n' % self.nickname)
self.socket.send('USER %s some stuff :Python IRC\r\n' % self.nickname)#change this
self.socket.send('JOIN %s \r\n' % self.channel)
+
+ # need to register bot nick bofre you can use this. If you'd rather skip register comment out next lines.
+ self.socket.send('PRIVMSG NickServ :IDENTIFY %s %s\r\n' % (self.nickname, self.password))
+
self.mainLoop()
def mainLoop(self):
while True:
- recievedData = self.socket.recv(self.tempCacheSize)
- self.log(recievedData)
-
+ receivedData = self.socket.recv(self.tempCacheSize)
+ #self.log(recievedData)
messageInfo = dict()
- isChat = self.regexIsChat.match(recievedData)
+ isChat = self.regexIsChat.match(receivedData)
if isChat:
messageInfo['user'] = isChat.group('user')
messageInfo['isp'] = isChat.group('isp')
@@ -47,17 +51,20 @@ def mainLoop(self):
if isCommand:
self.commandModule.runCommand(isCommand.group('command'), messageInfo)
- self.behaviourModule.performBehaviours(recievedData)
+ self.behaviourModule.performBehaviours(receivedData)
#temporary quit method, should be changed so only admins can use
- if recievedData.find('!!quit') != -1:
+ if receivedData.find('!!quit') != -1:
self.log("Quitting")
self.socket.send('QUIT\r\n')
break
#make sure we don't time out of server
- if recievedData.find('PING') != -1:
- self.socket.send('PONG %s \r\n' % recievedData.split()[1])
+ if receivedData.find('PING') != -1:
+ self.socket.send('PONG %s \r\n' % receivedData.split()[1])
+ else:
+ # moved log here to filter out ping/pong chatter
+ self.log(receivedData)
def log(self, stringToLog):
#change eventually to log in a file but for now print is fine
View
5 settings.py
@@ -7,7 +7,8 @@ def create_config():
nick = tmpircbotname
port = 6667
network = irc.freenode.net
- channel = #progether
+ channel = ##reddit-progether
+ password = 1234test
"""
file_content = file_content.splitlines()
for line in file_content:
@@ -22,6 +23,7 @@ def read_config():
config['network'] = config_file.get('settings', 'network')
config['port'] = config_file.get('settings', 'port')
config['channel'] = config_file.get('settings', 'channel')
+ config['password'] = config_file.get('settings', 'password')
return config
@@ -33,3 +35,4 @@ def read_config():
print conf['network']
print conf['port']
print conf['channel']
+ print conf['password']
View
6 settings.txt
@@ -1,6 +0,0 @@
-[settings]
-nick = TestyTest
-network = irc.freenode.net
-port = 6667
-channel = #progether
-
Please sign in to comment.
Something went wrong with that request. Please try again.