From e42d8b74a6fb3b2758e4769366d6a43f387998bb Mon Sep 17 00:00:00 2001 From: Ne02ptzero Date: Tue, 18 Nov 2014 17:31:48 +0100 Subject: [PATCH] Moderation && Base Maj --- config.json | 8 ++-- core/Core.py | 1 + modules/{hi => base}/__init__.py | 0 modules/base/base.py | 25 ++++++++++++ modules/hi/hi.py | 66 -------------------------------- modules/moderate/__init__.py | 0 modules/moderate/moderate.py | 22 +++++++++++ morphux.py | 18 ++++++--- 8 files changed, 64 insertions(+), 76 deletions(-) rename modules/{hi => base}/__init__.py (100%) create mode 100644 modules/base/base.py delete mode 100644 modules/hi/hi.py create mode 100644 modules/moderate/__init__.py create mode 100644 modules/moderate/moderate.py diff --git a/config.json b/config.json index 9e905f8..9cd2975 100644 --- 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 index 2bc9277..fb6f6be 100644 --- a/core/Core.py +++ b/core/Core.py @@ -62,6 +62,7 @@ def kick(self, user, message = ""): 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 similarity index 100% rename from modules/hi/__init__.py rename to modules/base/__init__.py diff --git a/modules/base/base.py b/modules/base/base.py new file mode 100644 index 0000000..a9c5b10 --- /dev/null +++ b/modules/base/base.py @@ -0,0 +1,25 @@ +# Base Module +# By: Louis + +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 deleted file mode 100644 index 1d35b76..0000000 --- a/modules/hi/hi.py +++ /dev/null @@ -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 ", - "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/moderate/__init__.py b/modules/moderate/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/moderate/moderate.py b/modules/moderate/moderate.py new file mode 100644 index 0000000..cb31531 --- /dev/null +++ b/modules/moderate/moderate.py @@ -0,0 +1,22 @@ +# Moderation Module +# By: Louis + +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 index c4c7fdb..a6dfac5 100644 --- a/morphux.py +++ b/morphux.py @@ -57,7 +57,7 @@ def loop(self): 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 @@ def onJoin(self, line): 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 @@ def onNickChange(self, line): 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 @@ def getHeadersLine(self, line): 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 @@ def userExists(self, nick): # 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 @@ def showHelp(self, args): 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)