Пример #1
0
    def text(
        obj_in: Union[schema.UserInfo, schema.UserBest30, schema.SongInfo,
                      schema.SongScore]
    ) -> MessageSegment:
        if isinstance(obj_in, schema.UserInfo):
            info_msg = '\n'.join(
                (f"name: {obj_in.name}", f"PTT: {obj_in.rating}"))
            recent = obj_in.recent_score
            recent_msg = '\n'.join(
                (f"最近游玩: {recent.song_id}", f"难度: {recent.difficulty}",
                 f"Score: {recent.score}", f"PTT: {recent.rating:.2f}",
                 f"大 P: {recent.shiny_perfect_count}",
                 f"小 P: {recent.perfect_count - recent.shiny_perfect_count}",
                 f"count P: {recent.perfect_count}",
                 f"count FAR: {recent.near_count}",
                 f"count MISS: {recent.miss_count}",
                 f"Time: {recent.time_played:%F %X}")) if recent else None
            msg = '\n'.join(
                [x for x in [info_msg, recent_msg] if isinstance(x, str)])
            return MessageSegment.text(msg)
        if isinstance(obj_in, schema.UserBest30):

            def songscore_msg_lambda(s: schema.SongScore) -> str:
                return '\n'.join(
                    (f"{s.song_id} {s.difficulty}", f"  Score: {s.score}",
                     f"  PTT: {s.rating:.2f}"))

            info_msg = '\n'.join((f"b30_avg: {obj_in.best30_avg}",
                                  f"r10_avg: {obj_in.recent10_avg}"))
            songs_msg = '\n'.join(f"{i + 1}: {val}" for i, val in enumerate(
                map(songscore_msg_lambda, obj_in.best30_list)))
            msg = '\n'.join((info_msg, songs_msg))
            return MessageSegment.text(msg)
        if isinstance(obj_in, schema.SongInfo):

            def songinfo_perlevel(s: schema.SongInfoPerLevel) -> str:
                return '\n'.join(
                    (f"- 难度: {s.ratingClass}",
                     f"  等级: {s.rating}{'+' if s.ratingPlus else ''}",
                     f"  定数: {s.ratingReal}", f"  物量: {s.totalNotes}"))

            info_msg = '\n'.join(
                (f"song_id: {obj_in.id}", f"artist: {obj_in.artist}",
                 f"bpm: {obj_in.bpm}", f"date: {obj_in.date:%F %X}"))
            levels_msg = '\n'.join(map(songinfo_perlevel, obj_in.difficulties))
            msg = '\n'.join((info_msg, levels_msg))
            return MessageSegment.text(msg)
        if isinstance(obj_in, schema.SongScore):
            songscore_msg = text_utils.songscore(obj_in)
            return MessageSegment.text(songscore_msg)
Пример #2
0
async def get_result(bot: Bot, event: Event, state: T_State):
    at = MessageSegment.at(event.get_user_id())
    if not state.get("content"):
        result = await get_help()
    elif str(state.get("content")).lower() == "list":
        plugin_set = nonebot.plugin.get_loaded_plugins()
        plugin_names = []
        for plugin in plugin_set:
            try:
                name = f'{plugin.name} | ' \
                    f'{plugin.module.__getattribute__("__help_plugin_name__")}'
            except:
                name = f'{plugin.name}'
            try:
                version = plugin.module.__getattribute__("__help_version__")
            except:
                version = ""
            plugin_names.append(f'{name} {version}')
        plugin_names.sort()
        newline_char = '\n'
        result = f'已加载插件:\n{newline_char.join(plugin_names)}'
    else:
        try:
            plugin = nonebot.plugin.get_plugin(state.get("content"))
        except AttributeError:
            plugin = None
        try:
            result = plugin.module.__getattribute__("__usage__")
        except:
            try:
                result = plugin.module.__doc__
            except AttributeError:
                result = f'{state.get("content")}插件不存在或未加载'
    await helper.finish(Message().append(at).append(
        MessageSegment.text(result)))
Пример #3
0
async def get_result(bot: Bot, event: Event, state: T_State):
    if state.get("content") in ('help', 'h'):
        at_user = MessageSegment.at(event.get_user_id())
        result = await get_help()
    else:
        at_user = MessageSegment.at(event.get_user_id())
        roll_result = await roll_dice(state.get("content"))
        result = MessageSegment.text(roll_result)
    await dice.finish(Message().append(at_user).append(result))
Пример #4
0
 def cqcode(self) -> MessageSegment:
     if salmon.configs.RES_PROTOCOL == 'http':
         return MessageSegment.image(self.url)
     elif salmon.configs.RES_PROTOCOL == 'file':
         return MessageSegment.image(
             f'file:///{os.path.abspath(self.path)}')
     else:
         try:
             return MessageSegment.image(util.pic2b64(self.open()))
         except Exception as e:
             salmon.logger.exception(e)
             return MessageSegment.text('[图片出错]')