Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions astrbot/core/platform/astrbot_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,29 @@ def __str__(self) -> str:


class AstrBotMessage:
"""AstrBot 的消息对象"""
"""Represents a message received from the platform, after parsing and normalization.
This is the main message object that will be passed to plugins and handlers."""

type: MessageType # 消息类型
self_id: str # 机器人的识别id
session_id: str # 会话id。取决于 unique_session 的设置。
message_id: str # 消息id
group: Group | None # 群组
sender: MessageMember # 发送者
message: list[BaseMessageComponent] # 消息链使用 Nakuru 的消息链格式
message_str: str # 最直观的纯文本消息字符串
type: MessageType
"""GroupMessage, FriendMessage, etc"""
self_id: str
"""Bot's ID"""
session_id: str
"""Session ID, which is the last part of UMO"""
message_id: str
"""Message ID"""
group: Group | None
"""The group info, None if it's a friend message"""
sender: MessageMember
"""The sender info"""
message: list[BaseMessageComponent]
"""Sorted list of message components after parsing"""
message_str: str
"""The parsed message text after parsing, without any formatting or special components"""
raw_message: object
timestamp: int # 消息时间戳
"""The raw message object, the specific type depends on the platform"""
timestamp: int
"""The timestamp when the message is received, in seconds"""

def __init__(self) -> None:
self.timestamp = int(time.time())
Expand All @@ -70,16 +81,12 @@ def __str__(self) -> str:

@property
def group_id(self) -> str:
"""向后兼容的 group_id 属性
群组id,如果为私聊,则为空
"""
if self.group:
return self.group.group_id
return ""

@group_id.setter
def group_id(self, value: str | None) -> None:
"""设置 group_id"""
if value:
if self.group:
self.group.group_id = value
Expand Down
213 changes: 213 additions & 0 deletions dashboard/src/components/config/ConfigProfileSidebar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
<template>
<div class="config-profile-sidebar">
<div class="d-flex align-center justify-space-between mb-3">
<h3 class="text-subtitle-1 font-weight-bold mb-0">
<v-icon size="18" class="mr-1">mdi-format-list-bulleted-square</v-icon>
{{ tm('profileSidebar.title') }}
</h3>
<v-tooltip :text="tm('configManagement.manageConfigs')" location="top">
<template #activator="{ props: tooltipProps }">
<v-btn v-bind="tooltipProps" size="small" variant="text" icon="mdi-cog" :disabled="disabled"
@click="emit('manage')" />
</template>
</v-tooltip>
</div>

<div class="config-profile-list">
<v-card v-for="config in configs" :key="config.id" class="profile-card" :class="{
'profile-card--active': config.id === selectedConfigId,
'profile-card--disabled': disabled
}" variant="outlined" @click="onSelect(config.id)">
<div class="profile-card__name text-h4 d-flex align-center">
<v-icon size="24" class="mr-2">mdi-file-outline</v-icon>
{{ config.name }}
</div>
<div class="mt-3 d-flex" style="align-items: start; justify-content: center;">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better code organization and adherence to best practices, it's recommended to avoid inline styles. Please move the styling for this div into a dedicated CSS class in the <style> block. This improves maintainability and separates concerns. You can then add the corresponding styles to a new .profile-card__routes class in the <style> block.

        <div class="mt-3 d-flex profile-card__routes">

