Exemple #1
0
        repeat_mode = 0
        return {'reply': "复读模式已关闭~( TロT)σ"}


@admin_required
def save_handler(context):
    try:
        with open('waken_list.json', 'w') as f:
            json.dump(waken_list, f)
        with open('waken_num.json', 'w') as f:
            json.dump(waken_num, f)
        return reply("持久化数据成功。")
    except IOError as e:
        return reply(e)


@admin_required
def flush_handler(context):
    if context['user_id'] == 617175214:
        return reply("狗滑稽又来删库了(╯°Д°)╯︵ ┻━┻")
    global today_date, waken_num, repeat_mode
    waken_list.clear()
    waken_num = 0
    repeat_mode = 0
    today_date = date.today()
    return {'reply': "清除数据成功。"}


if __name__ == "__main__":
    bot.run(host='0.0.0.0', port=8080, debug=True)
Exemple #2
0
sched = BackgroundScheduler()


def report():
    get_report(878753509)  # 科协
    get_report(937518271)  # 科创


try:
    init()
except Exception as e:
    pass

bot = CQHttp(api_root='http://127.0.0.1:5700')


@bot.on_message()
def handle_massage(context):
    handler(context, 878753509)
    handler(context, 937518271)

    return {"reply": None, 'at_sender': False}


sched.add_job(report, 'cron', hour='23', minute='55')

sched.start()

bot.run(host='127.0.0.1', port=8080, debug=True)
Exemple #3
0
#!/usr/local/Python3/bin/python3

from pprint import pprint
from cqhttp import CQHttp

bot = CQHttp(api_root='http://192.168.56.3:5700')


@bot.on_message('private')
def handle_msg(ctx):
    pprint(ctx)
    msg = ctx['message']
    bot.send(ctx, msg)


bot.run('127.0.0.1', 8080)
Exemple #4
0
            nickname = context['message'][3:]
            buka = add_card_auto.check_data(nickname)
            bot.send(context, buka)


# 新人加群提醒
@bot.on_event('group_increase')
def handle_group_increase(context):
    if context['group_id'] == setting.groupid():
        welcome = [{
            'type': 'text',
            'data': {
                'text': '欢迎新聚聚:'
            }
        }, {
            'type': 'at',
            'data': {
                'qq': str(context['user_id'])
            }
        }, {
            'type': 'text',
            'data': {
                'text': ',进了应援会的门就是源源的人\n%s' % setting.welcome()
            }
        }]
        bot.send(context, message=welcome, is_raw=True)  # 发送欢迎新人


# 如果修改了端口,请修改http-API插件的配置文件中对应的post_url
bot.run(host='127.0.0.1', port=8080)
Exemple #5
0
        return text
    elif ('课' in text) and ('上' in text):
        return text
    elif ('面试' in text) or ('校招' in text):
        return text
    return ''


@bot.on_message()
def handle_msg(context):
    global last_context
    last_context = context

    new_text = filter(context['message'])
    if new_text != "":
        client.send(new_text)

    bot.send(context, '你好呀,下面一条是你刚刚发的:')
    return {'reply': context['message'], 'at_sender': False}


@client.on_received
def on_received(protocol, text):
    global last_context
    global bot
    bot.send(last_context, text)


client.start(wait=False)
bot.run(host='0.0.0.0', port=8080)
Exemple #6
0
                bot.send(event, message=bot_msg)
            if usr_chooce in menu_dic:
                usr_msg = usr_msg.strip(usr_chooce)
                bot.send(event, menu_dic[usr_chooce](usr_msg))
    except KeyError:
        # 聊天语句没有@机器人就会报错内容为KeyErro
        pass


@bot.on_message('private')
def handle_private_msg(event):
    print(event)
    bot.send(event, message='私人消息发送成功')


bot.run(host='127.0.0.1', port=5701, debug=True)

#bot_server = Flask(__name__)
#@bot_server.route('/api/message',methods=['POST'])
#def server():
#    data = request.get_data().decode('utf8')
#    data = loads(data)
#    print(data['message'][0]['data']['text'])
#bot_server.run(port=5701)
#data = {
#    'user_id':394761716,
#    'message':myfunc.weather(),
#    'auto_escape':False,
#}
#api_url = 'http://127.0.0.1:5700/send_private_msg'
#r = requests.post(api_url, data=data)
Exemple #7
0
@bot.on_request('friend')
def handle_request(context):
    mysqlconn.ping(reconnect=True)
    sql = 'INSERT INTO service_log (time, type, target) VALUES (NOW(),"friendAdd",%s)'
    mysqldb.execute(sql, (f'person:{context["user_id"]}'))
    mysqlconn.commit()
    return {"approve": True}


