Пример #1
0
async def al_query_coordinate(key_name):
    '''
    # 根据船名找地图
    '''
    resultlist = sql_read("User.db",
                          "ship_map",
                          "Currentname",
                          "*{}*".format(key_name),
                          link="GLOB")
    if not resultlist:
        resultlist = sql_read("User.db",
                              "ship_map",
                              "Usedname",
                              "*{}*".format(key_name),
                              link="GLOB")
    if resultlist:
        output = ""
        for name in resultlist:
            output += "\n原名:{0[0]}\t和谐名:{0[1]}\t可在以下地点打捞\n".format(name)
            for i, j in enumerate(name[2:], 2):
                if j:
                    output += MapID[i] + "\t"
    else:
        output = "该船名未收录或无法打捞"
    return output
Пример #2
0
async def _():

    bot = nonebot.get_bot()
    # await bot.send_group_msg(group_id=580695689, message='测试执行')
    try:
        group_list = sql_read("User.db",
                              "group_info",
                              "Call_bell_AZ",
                              1.0,
                              field="group_id",
                              in_where=True)
        if group_list:
            time_line = line()
            for group_id in group_list:
                await bot.send_group_msg(group_id=group_id[0],
                                         message=time_line)

        group_list = sql_read("User.db",
                              "group_info",
                              "Call_bell",
                              1.0,
                              field="group_id",
                              in_where=True)
        if group_list:
            now_time = time.strftime('%H', time.localtime(time.time()))
            for group_id in group_list:
                await bot.send_group_msg(group_id=group_id[0],
                                         message='现在{}点咯!'.format(now_time))
    except CQHttpError:
        pass
Пример #3
0
async def _():
    bot = nonebot.get_bot()
    now = datetime.now(pytz.timezone('Asia/Shanghai'))

    # 火星时报
    group_list = sql_read("User.db",
                          "group_info",
                          "Sara_news",
                          1.0,
                          field="group_id",
                          in_where=True)
    if group_list:
        update_info = update_check('233114659')
        if update_info[0]:
            for group_id in group_list:
                try:
                    await bot.send_group_msg(group_id=group_id[0],
                                             message=update_info[1])
                except CQHttpError as err:
                    await notice(bot, group_id[0], err)

    # 标枪快讯
    group_list = sql_read("User.db",
                          "group_info",
                          "Javelin_news",
                          1.0,
                          field="group_id",
                          in_where=True)
    if group_list:
        update_info = update_check('300123440')
        if update_info[0]:
            #update_info = "{}\n————————\n百度机翻如下:\n\n{}".format(update_info[1], render(update_info[1]))
            for group_id in group_list:
                try:
                    await bot.send_group_msg(group_id=group_id[0],
                                             message=update_info[1])
                except CQHttpError as err:
                    await notice(bot, group_id[0], err)

    # 罗德岛线报
    group_list = sql_read("User.db",
                          "group_info",
                          "Arknights",
                          1.0,
                          field="group_id",
                          in_where=True)
    if group_list:
        update_info = update_check('161775300')
        if update_info[0]:
            for group_id in group_list:
                try:
                    await bot.send_group_msg(group_id=group_id[0],
                                             message=update_info[1])
                except CQHttpError as err:
                    await notice(bot, group_id[0], err)
