IRC-Bot

morphux IRC bot
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/IRC-Bot

commit e42d8b74a6fb3b2758e4769366d6a43f387998bb
parent 5557855d5a3dfbb37bb382d0e97f005b065cf58b
Author: Ne02ptzero <l.solofrizzo@gmail.com>
Date:   Tue, 18 Nov 2014 17:31:48 +0100

Moderation && Base Maj

Diffstat:
Mconfig.json | 8++++----
Mcore/Core.py | 1+
Rmodules/hi/__init__.py -> modules/base/__init__.py | 0
Amodules/base/base.py | 25+++++++++++++++++++++++++
Dmodules/hi/hi.py | 66------------------------------------------------------------------
Rmodules/hi/__init__.py -> modules/moderate/__init__.py | 0
Amodules/moderate/moderate.py | 22++++++++++++++++++++++
Mmorphux.py | 18++++++++++++------
8 files changed, 64 insertions(+), 76 deletions(-)

diff --git a/config.json b/config.json @@ -1,12 +1,12 @@ { "host": "irc.freenode.net", - "chan": "#ne02ptzero", + "chan": "#morphux", "port": "6667", "symbol": "!", - "nick": "Bot2fab4u", - "password": "", + "nick": "CL4P_TP", + "password": "morphuxftw", "debug": 1, - "identify": 0, + "identify": 1, "welcomeMessage": "o/", "errorMessage": "Duknow this command !" } diff --git a/core/Core.py b/core/Core.py @@ -62,6 +62,7 @@ class Core: if (message == ""): message = self.config["banMessage"] self.coreSend("KICK " + self.config["chan"] + " " + user + " : " + message) + print "HERE KICK" # Join a channel def join(self): diff --git a/modules/hi/__init__.py b/modules/base/__init__.py diff --git a/modules/base/base.py b/modules/base/base.py @@ -0,0 +1,25 @@ +# Base Module +# By: Louis <louis@ne02ptzero> + +class Base: + + def command(self): + self.config = { + "command": { + "ping": { + "function": self.ping, + "usage": "ping", + "help": "Make a ping to the bot" + } + }, + "onJoin": { + "join": self.join + } + } + return self.config + + def ping(self, Morphux, infos): + Morphux.sendMessage("Pong !", infos['nick']) + + def join(self, Morphux, user): + Morphux.sendMessage("Hey, howr u doin :) ?", user) diff --git a/modules/hi/hi.py b/modules/hi/hi.py @@ -1,66 +0,0 @@ - -class Hi: - def command(self): - self.config = { - "command": { - "hi": { - "function": self.hiCommand, - "usage": "hi", - "help": "Say hi to the bot" - }, - "cake": { - "function": self.someCake, - "usage": "cake <user>", - "help": "Give a piece of cake to someone !" - } - }, - "onJoin": { - 'sayHello' :self.sayHello - }, - "onLeave": { - 'sayGoodbye': self.sayGoodbye - }, - "onNickChange": { - 'newNick': self.newNick - }, - "onQuit": { - 'quit': self.quit - }, - "before": { - 'before': self.before - }, - "after": { - 'after': self.after - } - } - return self.config - - def hiCommand(self, Morphux, infos): - Morphux.sendMessage("Hello !", infos['nick']) - - def someCake(self, Morphux, infos): - if (len(infos['args'][0]) == 0): - Morphux.sendMessage("Kay fine, i eat my cake alone.", infos['nick']); - if (Morphux.userExists(infos['args'][0])): - Morphux.sendMessage(infos['nick'] + " give u some cake :) !" ,infos['args'][0]) - else: - Morphux.sendMessage("Can't find user " + infos['args'][0], infos['nick']); - - def sayHello(self, Morphux, user): - Morphux.sendMessage("Hi :)", user) - - def sayGoodbye(self, Morphux, user): - Morphux.sendMessage(user + " is dead...") - - def newNick(self, Morphux, oldNick, newNick): - Morphux.sendMessage(oldNick + " change to " + newNick) - - def quit(self, Morphux, nick): - Morphux.sendMessage(nick + " quit !") - - def before(self, Morphux, line): - #Morphux.sendMessage("Before: " + line) - return 1; - - def after(self, Morphux, line): - print "after YAY " + line diff --git a/modules/hi/__init__.py b/modules/moderate/__init__.py diff --git a/modules/moderate/moderate.py b/modules/moderate/moderate.py @@ -0,0 +1,22 @@ +# Moderation Module +# By: Louis <louis@ne02ptzero.me> + +class Moderate: + def command(self): + self.config = { + "command": { + "kick": { + "function": self.kick, + "usage": "kick user", + "help": "GET REKT" + } + } + } + return self.config + + def kick(self, Morphux, infos): + if (Morphux.isAdmin(infos['nick'])): + if (len(infos['args'])): + Morphux.kick(infos['args'][0], "GET REKT") + else: + Morphux.sendMessage("You're not admin !", infos['nick']) diff --git a/morphux.py b/morphux.py @@ -57,7 +57,7 @@ class Morphux: elif (infos != False): if (infos["command"] in self.commands): self.commands[infos["command"]]["function"](self, infos) - print("New command:" + infos["command"]) + print("New command ["+ infos['nick'] +"]: " + infos["command"]) else: self.sendMessage(self.config["errorMessage"], infos["nick"]) for name, function in self.after.items(): @@ -150,6 +150,8 @@ class Morphux: user = line.split(" ") user[0] = user[0][1:] self.currentUsers[user[0].split("!")[0]] = True + if (user[0].split("!")[0] == self.config['nick']): + return for name, function in self.join.items(): function(self, user[0].split("!")[0]) @@ -163,6 +165,8 @@ class Morphux: if (userName[0] in self.currentUsers): del self.currentUsers[userName[0]] self.currentUsers[newNick] = True + if (newNick == self.config['nick']): + return for name, function in self.nickChange.items(): function(self, userName[0], newNick) @@ -173,10 +177,8 @@ class Morphux: line = line.split("\n") for value in line: users = value.split(":") - # :barjavel.freenode.net 353 Bot2fab4u = #morphux :Bot2fab4u abclive ryad Enerdhil[Phone] Valouche Noich @Ne02ptzero enerdhil @CL4P_TP Noich_root if (len(users) >= 2): details = users[1].split(" ") - #print value if (len(details) >= 2): if (details[1] == "353"): users = users[2].split(" ") @@ -220,9 +222,9 @@ class Morphux: # If User is Admin # @param: string def isAdmin(self, nick): - if (userExists(nick)): - if ('isAdmin' in self.currentUsers[nick]): - if (self.currentUsers[nick] == 1): + if (self.userExists(nick)): + if (self.currentUsers[nick] != True): + if ('isAdmin' in self.currentUsers[nick]): return True return False @@ -235,3 +237,7 @@ class Morphux: self.sendMessage(args[0] +": <"+ usage +"> ("+help+")") else: self.sendMessage("Can't find command " + args[0]) + + # Kick an user + def kick(self, user, reason): + self.s.kick(user, reason)