Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #27 from joshgit/master

adding join command for multiple channels
  • Loading branch information...
commit f2348ce19536d7c55eaca63531625ce6ef07a856 2 parents acca211 + 71595fa
@LiquidHelium LiquidHelium authored
View
2  commands/cmds.py
@@ -7,5 +7,5 @@ def __init__(self):
self.channel = ircHelpers.getChannel()
def onRun(self, arguments, messageInfo):
- command = 'PRIVMSG %s :%s\r\n' % (self.channel, "http://en.wikipedia.org/wiki/List_of_Internet_Relay_Chat_commands")
+ command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "http://en.wikipedia.org/wiki/List_of_Internet_Relay_Chat_commands")
ircHelpers.send(command)
View
24 commands/faq.py
@@ -1,12 +1,12 @@
-from core import ircBot
-import ircHelpers
-
-@ircBot.registerCommand('faq')
-class Faq:
- def __init__(self):
- self.channel = ircHelpers.getChannel()
-
- def onRun(self, arguments, messageInfo):
- command = 'PRIVMSG %s :%s\r\n' % (self.channel, "http://code.reddit.com/wiki/help/faqs/progether")
- ircHelpers.send(command)
-
+from core import ircBot
+import ircHelpers
+
+@ircBot.registerCommand('faq')
+class Faq:
+ def __init__(self):
+ self.channel = ircHelpers.getChannel()
+
+ def onRun(self, arguments, messageInfo):
+ command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "http://code.reddit.com/wiki/help/faqs/progether")
+ ircHelpers.send(command)
+
View
24 commands/git.py
@@ -1,12 +1,12 @@
-from core import ircBot
-import ircHelpers
-
-@ircBot.registerCommand('git')
-class Git:
- def __init__(self):
- self.channel = ircHelpers.getChannel()
-
- def onRun(self, arguments, messageInfo):
- command = 'PRIVMSG %s :%s\r\n' % (self.channel, "https://github.com/Progether")
- ircHelpers.send(command)
-
+from core import ircBot
+import ircHelpers
+
+@ircBot.registerCommand('git')
+class Git:
+ def __init__(self):
+ self.channel = ircHelpers.getChannel()
+
+ def onRun(self, arguments, messageInfo):
+ command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "https://github.com/Progether")
+ ircHelpers.send(command)
+
View
24 commands/irc.py
@@ -1,12 +1,12 @@
-from core import ircBot
-import ircHelpers
-
-@ircBot.registerCommand('irc')
-class IRC:
- 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: #reddit-progether")
- ircHelpers.send(command)
-
+from core import ircBot
+import ircHelpers
+
+@ircBot.registerCommand('irc')
+class IRC:
+ def __init__(self):
+ self.channel = ircHelpers.getChannel()
+
+ def onRun(self, arguments, messageInfo):
+ command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "server: irc.freenode.net, channel: #reddit-progether")
+ ircHelpers.send(command)
+
View
11 commands/join.py
@@ -0,0 +1,11 @@
+from core import ircBot
+import ircHelpers
+
+@ircBot.registerCommand('join')
+class Reddit:
+ def __init__(self):
+ self.channel = ircHelpers.getChannel()
+
+ def onRun(self, arguments, messageInfo):
+ command = 'JOIN %s \r\n' % arguments
+ ircHelpers.send(command)
View
24 commands/reddit.py
@@ -1,12 +1,12 @@
-from core import ircBot
-import ircHelpers
-
-@ircBot.registerCommand('reddit')
-class Reddit:
- def __init__(self):
- self.channel = ircHelpers.getChannel()
-
- def onRun(self, arguments, messageInfo):
- command = 'PRIVMSG %s :%s\r\n' % (self.channel, "http://reddit.com/r/progether/")
- ircHelpers.send(command)
-
+from core import ircBot
+import ircHelpers
+
+@ircBot.registerCommand('reddit')
+class Reddit:
+ def __init__(self):
+ self.channel = ircHelpers.getChannel()
+
+ def onRun(self, arguments, messageInfo):
+ command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "http://reddit.com/r/progether/")
+ ircHelpers.send(command)
+
View
24 commands/speak.py
@@ -1,12 +1,12 @@
-from core import ircBot
-import ircHelpers
-
-@ircBot.registerCommand('say')
-class Speak:
- def __init__(self):
- self.channel = ircHelpers.getChannel()
-
- def onRun(self, arguments, messageInfo):
- command = 'PRIVMSG %s :%s\r\n' % (self.channel, messageInfo['user'] + ' told me to say ' + arguments)
- ircHelpers.send(command)
-
+from core import ircBot
+import ircHelpers
+
+@ircBot.registerCommand('say')
+class Speak:
+ def __init__(self):
+ self.channel = ircHelpers.getChannel()
+
+ def onRun(self, arguments, messageInfo):
+ command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], messageInfo['user'] + ' told me to say ' + arguments)
+ ircHelpers.send(command)
+
View
24 commands/wiki.py
@@ -1,12 +1,12 @@
-from core import ircBot
-import ircHelpers
-
-@ircBot.registerCommand('wiki')
-class Wiki:
- def __init__(self):
- self.channel = ircHelpers.getChannel()
-
- def onRun(self, arguments, messageInfo):
- command = 'PRIVMSG %s :%s\r\n' % (self.channel, "http://http://progether.wikia.com/wiki/Progether_Wiki/")
- ircHelpers.send(command)
-
+from core import ircBot
+import ircHelpers
+
+@ircBot.registerCommand('wiki')
+class Wiki:
+ def __init__(self):
+ self.channel = ircHelpers.getChannel()
+
+ def onRun(self, arguments, messageInfo):
+ command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "http://http://progether.wikia.com/wiki/Progether_Wiki/")
+ ircHelpers.send(command)
+
View
180 core.py
@@ -1,90 +1,90 @@
-import socket, re
-import chatLog
-
-from commandModule import CommandModule
-from behaviourModule import BehaviourModule
-
-from settings import read_config
-
-class IRCBot:
- def __init__(self, tempCacheSize=4096):
- conf = read_config()
- self.network = conf['network']
- self.port = int(conf['port'])
- self.channel = conf['channel']
- self.quitCmd = conf['quit']
- self.nickname = conf['nick']
- self.password = conf['password']
- self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-
- self.tempCacheSize = tempCacheSize
- self.cLog = chatLog.ChatLog()
-
- self.behaviourModule = BehaviourModule()
- 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>.+)")
-
- def run(self):
- self.socket.connect((self.network, self.port))
- self.log(self.socket.recv(self.tempCacheSize))
- 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:
- receivedData = self.socket.recv(self.tempCacheSize)
- #self.log(recievedData)
- messageInfo = dict()
- isChat = self.regexIsChat.match(receivedData)
- if isChat:
- messageInfo['user'] = isChat.group('user')
- messageInfo['isp'] = isChat.group('isp')
- messageInfo['channel'] = isChat.group('channel')
- messageInfo['message'] = isChat.group('message')
-
- isCommand = self.regexIsCommand.match(messageInfo['message'])
- if isCommand:
- self.commandModule.runCommand(isCommand.group('command'), messageInfo)
-
- self.behaviourModule.performBehaviours(receivedData)
-
- #temporary quit method, should be changed so only admins can use
- if receivedData.find(self.quitCmd) != -1:
- self.log("Quitting")
- self.socket.send('QUIT\r\n')
- break
-
- #make sure we don't time out of server
- 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
- print stringToLog
- self.cLog.addLog(stringToLog)
-
- def registerCommand(self, commandName, **options):
- def decorator(f):
- self.commandModule.commandList[commandName] = f()
- return f
- return decorator
-
- def registerBehaviour(self, **options):
- def decorator(f):
- self.behaviourModule.behaviourList.append(f())
- return f
- return decorator
-
-ircBot = IRCBot()
-
+import socket, re
+import chatLog
+
+from commandModule import CommandModule
+from behaviourModule import BehaviourModule
+
+from settings import read_config
+
+class IRCBot:
+ def __init__(self, tempCacheSize=4096):
+ conf = read_config()
+ self.network = conf['network']
+ self.port = int(conf['port'])
+ self.channel = conf['channel']
+ self.quitCmd = conf['quit']
+ self.nickname = conf['nick']
+ self.password = conf['password']
+ self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+ self.tempCacheSize = tempCacheSize
+ self.cLog = chatLog.ChatLog()
+
+ self.behaviourModule = BehaviourModule()
+ 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>.+)")
+
+ def run(self):
+ self.socket.connect((self.network, self.port))
+ self.log(self.socket.recv(self.tempCacheSize))
+ 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:
+ receivedData = self.socket.recv(self.tempCacheSize)
+ #self.log(recievedData)
+ messageInfo = dict()
+ isChat = self.regexIsChat.match(receivedData)
+ if isChat:
+ messageInfo['user'] = isChat.group('user')
+ messageInfo['isp'] = isChat.group('isp')
+ messageInfo['channel'] = isChat.group('channel')
+ messageInfo['message'] = isChat.group('message')
+
+ isCommand = self.regexIsCommand.match(messageInfo['message'])
+ if isCommand:
+ self.commandModule.runCommand(isCommand.group('command'), messageInfo)
+
+ self.behaviourModule.performBehaviours(receivedData)
+
+ #temporary quit method, should be changed so only admins can use
+ if receivedData.find(self.quitCmd) != -1:
+ self.log("Quitting")
+ self.socket.send('QUIT\r\n')
+ break
+
+ #make sure we don't time out of server
+ 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
+ print stringToLog
+ self.cLog.addLog(stringToLog)
+
+ def registerCommand(self, commandName, **options):
+ def decorator(f):
+ self.commandModule.commandList[commandName] = f()
+ return f
+ return decorator
+
+ def registerBehaviour(self, **options):
+ def decorator(f):
+ self.behaviourModule.behaviourList.append(f())
+ return f
+ return decorator
+
+ircBot = IRCBot()
+
View
88 settings.py
@@ -1,41 +1,47 @@
-from ConfigParser import ConfigParser
-
-def create_config():
- config_file = open("settings.txt", 'w')
- file_content = """\
- [settings]
- nick = tmpircbotname
- port = 6667
- network = irc.freenode.net
- quit = !!quit
- channel = #reddit-progether
- password = 1234test
- """
- file_content = file_content.splitlines()
- for line in file_content:
- config_file.write(line.strip() + "\n")
- config_file.close()
-
-def read_config():
- config = dict()
- config_file = ConfigParser()
- config_file.read("settings.txt")
- config['nick'] = config_file.get('settings', 'nick')
- config['network'] = config_file.get('settings', 'network')
- config['port'] = config_file.get('settings', 'port')
- config['channel'] = config_file.get('settings', 'channel')
- config['quit'] = config_file.get('settings', 'quit')
- config['password'] = config_file.get('settings', 'password')
- return config
-
-
-
-if __name__ == '__main__':
- create_config()
- conf = read_config()
- print conf['nick']
- print conf['network']
- print conf['port']
- print conf['channel']
- print conf['quit']
- print conf['password']
+from ConfigParser import ConfigParser
+
+FILE_NAME = "settings.txt"
+
+def create_config():
+ config_file = open(FILE_NAME, 'w')
+ file_content = """\
+ [settings]
+ nick = tmpircbotname
+ port = 6667
+ network = irc.freenode.net
+ quit = !!quit
+ channel = #reddit-progether
+ password = 1234test
+ """
+ file_content = file_content.splitlines()
+ for line in file_content:
+ config_file.write(line.strip() + "\n")
+ config_file.close()
+
+def read_config():
+ config = dict()
+ config_file = ConfigParser()
+ config_file.read(FILE_NAME)
+ if not config_file.has_section('settings'):
+ print "Unable to read settings file at %s" % FILE_NAME
+ create_config()
+ config_file.read(FILE_NAME)
+ print "Created new settings file at %s" % FILE_NAME
+
+ config['nick'] = config_file.get('settings', 'nick')
+ config['network'] = config_file.get('settings', 'network')
+ config['port'] = config_file.get('settings', 'port')
+ config['channel'] = config_file.get('settings', 'channel')
+ config['quit'] = config_file.get('settings', 'quit')
+ config['password'] = config_file.get('settings', 'password')
+ return config
+
+
+if __name__ == '__main__':
+ create_config()
+ conf = read_config()
+ print conf['nick']
+ print conf['network']
+ print conf['port']
+ print conf['channel']
+ print conf['password']
Please sign in to comment.
Something went wrong with that request. Please try again.