Example #1
0
def send_message(message_list: list):
    """向配置文件当中指定的群群发消息"""
    for message in message_list:
        for grp_id in setting.group_id():
            bot.send_group_msg_async(group_id=grp_id,
                                     message=message,
                                     auto_escape=False)
            time.sleep(0.5)
Example #2
0
def send_pk_message(pk_data):
    """发送PK数据信息"""
    message = fund.pk.get_pk_message(pk_data)
    send_groups = setting.group_id() + pk_data['extend_qq_groups']
    for grp_id in send_groups:
        bot.send_group_msg_async(group_id=grp_id,
                                 message=message,
                                 auto_escape=False)
        time.sleep(0.5)
Example #3
0
def handle_group_increase(context):
    """加群发送欢迎消息"""
    if context['group_id'] in setting.group_id():
        welcome = [{
            'type': 'text',
            'data': {
                'text': '欢迎'
            }
        }, {
            'type': 'at',
            'data': {
                'qq': str(context['user_id'])
            }
        }, {
            'type': 'text',
            'data': {
                'text': f'加入本群\n{setting.welcome()}'
            }
        }]
        bot.send(context, message=welcome, auto_escape=True)
Example #4
0
def handle_msg(context):
    """关键字响应\n
    目前设定了PK, 集资, 补档, 以及关键字撤回和重复刷屏禁言.
    """
    if (context['user_id'] != context['self_id']
            and context['message_type'] == 'group'):
        check_group_list = setting.group_id() + setting.dev_group_id()
        for pk_data in setting.pk_datas():
            if time.mktime(
                    time.strptime(pk_data['end_time'],
                                  '%Y-%m-%d %H:%M:%S')) < time.time():
                continue
            if (context['group_id'] in pk_data['extend_qq_groups']
                    or context['group_id'] in check_group_list):
                if (context['message'] in ['PK', 'pk', 'Pk']
                        or context['message'] in pk_data['key_word']):
                    message = fund.pk.get_pk_message(pk_data)
                    bot.send(context, message)
        if (context['group_id'] in setting.group_id()
                or context['group_id'] in setting.dev_group_id()):
            if context['message'] == '集资':
                session = sessionmaker(bind=engine)()
                message = ''
                project_list = fund.get_started_project(session)
                if project_list.count() > 0:
                    for project in project_list:
                        message += f'{project.title}(准备中):{project.link()}\n'
                project_list = fund.get_prepared_project(session)
                if project_list.count() > 0:
                    for project in project_list:
                        message += f'{project.title}(准备中):{project.link()}\n'
                if message == '':
                    message = '暂时没有集资项目'
                session.close()
                bot.send(context, message.rstrip('\n'))
            if context['message'] == '补档':
                intro_pos = setting.read_config('system', 'intro')
                f = open(intro_pos, 'r', -1, 'utf-8')
                ori_message = f.read()
                message_list = ori_message.split('$')
                for message in message_list:
                    bot.send(context, message)
        # 敏感词撤回与重复刷屏禁言
        if context['group_id'] in setting.group_id():
            for word in setting.shutword():
                if word in context['message']:
                    bot.delete_msg(message_id=context['message_id'])
                    logger.info('成员%s的消息%s因为含有敏感词%s被撤回', context['user_id'],
                                context['message'], word)
            prev_message = repeat_message[context['group_id']]['message']
            prev_user = repeat_message[context['group_id']]['user_id']
            if (context['message'] == prev_message
                    and context['user_id'] == prev_user):
                repeat_message[context['group_id']]['time'] += 1
                logger.debug('成员%s重复发言第%d次', context['user_id'],
                             repeat_message[context['group_id']]['time'])
            else:
                repeat_message[context['group_id']]['time'] = 0
            repeat_message[context['group_id']]['message'] = context['message']
            repeat_message[context['group_id']]['user_id'] = context['user_id']
            if repeat_message[context['group_id']]['time'] >= 4:
                bot.set_group_ban(group_id=context['group_id'],
                                  user_id=context['user_id'],
                                  duration=60 * 60)
                logger.info('成员%s因为重复发言刷屏被禁言一小时', context['user_id'])
Example #5
0
import fund.pk
import pocket48
import setting
import weibo

logger = logging.getLogger('QQBot')
bot = CQHttp(api_root='http://127.0.0.1:5700/')
sched = BackgroundScheduler()
engine = create_engine(setting.db_link())
global pk_mission_started
global repeat_message
# 列表中保存的是已经完成初始化的PK项目
pk_mission_started = list()
# 重复刷屏禁言的准备
repeat_message = dict()
for thisGrpID in setting.group_id():
    properties = ['message', 'user_id', 'times']
    repeat_message[thisGrpID] = {info: '' for info in properties}


def send_message(message_list: list):
    """向配置文件当中指定的群群发消息"""
    for message in message_list:
        for grp_id in setting.group_id():
            bot.send_group_msg_async(group_id=grp_id,
                                     message=message,
                                     auto_escape=False)
            time.sleep(0.5)


# 发送集资信息