Пример #4
0
async def training(Question, Answer, Qid, only_to_me=False):

    if only_to_me:
        score = sql_read(
            "plugins/icarus/data.db",
            "favor_score",
            'ID',
            Qid,
            'score',
        )[0][0]
        if score >= 700:
            max_index = 3
        elif score >= 300:
            max_index = 2
        elif score >= 100:
            max_index = 1
        else:
            return "哈?!只对你说,你想得美\n(#‘д´)ノ\n[好感度不足]"

        current_index, end_index = sql_read("plugins/icarus/data.db",
                                            "dedicated_corpus", 'ID', Qid,
                                            'current, end')[0]
        if max_index > current_index:  # 可用槽数大于已用槽数
            r_index = current_index
            current_index += 1  # 已用槽数 +1
            sql_rewrite("plugins/icarus/data.db", 'dedicated_corpus', "ID",
                        Qid, "current", current_index)  # 更新已用槽记录
            response = "嗯嗯,我只和你说哦的\nヾ(^▽^*)))"
        elif max_index <= current_index:  # 可用槽数小于或等于已用槽数
            r_index = end_index
            end_index = 0 if end_index + 2 > max_index else end_index + 1  # 最旧槽更新为可用槽中最旧的
            sql_rewrite("plugins/icarus/data.db", 'dedicated_corpus', "ID",
                        Qid, "current", max_index)  # 更新已用槽为可用槽
            sql_rewrite("plugins/icarus/data.db", 'dedicated_corpus', "ID",
                        Qid, "end", end_index)  # 更新最旧槽记录
            response = "我只能记住最后{}条只给你的回答,之前的都忘光光惹\n ≧ ﹏ ≦".format(max_index)
        sql_rewrite("plugins/icarus/data.db", 'dedicated_corpus', "ID", Qid,
                    "question{}".format(r_index), Question)
        sql_rewrite("plugins/icarus/data.db", 'dedicated_corpus', "ID", Qid,
                    "answer{}".format(r_index), Answer)

    else:
        data = (Answer, Question, Keyword_extraction(Question, 1)[0])
        sql_write("plugins/icarus/data.db", "universal_corpus", data)
        points(Qid, flag=True)
        response = random.choice(
            ("伊卡洛斯记住了你的话,因为你的认真教导,好感度上升了", "伊卡洛斯记住了你的话,你教学的时候太严厉了,好感度下降了",
             "这样的吗,我大概记住了\nฅ( ̳• ◡ • ̳)ฅ", "伊卡洛斯喜欢学习\nヾ(◍°∇°◍)ノ゙",
             "虽然不太懂,但是伊卡洛斯还是把你教的知识记在了心里"))
    return response
Пример #5
0
async def _():
    bot = nonebot.get_bot()
    # await bot.send_group_msg(group_id=580695689, message='测试执行')
    try:
        group_list = sql_read("User.db",
                              "group_info",
                              "Daily_remind_AzurLane",
                              1.0,
                              field="group_id",
                              in_where=True)
        if group_list:
            week = time.localtime(time.time()).tm_wday
            if week > 2:
                week -= 3
                flag = False
            else:
                flag = True

            for group_id in group_list:
                await bot.send_group_msg(
                    group_id=group_id[0],
                    message=REMIND_TEXT["AzurLane"][week].format(
                        REMIND_TEXT["ZH_CODE"][week][flag]))
    except CQHttpError:
        pass
Пример #6
0
def update_check(uid):
    """
    # 检测B博是否更新
    """
    update_data = crawler.get_trend(uid, flag=False)  # 获取动态信息
    update_time = date_box.sql_read("User.db",
                                    "Crawler_update_time",
                                    "update_url",
                                    uid,
                                    field="update_time")[0]  # 获取历史时间戳
    if update_data["code"] == 0:  # 正常状况
        posted_time = update_data["posted_time"]
        if posted_time > update_time[0]:  # 对比时间戳
            text_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                      time.localtime(posted_time))  # 时间戳格式化
            date_box.sql_rewrite("User.db", "Crawler_update_time",
                                 "update_url", uid, "update_time",
                                 str(posted_time))  # 更新历史时间戳

            img_url = update_data.get("img", "")
            main_body = update_data.get("main_body", "")
            sign = update_data.get("sign", "")

            echo = """最新动态:\n{}\n{}\n{} 于 {} 发布至 BiliBili 动态
详情请访问:https://space.bilibili.com/{}/dynamic""".format(main_body, img_url, sign,
                                                      text_time, uid)  # 发表最新动态
            return True, echo
        return False, None
    elif update_data["code"] == 1:  # 连续三次错误返回
        return False, "本周期尝试获取动态信息失败超过三次,等待下一更新周期"
    else:  # 其他状况
        return False, "错误码尚未定义"
