mirror of
https://github.com/krislamo/Flea
synced 2024-12-16 11:10:34 +00:00
Added simple Plugin functionality
Added very basic Plugin and reimporting functionality; Password is now sent after NickServ informs you that your nick is registered; Bugfix: cfgParser will now convert the string "false" to a boolean;
This commit is contained in:
parent
5b7d245347
commit
ec0e9a3485
@ -107,7 +107,7 @@ def cfgParser(cfgFile):
|
|||||||
if settings[x].lower() == "true":
|
if settings[x].lower() == "true":
|
||||||
settings[x] = True
|
settings[x] = True
|
||||||
elif settings[x].lower() == "false":
|
elif settings[x].lower() == "false":
|
||||||
settings[x] == False
|
settings[x] = False
|
||||||
|
|
||||||
# Conversion for positive integers
|
# Conversion for positive integers
|
||||||
elif re.search("^[0-9]+$", settings[x]) != None:
|
elif re.search("^[0-9]+$", settings[x]) != None:
|
||||||
|
@ -92,8 +92,11 @@ class irc:
|
|||||||
def Mode(self, nick, mode):
|
def Mode(self, nick, mode):
|
||||||
self.msg("MODE "+ nick + " "+mode)
|
self.msg("MODE "+ nick + " "+mode)
|
||||||
|
|
||||||
|
def PrivMsg(self, user, message):
|
||||||
|
self.msg("PRIVMSG "+user+" :"+message)
|
||||||
|
|
||||||
def Identify(self, password):
|
def Identify(self, password):
|
||||||
self.msg("NickServ IDENTIFY "+password)
|
self.PrivMsg("NickServ", "IDENTIFY "+password)
|
||||||
|
|
||||||
def Join(self, channel):
|
def Join(self, channel):
|
||||||
self.msg("JOIN "+channel)
|
self.msg("JOIN "+channel)
|
||||||
@ -104,9 +107,6 @@ class irc:
|
|||||||
def Notice(self, message, user):
|
def Notice(self, message, user):
|
||||||
self.msg("NOTICE "+user+" :"+message)
|
self.msg("NOTICE "+user+" :"+message)
|
||||||
|
|
||||||
def PrivMsg(self, user, message):
|
|
||||||
self.msg("PRIVMSG "+user+" :"+message)
|
|
||||||
|
|
||||||
def Part(self, channel, message):
|
def Part(self, channel, message):
|
||||||
self.msg("PART "+channel+" "+message)
|
self.msg("PART "+channel+" "+message)
|
||||||
|
|
||||||
|
81
core/main.py
81
core/main.py
@ -18,12 +18,83 @@ from core.config import *
|
|||||||
import core.irclib as irclib
|
import core.irclib as irclib
|
||||||
|
|
||||||
# Built-in to Python 2.7
|
# Built-in to Python 2.7
|
||||||
|
import __builtin__
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
# Allows reimporting modules
|
||||||
|
class ImportRollback:
|
||||||
|
def __init__(self):
|
||||||
|
# Dictionary of loaded modules
|
||||||
|
self.curMods = sys.modules.copy()
|
||||||
|
self.newImport = __builtin__.__import__
|
||||||
|
|
||||||
|
# Directory of plugins
|
||||||
|
self.plugins = os.getcwd()+"/plugins/"
|
||||||
|
|
||||||
|
# Add the plugins location to the path variable
|
||||||
|
# Helps the system find the plugin modules
|
||||||
|
sys.path.append(self.plugins)
|
||||||
|
|
||||||
|
# Override builtin import function with install()
|
||||||
|
__builtin__.__import__ = self.install
|
||||||
|
self.newMods = {}
|
||||||
|
|
||||||
|
# Import modules
|
||||||
|
def install(self, mod, globals=None, locals=None, fromlist=[]):
|
||||||
|
self.newMods[mod] = 1
|
||||||
|
return apply(self.newImport, (mod, globals, locals, fromlist))
|
||||||
|
|
||||||
|
# Delete modules
|
||||||
|
def reset(self):
|
||||||
|
for mod in self.newMods.keys():
|
||||||
|
if not self.curMods.has_key(mod):
|
||||||
|
del(sys.modules[mod])
|
||||||
|
|
||||||
|
__builtin__.__import__ = self.newImport
|
||||||
|
|
||||||
|
|
||||||
|
def PluginsImport():
|
||||||
|
# Get root of Flea
|
||||||
|
current = os.getcwd()
|
||||||
|
# Path to /plugins/ under /Flea/
|
||||||
|
plugins = current+"/plugins/"
|
||||||
|
|
||||||
|
# If /plugins/ exists change directory to it
|
||||||
|
if os.path.exists(plugins):
|
||||||
|
os.chdir(plugins)
|
||||||
|
|
||||||
|
# Go through every item in /plugins/
|
||||||
|
for item in os.listdir(plugins):
|
||||||
|
|
||||||
|
# Only import directory plugins (no single files)
|
||||||
|
if os.path.isdir(plugins+item):
|
||||||
|
print "[Plugins] Initializing "+item
|
||||||
|
__import__(item+".main")
|
||||||
|
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
os.chdir(current)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
# Parse main settings.conf file
|
||||||
config = cfgParser("settings.conf")
|
config = cfgParser("settings.conf")
|
||||||
|
|
||||||
|
# Keep track of modules for a rollback
|
||||||
|
importctrl = ImportRollback()
|
||||||
|
|
||||||
|
# Import /plugins/
|
||||||
|
if config["plugins"]:
|
||||||
|
if not PluginsImport():
|
||||||
|
print "[Plugins] Failed to load."
|
||||||
|
|
||||||
# Create irclib irc object
|
# Create irclib irc object
|
||||||
irc = irclib.irc()
|
irc = irclib.irc()
|
||||||
|
|
||||||
@ -91,12 +162,14 @@ def main():
|
|||||||
elif pack["cmd"] == "001":
|
elif pack["cmd"] == "001":
|
||||||
irc.Mode(config["nick"], config["mode"])
|
irc.Mode(config["nick"], config["mode"])
|
||||||
|
|
||||||
# Send password after End of MOTD
|
elif pack["cmd"] == "NOTICE":
|
||||||
elif pack["cmd"] == "376":
|
if pack["ident"] == "NickServ":
|
||||||
|
# Send password after NickServ informs you
|
||||||
|
# that your nick is registered
|
||||||
|
pattern = r"[Tt]his nickname is registered"
|
||||||
|
if re.search(pattern, pack["text"]):
|
||||||
irc.Identify(config["password"])
|
irc.Identify(config["password"])
|
||||||
# Temp test join
|
|
||||||
irc.Join("#Flea")
|
irc.Join("#Flea")
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
debug = true
|
debug = true
|
||||||
|
plugins = false
|
||||||
|
|
||||||
host = irc.example.net
|
host = irc.example.net
|
||||||
port = 7001
|
port = 7001
|
||||||
|
Loading…
Reference in New Issue
Block a user