##群成员增加 待开发
@bot.on_notice('group_increase')
def handle_request(context):
    mysqlconn.ping(reconnect=True)
    sql = 'INSERT INTO service_log (time, type, target) VALUES (NOW(),"groupMumAdd",%s)'
    mysqldb.execute(sql, (f'group:{context["group_id"]}'))
    mysqlconn.commit()


##加群请求 待开发
@bot.on_request("group")
def handle_group_increase(context):
    mysqlconn.ping(reconnect=True)
    sql = 'INSERT INTO service_log (time, type, target) VALUES (NOW(),"groupMumReq",%s)'
    mysqldb.execute(
        sql, (f'group:{context["user_id"]};person:{context["group_id"]}'))
    mysqlconn.commit()


if __name__ == '__main__':
    bot.run()
Exemple #8
0
from cqhttp import CQHttp

bot = CQHttp(api_root='http://127.0.0.1:5701/')


@bot.on_message()
def handle_msg(context):
    # 下面这句等价于 bot.send_private_msg(user_id=context['user_id'], message='你好呀,下面一条是你刚刚发的:')
    bot.send(context, '你好呀,下面一条是你刚刚发的:')
    return {'reply': context['message'], 'at_sender': False}  # 返回给 HTTP API 插件,走快速回复途径


@bot.on_event('group_increase')
def handle_group_increase(context):
    nickname = bot.get_group_member_info(group_id=context['group_id'],
                                         user_id=context['user_id'])['nickname']
    name = nickname if nickname else '新人'
    bot.send(context, message='欢迎{}~'.format(name), is_raw=True)


@bot.on_request('group')
def handle_group_request(context):
    if context['message'] != 'some-secret':
        # 验证信息不符,拒绝
        return {'approve': False, 'reason': '你填写的验证信息有误'}
    return {'approve': True}


bot.run(host='127.0.0.1', port=8080)
            except Exception as err:  # FileExistsError or OSError:
                print(str(err))
                suo1 = False
                suo2 = False
                suo3 = False
                suo3 = False
                temp3 = None
                temp4 = None
                timer1.cancel()
                bot.send(mubiao, '发b站动态出错:'+str(err))
        #pair = message.startswith("发送内容")
        if message == "发送内容" and suo1 == False:
            suo2 = True
            bot.send(mubiao, '请在120秒内输入消息')
            timer1 = Timer(120, suox)
            timer1.start()
            return

if __name__ == '__main__':
    '''
    wenjianjia='./imgs/'
    try:
        os.makedirs(wenjianjia)#自动创建目录,发现目录
    except Exception as err:  # FileExistsError or OSError:
        print(str(err))
    '''
    bot.run(host='127.0.0.1', port=8887)

#未严格测试!!!!!!!!!!!!!!!!!!!!!!!

Exemple #10
0
    #     out_message = redis_keywords.miguPunchIn()
    #     bot.send(event, message=out_message, user_id='825503975')

    message = event['message']
    ic(message, type(message))
    allowlist = redis_keywords.get_keywords(key=allowlist_key)
    denylist = redis_keywords.get_keywords(key=denylist_key)

    # deny, allow 形如 食:面包 牛奶
    # 分类: 细分
    for deny in denylist:
        for d in deny.split(':', 1)[1].split():
            if d in message:
                return
    for allow in allowlist:
        for a in allow.split(':', 1)[1].split():
            if a in message:
                # mail('qqbot', f'[{a}]优惠信息', convert(message))
                out_message = f'关键词:{a}\n{message}\n转发自群聊:{event["group_id"]}'
                bot.send_group_msg(group_id=group_id, message=out_message)
                # bot.send(event, message=out_message, group_id=group_id)
                break


@bot.on_request('group', 'friend')
def handle_request(event):
    return {'approve': True}  # 同意所有加群、加好友请求