Пример #7
0
async def _(session: NoticeSession):
    # 发送欢迎消息
    if sql_read("User.db",
                "group_info",
                "group_id",
                session.ctx["group_id"],
                field="New_add",
                in_where=True)[0][0]:
        await session.send(render_expression(EXL))
Пример #8
0
async def ai(user_input, Qid):
    keys = Keyword_extraction(user_input)

    text = points(Qid)

    max_ratio = 0
    response = []

    dedicated_corpus = sql_read("plugins/icarus/data.db", "dedicated_corpus",
                                'ID', Qid)[0]

    if dedicated_corpus and dedicated_corpus[7]:
        corpus = []
        for i in range(1, dedicated_corpus[7] + 1):
            corpus.append((dedicated_corpus[i + 3], dedicated_corpus[i]))
        max_ratio, response = selection(corpus, max_ratio, response,
                                        user_input)

        if max_ratio >= 0.7:
            return random.choice(response), text

    for i in keys:
        dedicated_corpus = sql_read("plugins/icarus/data.db",
                                    "universal_corpus", 'keys', i)
        max_ratio, response = selection(dedicated_corpus, max_ratio, response,
                                        user_input)

        if max_ratio >= 0.5:
            return random.choice(response), text

    for i in keys:
        dedicated_corpus = sql_read("plugins/icarus/data.db",
                                    "universal_corpus",
                                    'question',
                                    '%{}%'.format(i[1]),
                                    link="LIKE")
        max_ratio, response = selection(dedicated_corpus, max_ratio, response,
                                        user_input)

        if max_ratio >= 0.5:
            return random.choice(response), text

    response = "你在说什么,我怎么听不懂\n(○´・д・)ノ"
    return response, text
Пример #9
0
async def code_name(name):
    """
    # 重樱船名对应表
    # 以名字或代号为索引对应代号或名字
    # 参数:
    # name*    索引
    # 返回格式(str):
    # "name":"name"
    """
    result = sql_read("User.db", "Roster", "name", name)
    if not result:
        result = sql_read("User.db", "Roster", "code", name)
    try:
        result = list(result[0])
    except IndexError:
        toname = (False, )
    else:
        toname = (True, "和谐名:{0[0]}\t原名:{0[1]}".format(result))
    return toname
Пример #10
0
async def send_to_group(session: CommandSession):
    stripped_arg = session.current_arg_text.strip()
    if stripped_arg:
        stripped_arg_list = stripped_arg.split(" ", 1)
        if stripped_arg_list[0].startswith("#"):
            to = int(
                sql_read("User.db", "group_info", "id",
                         stripped_arg_list[0].lstrip("#"))[0][1])
        else:
            to = int(stripped_arg_list[0])
        info = stripped_arg_list[1]
        bot = get_bot()
        await bot.send_group_msg(group_id=to, message=info)
Пример #11
0
async def al_query_name(key_time):
    '''
    # 根据地图名找船
    '''
    result = sql_read("User.db", "ship_map", key_time, 1, "Usedname")
    if result:
        name_list = "\n在地图 %s 可以的打捞的舰船有:" % key_time
        result.sort(key=lambda elem: len(elem[0]))
        for name in result:
            name_list += "\n" + name[0]
    else:
        name_list = "没有找到地图 %s 的信息" % key_time
    return name_list
Пример #12
0
async def shipName(ship_id):

    if not ship_id:
        return "无"
    result = sql_read("User.db",
                      "wows_shipID",
                      "ShipID",
                      ship_id,
                      field="Name")
    if result:
        return result[0][0]
    else:
        return "未收录的ship_id:{}".format(ship_id)
