-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from joshgit/master
adding join command for multiple channels
- Loading branch information
Showing
10 changed files
with
221 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,12 +1,12 @@ | |||
from core import ircBot | from core import ircBot | ||
import ircHelpers | import ircHelpers | ||
|
|
||
@ircBot.registerCommand('faq') | @ircBot.registerCommand('faq') | ||
class Faq: | class Faq: | ||
def __init__(self): | def __init__(self): | ||
self.channel = ircHelpers.getChannel() | self.channel = ircHelpers.getChannel() | ||
|
|
||
def onRun(self, arguments, messageInfo): | def onRun(self, arguments, messageInfo): | ||
command = 'PRIVMSG %s :%s\r\n' % (self.channel, "http://code.reddit.com/wiki/help/faqs/progether") | command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "http://code.reddit.com/wiki/help/faqs/progether") | ||
ircHelpers.send(command) | ircHelpers.send(command) | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,12 +1,12 @@ | |||
from core import ircBot | from core import ircBot | ||
import ircHelpers | import ircHelpers | ||
|
|
||
@ircBot.registerCommand('git') | @ircBot.registerCommand('git') | ||
class Git: | class Git: | ||
def __init__(self): | def __init__(self): | ||
self.channel = ircHelpers.getChannel() | self.channel = ircHelpers.getChannel() | ||
|
|
||
def onRun(self, arguments, messageInfo): | def onRun(self, arguments, messageInfo): | ||
command = 'PRIVMSG %s :%s\r\n' % (self.channel, "https://github.com/Progether") | command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "https://github.com/Progether") | ||
ircHelpers.send(command) | ircHelpers.send(command) | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,12 +1,12 @@ | |||
from core import ircBot | from core import ircBot | ||
import ircHelpers | import ircHelpers | ||
|
|
||
@ircBot.registerCommand('irc') | @ircBot.registerCommand('irc') | ||
class IRC: | class IRC: | ||
def __init__(self): | def __init__(self): | ||
self.channel = ircHelpers.getChannel() | self.channel = ircHelpers.getChannel() | ||
|
|
||
def onRun(self, arguments, messageInfo): | def onRun(self, arguments, messageInfo): | ||
command = 'PRIVMSG %s :%s\r\n' % (self.channel, "server: irc.freenode.net, channel: #reddit-progether") | command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "server: irc.freenode.net, channel: #reddit-progether") | ||
ircHelpers.send(command) | ircHelpers.send(command) | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,12 +1,12 @@ | |||
from core import ircBot | from core import ircBot | ||
import ircHelpers | import ircHelpers | ||
|
|
||
@ircBot.registerCommand('reddit') | @ircBot.registerCommand('reddit') | ||
class Reddit: | class Reddit: | ||
def __init__(self): | def __init__(self): | ||
self.channel = ircHelpers.getChannel() | self.channel = ircHelpers.getChannel() | ||
|
|
||
def onRun(self, arguments, messageInfo): | def onRun(self, arguments, messageInfo): | ||
command = 'PRIVMSG %s :%s\r\n' % (self.channel, "http://reddit.com/r/progether/") | command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "http://reddit.com/r/progether/") | ||
ircHelpers.send(command) | ircHelpers.send(command) | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,12 +1,12 @@ | |||
from core import ircBot | from core import ircBot | ||
import ircHelpers | import ircHelpers | ||
|
|
||
@ircBot.registerCommand('say') | @ircBot.registerCommand('say') | ||
class Speak: | class Speak: | ||
def __init__(self): | def __init__(self): | ||
self.channel = ircHelpers.getChannel() | self.channel = ircHelpers.getChannel() | ||
|
|
||
def onRun(self, arguments, messageInfo): | def onRun(self, arguments, messageInfo): | ||
command = 'PRIVMSG %s :%s\r\n' % (self.channel, messageInfo['user'] + ' told me to say ' + arguments) | command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], messageInfo['user'] + ' told me to say ' + arguments) | ||
ircHelpers.send(command) | ircHelpers.send(command) | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,12 +1,12 @@ | |||
from core import ircBot | from core import ircBot | ||
import ircHelpers | import ircHelpers | ||
|
|
||
@ircBot.registerCommand('wiki') | @ircBot.registerCommand('wiki') | ||
class Wiki: | class Wiki: | ||
def __init__(self): | def __init__(self): | ||
self.channel = ircHelpers.getChannel() | self.channel = ircHelpers.getChannel() | ||
|
|
||
def onRun(self, arguments, messageInfo): | def onRun(self, arguments, messageInfo): | ||
command = 'PRIVMSG %s :%s\r\n' % (self.channel, "http://http://progether.wikia.com/wiki/Progether_Wiki/") | command = 'PRIVMSG %s :%s\r\n' % (messageInfo['channel'], "http://http://progether.wikia.com/wiki/Progether_Wiki/") | ||
ircHelpers.send(command) | ircHelpers.send(command) | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,90 +1,90 @@ | |||
import socket, re | import socket, re | ||
import chatLog | import chatLog | ||
|
|
||
from commandModule import CommandModule | from commandModule import CommandModule | ||
from behaviourModule import BehaviourModule | from behaviourModule import BehaviourModule | ||
|
|
||
from settings import read_config | from settings import read_config | ||
|
|
||
class IRCBot: | class IRCBot: | ||
def __init__(self, tempCacheSize=4096): | def __init__(self, tempCacheSize=4096): | ||
conf = read_config() | conf = read_config() | ||
self.network = conf['network'] | self.network = conf['network'] | ||
self.port = int(conf['port']) | self.port = int(conf['port']) | ||
self.channel = conf['channel'] | self.channel = conf['channel'] | ||
self.quitCmd = conf['quit'] | self.quitCmd = conf['quit'] | ||
self.nickname = conf['nick'] | self.nickname = conf['nick'] | ||
self.password = conf['password'] | self.password = conf['password'] | ||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
|
|
||
self.tempCacheSize = tempCacheSize | self.tempCacheSize = tempCacheSize | ||
self.cLog = chatLog.ChatLog() | self.cLog = chatLog.ChatLog() | ||
|
|
||
self.behaviourModule = BehaviourModule() | self.behaviourModule = BehaviourModule() | ||
self.commandModule = CommandModule() | self.commandModule = CommandModule() | ||
|
|
||
self.regexIsCommand = re.compile(r"(?P<command>!!..+)") | 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): | def run(self): | ||
self.socket.connect((self.network, self.port)) | self.socket.connect((self.network, self.port)) | ||
self.log(self.socket.recv(self.tempCacheSize)) | self.log(self.socket.recv(self.tempCacheSize)) | ||
self.socket.send('NICK %s \r\n' % self.nickname) | 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('USER %s some stuff :Python IRC\r\n' % self.nickname)#change this | ||
self.socket.send('JOIN %s \r\n' % self.channel) | 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. | # 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.socket.send('PRIVMSG NickServ :IDENTIFY %s %s\r\n' % (self.nickname, self.password)) | ||
|
|
||
self.mainLoop() | self.mainLoop() | ||
|
|
||
def mainLoop(self): | def mainLoop(self): | ||
while True: | while True: | ||
receivedData = self.socket.recv(self.tempCacheSize) | receivedData = self.socket.recv(self.tempCacheSize) | ||
#self.log(recievedData) | #self.log(recievedData) | ||
messageInfo = dict() | messageInfo = dict() | ||
isChat = self.regexIsChat.match(receivedData) | isChat = self.regexIsChat.match(receivedData) | ||
if isChat: | if isChat: | ||
messageInfo['user'] = isChat.group('user') | messageInfo['user'] = isChat.group('user') | ||
messageInfo['isp'] = isChat.group('isp') | messageInfo['isp'] = isChat.group('isp') | ||
messageInfo['channel'] = isChat.group('channel') | messageInfo['channel'] = isChat.group('channel') | ||
messageInfo['message'] = isChat.group('message') | messageInfo['message'] = isChat.group('message') | ||
|
|
||
isCommand = self.regexIsCommand.match(messageInfo['message']) | isCommand = self.regexIsCommand.match(messageInfo['message']) | ||
if isCommand: | if isCommand: | ||
self.commandModule.runCommand(isCommand.group('command'), messageInfo) | self.commandModule.runCommand(isCommand.group('command'), messageInfo) | ||
|
|
||
self.behaviourModule.performBehaviours(receivedData) | self.behaviourModule.performBehaviours(receivedData) | ||
|
|
||
#temporary quit method, should be changed so only admins can use | #temporary quit method, should be changed so only admins can use | ||
if receivedData.find(self.quitCmd) != -1: | if receivedData.find(self.quitCmd) != -1: | ||
self.log("Quitting") | self.log("Quitting") | ||
self.socket.send('QUIT\r\n') | self.socket.send('QUIT\r\n') | ||
break | break | ||
|
|
||
#make sure we don't time out of server | #make sure we don't time out of server | ||
if receivedData.find('PING') != -1: | if receivedData.find('PING') != -1: | ||
self.socket.send('PONG %s \r\n' % receivedData.split()[1]) | self.socket.send('PONG %s \r\n' % receivedData.split()[1]) | ||
else: | else: | ||
# moved log here to filter out ping/pong chatter | # moved log here to filter out ping/pong chatter | ||
self.log(receivedData) | self.log(receivedData) | ||
|
|
||
def log(self, stringToLog): | def log(self, stringToLog): | ||
#change eventually to log in a file but for now print is fine | #change eventually to log in a file but for now print is fine | ||
print stringToLog | print stringToLog | ||
self.cLog.addLog(stringToLog) | self.cLog.addLog(stringToLog) | ||
|
|
||
def registerCommand(self, commandName, **options): | def registerCommand(self, commandName, **options): | ||
def decorator(f): | def decorator(f): | ||
self.commandModule.commandList[commandName] = f() | self.commandModule.commandList[commandName] = f() | ||
return f | return f | ||
return decorator | return decorator | ||
|
|
||
def registerBehaviour(self, **options): | def registerBehaviour(self, **options): | ||
def decorator(f): | def decorator(f): | ||
self.behaviourModule.behaviourList.append(f()) | self.behaviourModule.behaviourList.append(f()) | ||
return f | return f | ||
return decorator | return decorator | ||
|
|
||
ircBot = IRCBot() | ircBot = IRCBot() | ||
|
Oops, something went wrong.