bot.run(host='0.0.0.0', port=9999, debug=True)
Exemple #11
0
                                                       neededVarName,
                                                       isIndividual,
                                                       defaultValue)
            intercepted = func(bot, context, msg, state, individualState,
                               inputVars, updateVars)
            if intercepted:
                everIntercepted = True
                break

        if not everIntercepted and state == "idle":
            for priority, func, neededVars in idleFuncList:
                inputVars = {}
                for neededVarName in neededVars:
                    defaultValue, isIndividual = neededVars[neededVarName]
                    inputVars[neededVarName] = getVariable(
                        context, cur, neededVarName, isIndividual,
                        defaultValue)
                intercepted = func(bot, context, msg, state, individualState,
                                   inputVars, updateVars)
                if intercepted:
                    everIntercepted = True
                    break

    if everIntercepted:
        for updateVarName in updateVars:
            value, isIndividual = updateVars[updateVarName]
            setVariable(context, cur, updateVarName, isIndividual, value)


bot.run(host='172.17.0.1', port=8081)
Exemple #12
0
        # 下面这句等价于 bot.send_private_msg(user_id=context['user_id'], message='你好呀,下面一条是你刚刚发的:')
        words = words_conform(context['message'])
        judge = words.getword()
        print(judge)
        # if '天气' in context['message']:
        #     viplocation=re.findall(r'(.*?)天气',context['message'])[0]
        #     wea = alone_response(viplocation)
        #
        #     try:
        #         bot.send(context,f'你正在查询{viplocation}天气')
        #     except Error:
        #         pass
        # return {'reply': context['message'],
        #         'at_sender': False}  # 返回给 HTTP API 插件,走快速回复途径

    bot.run(host='127.0.0.1', port=3031)

    raise Exception('pause')

    while True:
        nowtime = time.localtime().tm_hour
        if nowtime == 21 or nowtime == 6:
            warn_hours = 10
        else:
            warn_hours = 1
        userlist_c = [1225753951]
        userlist_d = [2792457328]
        s = Weather(location='上海奉贤', userlist=userlist_d)
        j = Weather(location='河南济源', userlist=userlist_d)
        b = Weather(location='北京海淀', userlist=userlist_c)
        if nowtime == 6:
Exemple #13
0
class ListenGroup(QThread):
    def __init__(self):
        super(QThread, self).__init__()
        self.pref5 = Preferences()
        self.api_root_url = 'http://127.0.0.1:%s/' % self.pref5.getapi_root_port(
        )
        self.post_port = int(self.pref5.getpost_url_port())
        self.bot = CQHttp(api_root=self.api_root_url)

    def run(self):
        @self.bot.on_message('group')
        def handle_msg(context):
            if context['group_id'] in self.pref5.getqqidarray(
            ) and context['user_id'] != context['self_id']:
                # 关键词禁言
                if self.pref5.getshutwordslist():
                    for word in self.pref5.getshutwordslist():
                        if word in context['message']:
                            self.bot.set_group_ban(
                                group_id=context['group_id'],
                                user_id=context['user_id'],
                                duration=30 * 60)
                # 关键词回复
                if context['message'] == '集资' or context[
                        'message'] == 'jz' or context[
                            'message'] == '打卡' or context['message'] == 'dk':
                    jz = ''
                    jz_array = md_init(self.pref5.getproidarray())
                    for jz_dict in jz_array:
                        jz += jz_dict['name'] + '\n' + jz_dict[
                            'url_short'] + '\n'
                    self.bot.send(context, jz)
                elif context['message'] == 'wds20' or context[
                        'message'] == 'jz20' or context[
                            'message'] == 'rank' or context[
                                'message'] == '聚聚榜' or context[
                                    'message'] == 'jzb' or context[
                                        'message'] == '集资榜':
                    rank1_array = rank(1)
                    for rank1_msg in rank1_array:
                        self.bot.send(context, rank1_msg)
                elif context['message'] == 'dkb' or context[
                        'message'] == '打卡榜' or context[
                            'message'] == 'dk20' or context[
                                'message'] == 'dakabang':
                    rank2_array = rank(2)
                    for rank2_msg in rank2_array:
                        self.bot.send(context, rank2_msg)
                elif "独占" in context['message']:
                    dz = ''
                    dz_array = md_init(self.pref5.getproidarray())
                    for dz_dict in dz_array:
                        dz += dz_dict['name'] + '\n' + dz_dict[
                            'url_short'] + '\n'
                    duzhan = "独占请集资" + '\n' + dz
                    self.bot.send(context, duzhan)
                elif context['message'] == '欢迎新人':
                    self.bot.send(context, self.pref5.getwelcome())
                elif context['message'] == '项目进度' or context['message'] == '进度':
                    jd_array = result(self.pref5.getproidarray())
                    jd = ''
                    for jd_msg in jd_array:
                        jd += jd_msg + '\n'
                    self.bot.send(context, jd)

        # 新人加群提醒
        @self.bot.on_event('group_increase')
        def handle_group_increase(context):
            if context['group_id'] == self.pref5.getqqidarray[0]:
                # ret = bot.get_stranger_info(user_id=context['user_id'], no_cache=False)
                # welcome = '欢迎新聚聚:@' + ret['nickname'] + ' 加入本群\n\n' + setting.welcome()
                welcome = [{
                    'type': 'text',
                    'data': {
                        'text': '欢迎新聚聚:'
                    }
                }, {
                    'type': 'at',
                    'data': {
                        'qq': str(context['user_id'])
                    }
                }, {
                    'type': 'text',
                    'data': {
                        'text': ' 加入本群\n\n%s' % self.pref5.getwelcome()
                    }
                }]
                self.bot.send(context, message=welcome, is_raw=True)  # 发送欢迎新人

        # 如果修改了端口,请修改http-API插件的配置文件中对应的post_url
        self.bot.run(host='127.0.0.1', port=self.post_port)