Пример #13
0
async def _():
    bot = nonebot.get_bot()
    # await bot.send_group_msg(group_id=580695689, message='测试执行')
    try:
        group_list = sql_read("User.db",
                              "group_info",
                              "Daily_remind_FGO",
                              1.0,
                              field="group_id",
                              in_where=True)
        if group_list:
            week = time.localtime(time.time()).tm_wday  # 0-6 周一为 0
            for group_id in group_list:
                await bot.send_group_msg(group_id=group_id[0],
                                         message=REMIND_TEXT["FGO"][week])
    except CQHttpError:
        pass
Пример #14
0
def points(Qid, flag=False):
    score = sql_read(
        "plugins/icarus/data.db",
        "favor_score",
        'ID',
        Qid,
        'score',
    )
    if not score:
        sql_write("plugins/icarus/data.db", "favor_score", (Qid, 50))
        data = (Qid, "", "", "", "", "", "", 0, 0)
        sql_write("plugins/icarus/data.db", "dedicated_corpus", data)
        score = [(50, )]
    score = score[0][0]
    if flag:
        new_score = score + random.randint(5, 7)
    else:
        new_score = score + random.randint(-2, 3)
    sql_rewrite("plugins/icarus/data.db", 'favor_score', "ID", Qid, "score",
                new_score)
    if new_score >= 700:  # 爱
        if score < 700:  # 晋升
            return "伊卡洛斯想和你永远在一起\n使用命令 ”只对我说“ + 空格 + 对话问题#回答内容,可以设置一项专属回答\n示范:只对我说 还记得我们的约定吗#我会永远记得的"
    elif new_score >= 300:  # 喜欢
        if score < 300:  # 晋升
            return "伊卡洛斯喜欢和你聊天\n使用命令 ”只对我说“ + 空格 + 对话问题#回答内容,可以设置一项专属回答\n示范:只对我说 还记得我们的约定吗#我会永远记得的"
        elif score >= 700:  # 降级
            return "伊卡洛斯觉得还不够了解你"
    elif new_score >= 100:  # 熟悉
        if score < 100:  # 晋升
            return "伊卡洛斯愿意了解你了\n使用命令 ”只对我说“ + 空格 + 对话问题#回答内容,可以设置一项专属回答\n示范:只对我说 还记得我们的约定吗#我会永远记得的"
        elif score >= 300:  # 降级
            return "伊卡洛斯不再喜欢你了"
    elif new_score >= 0:  # 陌生
        if score < 0:  # 晋升
            return "伊卡洛斯不再讨厌你了"
        elif score >= 100:  # 降级
            return "伊卡洛斯开始疏远你了"
    else:  # 讨厌
        if score >= 0:  # 降级
            return "伊卡洛斯开始讨厌你了"
    return ""
Пример #15
0
async def shipID(ship_name):
    """
    # 以名字为索引,查询ID
    # 参数:
    # ship_name*    索引名
    # 返回格式(str):
    # "name"
    """
    if not ship_name:
        return "无"

    resultlist = sql_read("User.db",
                          "wows_shipID",
                          "Name",
                          "*{}*".format(ship_name),
                          field="ShipID",
                          link="GLOB")
    if resultlist:
        output = ''
        for result in resultlist:
            output += "{},".format(result[0])
        return output, True
    else:
        return "未收录此船名", False
