Exemplo n.º 1
0
def getCommandsHelp(user):
    def formatCommands(commands):
        descs = []
        for comand in commands:
            desc = '命令:'+comand.Name+'\n'+\
            '作用:'+comand.Func+'\n'+\
            '用法:'+comand.Usage+'\n'
            descs.append(desc)
        return '\n'.join(descs)  
    commandList = list(filter(lambda com:com.Permission <= user.Level, ALL_COMANDS))
    commandsCount = len(commandList)
    maxCount = 20
    if commandsCount == 0:
        return '暂无可用命令'
    elif commandsCount > maxCount:#拆分
        def splitList(orgList, length):
            listGroups = zip(*(iter(orgList),) *length)
            newList = [list(i) for i in listGroups]
            count = len(orgList) % length
            newList.append(orgList[-count:]) if count !=0 else newList
            return newList
        commandSplitList = splitList(commandList,maxCount)
        for spList in commandSplitList:
            sendTextMsg(user.Id,formatCommands(spList))
        return ''
    else:
        return formatCommands(commandList)
Exemplo n.º 2
0
def _runTaskRightNow(user, funcName):
    func = getattr(task, funcName,None)
    if func is None:
        sendTextMsg(user.Id, '未找到指定任务')
    else:
        if callable(func):
            Logger.v('开始执行' + funcName)
            func(True)
        else:
            Logger.e(func + '无法执行','not callable')
Exemplo n.º 3
0
def _sendMsgToAll(commander, msg):
    users = getUsers()
    result = ''
    if len(users) > 0:
        for user in users:
            sendTextMsg(user.Id, msg)
        result = '已发送<' + msg + '>至{}位用户'.format(len(users))
    else:
        result = '没有可用用户'
    sendTextMsg(commander.Id, result)
Exemplo n.º 4
0
 def getResultAndSend():
     try:
         result = func() if args is None else func(args)
         if not result is None:
             if len(result) < 50 and ('.png' in result
                                     or '.jpg' in result):  #如果是个图片 则发送图片
                 sendImageMsg(to.Id, result)
                 os.remove(result)
             else:
                 sendTextMsg(to.Id, result)
         else:
             Logger.v(func.__name__ + '未返回执行结果')
     except Exception as e:
         Logger.e(func.__name__ + '执行失败', e)
Exemplo n.º 5
0
# -*- coding: utf-8 -*-
# 主入口

import web
from wechat.handle import Handle
from notice.sendWechat import sendTextMsg
from users import MANAGER
import task
from logger import Logger
from utils.speaker import speak

urls = (
    '/wx',
    'Handle',
)

if __name__ == '__main__':
    try:
        noticeTxt = '树莓派控制器已启动'
        speak(noticeTxt)
        sendTextMsg(MANAGER.Id, noticeTxt)
        task.startTasks()
        app = web.application(urls, globals())
        app.run()
    except Exception as e:
        Logger.n('控制器启动失败', e)
Exemplo n.º 6
0
def _startSmallTarget(fromUser=False):  #达目标自动围观
    Logger.v('开始执行达目标自动围观')
    result = autoFollow()
    if result.new_money > 0:
        Logger.v('达目标围观新分得了{}元钱'.format(result.new_money))
        sendTextMsg(MANAGER.Id, '达目标围观新分得了{}元钱'.format(result.new_money))
Exemplo n.º 7
0
def _startMiZhongchou(fromUser=False):  #发送小米众筹产品信息
    Logger.v('开始获取小米众筹产品信息并发送')
    info = getGoodList()
    sendTextMsg(MANAGER.Id, info)
Exemplo n.º 8
0
def _executeShell(user, command):
    status, output = subprocess.getstatusoutput(command)
    result = ('执行成功:\n' if status == 0 else '执行失败:\n') + output
    sendTextMsg(user.Id, result)