Exemple #14
0
@bot.on_request()
def handle_request(context):
    t2 = threading.Thread(target=bot_req.ReqCenter, args=(bot, context))
    t2.start()


# bp监视定时任务
max_count = 5000
sched_t1 = threading.Thread(target=bot_job.bpCareCenter, args=(bot, max_count))
sched_t1.setDaemon(True)
sched_t1.start()

# 踢人定时任务
sched_t2 = threading.Thread(target=bot_job.killCenter, args=(bot, ))
sched_t2.setDaemon(True)
sched_t2.start()

# pp超限踢人定时任务
sched_t3 = threading.Thread(target=bot_job.checkOutCenter, args=(bot, ))
sched_t3.setDaemon(True)
sched_t3.start()

# 记录清除定时任务
sched_t4 = threading.Thread(target=bot_job.cleanCenter, args=(bot, ))
sched_t4.setDaemon(True)
sched_t4.start()

# 监听启动
bot.run(host='127.0.0.1', port=8912)
Exemple #15
0

@bot.on_message("group")  #此处参数为上报数据的message_type,若不填将接受所有信息
def handle_msg(con):
    #bot.send(context, '你好呀,下面一条是你刚刚发的:')
    #bot.send_private_msg(user_id=con["user_id"],message="[CQ:at,qq="+str(con["user_id"])+"]")
    #@人的CQ码
    #bot.send_group_msg(group_id=con["group_id"],message="[CQ:at,qq="+str(con["user_id"])+"] 我好帮你点了,@你一直不回,麻烦回一下")
    if (con["group_id"] in group):  #在要发送的群内
        if (mNum[con["group_id"]] > random.randint(MIN, MAX)  #需要隔几条信息
                and time.time() - lastTime[con["group_id"]] > dur  #需要间隔一定秒数
            ):
            #先更新信息条数和时间,减少多线程问题
            mNum[con["group_id"]] = 0
            lastTime[con["group_id"]] = time.time()
            try:
                bot.send_group_msg(group_id=con["group_id"],
                                   message=info + "[CQ:face,id=" +
                                   str(random.randint(0, 170)) + "]")
            except Error as e:
                if (e.retcode == -34):
                    print("群" + str(con["group_id"]) + "发送失败,已被T或被禁言")
                    group.remove(con["group_id"])  #除去已经不能发言的群
            else:
                print("已向群" + str(con["group_id"]) + "推送")
        else:
            mNum[con["group_id"]] += 1  #接收到的信息加一


bot.run(host='127.0.0.1', port=revP)  #监听端口要改
Exemple #16
0
        result = now_can_get(event, message)
        if result != None:
            bot.send(event, result)
            return
        result = today_can_get(event, message)
        if result != None:
            bot.send(event, result)
            return
        result = search_wiki(event, message)
        if result != None:
            bot.send(event, result)
            return

    except Exception as e:
        bot.send(event, '出错: ' + repr(e))


@bot.on_notice('group_increase')  # 如果插件版本是 3.x,这里需要使用 @bot.on_event
def handle_group_increase(event):
    bot.send(event,
             message='欢迎新人,群名片请改成系统用户名+角色名+岛屿,祝您无人岛移居愉快',
             auto_escape=True)  # 发送欢迎新人


@bot.on_request('group', 'friend')
def handle_request(event):
    return {'approve': True}  # 同意所有加群、加好友请求


bot.run(host='0.0.0.0', port=7777)