#!/usr/bin/env /usr/bin/python3 import config import lang priv_map = {} m_conf = config.get_plgconf("privilege") def get_priv(cmd): return priv_map[cmd] def set_priv(cmd, priv): priv_map[cmd] = priv import main R = main.R import database def get_userpriv(user): ud = database.get_user_details(user) if ud != None: if ("privilege" in ud): return _("Username: %(username)s has privilege %(pri)i.") % { 'username': user, 'pri': ud["privilege"] } return _("Username: %s info not exist in database.") % user
#!/usr/bin/env /usr/bin/python3 import plyvel, os import config m_conf = config.get_plgconf("database") import main R = main.R import json import lang import yaml user_db = os.getcwd() + m_conf["user_path"] def check_dbs(): if not os.path.exists(user_db): os.makedirs(user_db) db = plyvel.DB(user_db, create_if_missing=True) for key, value in db: if key == b'': db.delete("".encode("utf-8"), sync=True) db.close() def get_user_details(uname): db = plyvel.DB(user_db) tmp = db.get(uname.encode('utf-8')) db.close() if tmp == None: return None else: return json.loads(tmp.decode('utf-8'))
#!/usr/bin/env /usr/bin/python3 import sleekxmpp import config import main import privilege import time import lang import re m_conf = config.get_plgconf("xmpp") xmpp_priv = {} xmpp_priv["moderator"] = 2 xmpp_priv["participant"] = 4 refractory_p = m_conf["refractory"] refr_alert = {} last_time = dict() B = main.B class MUCBot(sleekxmpp.ClientXMPP): def __init__(self, jid, password, roomlist): sleekxmpp.ClientXMPP.__init__(self, jid, password) self.roles = dict() self.muc_jid = dict() self.reply_to_nonmuc = True self.roomlist = roomlist self.add_event_handler("message", self.message) self.add_event_handler("session_start", self.start) self.add_event_handler("groupchat_message", self.muc_message) self.add_event_handler("groupchat_presence", self.muc_presence) # self.add_event_handler("muc::%s::got_online" % self.room, self.muc_online)
#!/usr/bin/env /usr/bin/python3 import main B = main.B import lang import config import privilege m_conf = config.get_plgconf("ircproto") from irc3.plugins.command import command from irc3.testing import ini2config import irc3 import os import re import threading @irc3.plugin class MyPlugin: requires = [ 'irc3.plugins.core', # 'irc3.plugins.userlist', # 'irc3.plugins.command', ] def __init__(self, bot): self.bot = bot self.log = self.bot.log self.joinoninvite = False # def connection_made(self): # """triggered when connection is up"""
#!/usr/bin/env /usr/bin/python3 # -*- coding: utf-8 -*- import logging import telegram from telegram.error import NetworkError, Unauthorized import main B = main.B import lang import config import privilege import plyvel,os m_conf=config.get_plgconf("telegram") tg_db = os.getcwd()+m_conf["database"] import threading import re if not 'token' in m_conf: raise Exception(_("Token not found in the configure file.")) class tg_bot(): def __init__(self): self.update_id = None self.bot = telegram.Bot(m_conf["token"]) def msg_proc(self): updates = self.bot.getUpdates(offset=self.update_id,timeout=10) for u in updates: self.update_id = u.update_id + 1 print(u)
#!/usr/bin/env /usr/bin/python3 import sys,os,imp import config import main import lang R = main.R plugindir=os.getcwd()+config.get_plgconf("path") sys.path.append(plugindir) plgmap={} #def list_plugins(): # tmpl=[] # for parent,dirnames,filenames in os.walk(plugindir): # for f in filenames: # ext = f[f.index("."):] # if(ext == ".py" or ext == ".so" or ext == ".pyc"): # tmpl.append(f) # return tmpl def load_plugin(plugindir,mod_name): f, filename, description = imp.find_module(mod_name,[plugindir]) print(_("Loading plugin: %(name)s , %(desc)s") %{'name':filename, 'desc':description}) return imp.load_module(mod_name, f, filename, description) @R.add(_(".*\:\s?\/listplugins\s?"),"oncommand") def list_plugin(msg): res = _("All plugin:\n") for k in plgmap: res+=k res+="\n"
#!/usr/bin/env /usr/bin/python3 import main import privilege import config import time,os import lang import gzip import tarfile import re m_conf=config.get_plgconf("logg") R = main.R log_path=os.getcwd()+m_conf["path"] log_flag={} ISOTIMEFORMAT='%Y-%m-%d %X' def check_log_dir(): if os.path.isdir(log_path): return True else: return False def go_gzip(s,d): buf = b"" if os.path.isfile(s): with open(s, 'rb') as f: buf += f.read() with gzip.open(d, 'wb') as f: f.write(buf) return 0
#!/usr/bin/env /usr/bin/python3 import os import config m_conf=config.get_plgconf("library") import main import pluginmgr R = main.R import json import lang import uuid import database libpath = os.getcwd()+m_conf["path"] lib = dict() pcpy = ["name","id","type"] c_enum = m_conf["def_obj_enum"] c_inve = m_conf["def_obj_dir"] def load_lib(): file_list = [os.path.join(dp, f) for dp, dn, filenames in os.walk(libpath) for f in filenames if os.path.splitext(f)[1] == '.json'] for a_file in file_list: tmp = open(a_file) m_dat = json.load(tmp) tmp.close() for item in m_dat: if "type" in item: if not item["type"] in lib: lib[item["type"]] = dict() if "id" in item: m_id = item["id"] if m_id in lib[item["type"]]:
#!/usr/bin/env /usr/bin/python3 import gettext import locale import os import config appname = config.datamap["appname"] c_locale = config.get_plgconf("languages") gettext.bindtextdomain(appname, os.getcwd() + c_locale["locale"] + "/") gettext.textdomain(appname) lang_map = dict() if "default" in c_locale: def_lang = gettext.translation(appname, os.getcwd() + c_locale["locale"] + "/", languages=[c_locale["default"]]) cur_loc = c_locale["default"] else: current_locale, encoding = locale.getdefaultlocale() def_lang = gettext.translation(appname, os.getcwd() + c_locale["locale"] + "/", languages=[current_locale]) cur_loc = current_locale def_lang.install() import main R = main.R @R.add(_(".*\:\s?\/listlangs\s?"), "oncommand")
#!/usr/bin/env /usr/bin/python3 import main import lang import config import database m_conf = config.get_plgconf("htmlext") import os import threading from flask import Flask, request, send_from_directory, render_template, redirect, make_response def m_valid_login(user, passw): # if user in pluginmgr.plgmap["xmpp"].m_bot.muc_jid: # print(_("Redirecting user privilege change to real JID.")) # user = pluginmgr.plgmap["xmpp"].m_bot.muc_jid[user] ud = database.get_user_details(user) if ud == None: return False return True class WebServer: def __init__(self): self.app = Flask(__name__, static_folder=m_conf["base"], template_folder=m_conf["base"] + '/templates') self.app.root_path = os.getcwd() self.set_router()