Пример #16
0
async def get_repeat(session: CommandSession, text: str) -> Optional[str]:
    # 查询数据库
    if not text:
        return None
    switch = sql_read("User.db",
                      "group_info",
                      "group_id",
                      session.ctx["group_id"],
                      field="repeat",
                      in_where=True)  # 权限管理器
    if not switch:  # 如果没有这个群的配置记录,则添加一条,默认全部为False
        sql_write("User.db", "group_info (id, group_id)",
                  '(Null, {})'.format(session.ctx["group_id"]))
    elif not switch[0][0]:  # 如果配置记录为关闭,则退出
        pass
    else:
        try:
            old_info, flag, user, old_user = sql_read(
                "User.db", "repeat_info", "groupid",
                session.ctx["group_id"])[0][:4]
        except IndexError:
            # 初步判定为未添加复读
            sql_write("User.db", "repeat_info",
                      '("", 0, Null, Null,{})'.format(session.ctx["group_id"]))
        else:
            if old_info == text:
                if flag > 1 or flag == 0:
                    text = False
                flag += 1
                # 更改数据库
                sql_rewrite("User.db", "repeat_info", "groupid",
                            session.ctx["group_id"], "flag", flag)  # 复读次数
                sql_rewrite("User.db", "repeat_info", "groupid",
                            session.ctx["group_id"], "old_userid",
                            user)  # 更迭在位者id
                sql_rewrite("User.db", "repeat_info", "groupid",
                            session.ctx["group_id"], "userid",
                            session.ctx["user_id"])  # 记录继位者id
                await session.finish(text)
            else:
                if flag >= 2 and False:
                    bot = session.bot
                    try:
                        # 禁言在位者
                        await bot.set_group_ban(
                            group_id=session.ctx['group_id'],
                            user_id=old_user,
                            duration=flag * 120)
                        if old_user != session.ctx['user_id']:  #判断是否自己打断自己
                            # 禁言篡位者
                            await bot.set_group_ban(
                                group_id=session.ctx['group_id'],
                                user_id=session.ctx['user_id'],
                                duration=flag * 100)
                    except:
                        await session.send("执行异常,请检查权限,参数")
                # 更改数据库
                sql_rewrite("User.db", "repeat_info", "groupid",
                            session.ctx["group_id"], "flag", 0)  # 清空次数
                sql_rewrite("User.db", "repeat_info", "groupid",
                            session.ctx["group_id"], "info", text)  # 更新文本
                sql_rewrite("User.db", "repeat_info", "groupid",
                            session.ctx["group_id"], "old_userid",
                            "")  # 清空在位者id
                sql_rewrite("User.db", "repeat_info", "groupid",
                            session.ctx["group_id"], "userid", "")  # 清空继位者id
    return None
async def change_everything(session, field, renturn_id=False):
    """
    # 功能            字段名
    #------------------------
    # 复读姬                repeat
    # 开火权限              fire
    # 火星时报              Sara_news
    # 标枪快讯              Javelin_news
    # 报时                 Call_bell
    # 报时_舰C             Call_bell_AZ
    # 迎新                 New_add
    # 每日提醒_AzurLane     Daily_remind_AzurLane
    # 每日提醒_FGO          Daily_remind_FGO
    # 明日方舟              Arknights
    """
    bot = get_bot()
    stripped_arg = session.current_arg_text.strip() if await check_permission(
        bot, session.ctx, SUPERUSER) else False

    if stripped_arg:
        if stripped_arg.startswith("#"):
            intent = sql_read("User.db",
                              "group_info",
                              "id",
                              stripped_arg.lstrip("#"),
                              field=field,
                              in_where=True)[0][0]
            sql_rewrite("User.db", "group_info", "id",
                        stripped_arg.lstrip("#"), field, int(not intent))
            echo = sql_read("User.db",
                            "group_info",
                            "id",
                            stripped_arg.lstrip("#"),
                            field=field,
                            in_where=True)[0][0]
            if renturn_id:
                group_id = sql_read("User.db",
                                    "group_info",
                                    "id",
                                    stripped_arg.lstrip("#"),
                                    field="group_id",
                                    in_where=True)[0][0]
                return not not intent, not not echo, group_id
            return not not intent, not not echo
        else:
            group_id = stripped_arg
    else:
        group_id = session.ctx["group_id"]
    intent = sql_read("User.db",
                      "group_info",
                      "group_id",
                      group_id,
                      field=field,
                      in_where=True)[0][0]
    sql_rewrite("User.db", "group_info", "group_id", group_id, field,
                int(not intent))
    echo = sql_read("User.db",
                    "group_info",
                    "group_id",
                    group_id,
                    field=field,
                    in_where=True)[0][0]
    if renturn_id:
        return not not intent, not not echo, group_id

    return not not intent, not not echo