<v-icon size="24" class="mr-1">mdi-routes</v-icon>
<div class="profile-card__bindings">
<template v-if="bindingsForConfig(config.id).length > 0">
<v-tooltip v-for="binding in visibleBindings(bindingsForConfig(config.id))"
:key="`${config.id}-${binding.platformId}`" location="top">
<template #activator="{ props: tooltipProps }">
<button v-bind="tooltipProps" type="button" class="binding-pill"
@click.stop="onManageRoutes(config.id)">
<v-avatar size="22" class="binding-avatar" rounded="sm">
<img v-if="getBindingIcon(binding)" :src="getBindingIcon(binding)" :alt="binding.platformId"
class="binding-avatar__img" />
<v-icon v-else size="14">mdi-robot-outline</v-icon>
</v-avatar>
<span class="binding-pill__label">
{{ binding.platformId }}
</span>
</button>
</template>
<div class="binding-tooltip-content">
<div class="text-caption font-weight-bold mb-1">
{{ tm('profileSidebar.platformId') }}: {{ binding.platformId }}
</div>
<div class="text-caption mb-1">
{{ tm('profileSidebar.umop') }}:
</div>
<div v-for="umop in binding.umops" :key="`${binding.platformId}-${umop}`" class="text-caption">
{{ umop }}
</div>
</div>
</v-tooltip>
<v-chip v-if="bindingsForConfig(config.id).length > maxVisibleBindings" size="x-small" variant="tonal"
color="primary">
+{{ bindingsForConfig(config.id).length - maxVisibleBindings }}
</v-chip>
</template>
<span v-else class="text-caption text-medium-emphasis">
{{ tm('profileSidebar.noBindings') }}
</span>
</div>

</div>
</v-card>
</div>
</div>
</template>

<script setup lang="ts">
import { useModuleI18n } from '@/i18n/composables';
import { getPlatformIcon } from '@/utils/platformUtils';

interface ConfigInfo {
id: string;
name: string;
}

interface ConfigBinding {
platformId: string;
platformType?: string;
umops: string[];
}

const props = withDefaults(defineProps<{
configs: ConfigInfo[];
selectedConfigId: string | null;
bindingsByConfigId: Record<string, ConfigBinding[]>;
disabled?: boolean;
}>(), {
selectedConfigId: null,
bindingsByConfigId: () => ({}),
disabled: false
});

const emit = defineEmits<{
select: [configId: string];
manage: [];
manageRoutes: [payload: { configId: string }];
}>();

const { tm } = useModuleI18n('features/config');

const maxVisibleBindings = 6;

function onSelect(configId: string): void {
if (props.disabled) {
return;
}
emit('select', configId);
}

function onManageRoutes(configId: string): void {
if (props.disabled) {
return;
}
emit('manageRoutes', { configId });
}

function bindingsForConfig(configId: string): ConfigBinding[] {
return props.bindingsByConfigId[configId] || [];
}

function visibleBindings(bindings: ConfigBinding[]): ConfigBinding[] {
return bindings.slice(0, maxVisibleBindings);
}

function getBindingIcon(binding: ConfigBinding): string | undefined {
if (binding.platformType) {
return getPlatformIcon(binding.platformType);
}
return getPlatformIcon(binding.platformId);
}
</script>

<style scoped>
.config-profile-list {
display: flex;
flex-direction: column;
gap: 12px;
max-height: calc(100vh - 210px);
overflow-y: auto;
padding-right: 4px;
}

.profile-card {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
border-radius: 12px;
cursor: pointer;
padding: 12px;
transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}


.profile-card--active {
background: rgba(var(--v-theme-primary), 0.08);
}

.profile-card--disabled {
cursor: not-allowed;
opacity: 0.7;
}

.profile-card__name {
line-height: 1.3;
}

.profile-card__bindings {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 6px;
min-height: 28px;
}

.binding-pill {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 2px 8px 2px 4px;
border-radius: 999px;
border: 1px solid rgba(var(--v-theme-on-surface), 0.14);
background: rgba(var(--v-theme-surface), 1);
cursor: pointer;
transition: border-color 0.15s ease, background-color 0.15s ease;
}

.binding-pill:hover {
border-color: rgba(var(--v-theme-primary), 0.45);
background: rgba(var(--v-theme-primary), 0.06);
}

.binding-pill__label {
font-size: 0.78rem;
line-height: 1.1;
white-space: nowrap;
color: rgba(var(--v-theme-on-surface), 0.8);
}

.binding-avatar__img {
width: 100%;
height: 100%;
object-fit: contain;
padding: 2px;
}

.binding-tooltip-content {
max-width: 380px;
word-break: break-all;
}
</style>
Loading