From 8d354b44ada3725931a459a0957a67ad14fe7944 Mon Sep 17 00:00:00 2001
From: arvinxx
Date: Sun, 3 Sep 2023 18:03:13 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20feat:=20=E5=AE=8C=E5=96=84?=
=?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=BC=80=E5=8F=91=E6=A8=A1=E6=9D=BF=E7=9A=84?=
=?UTF-8?q?=E5=9F=BA=E7=A1=80=E5=86=85=E5=AE=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.dumirc.ts | 47 -----------
.fatherrc.ts | 19 -----
.prettierignore | 1 -
README.md | 2 +-
package.json | 9 +-
public/manifest-dev.json | 29 ++++---
public/manifest.json | 26 ------
src/data.ts | 173 ++++++++++++++++++++++++++++++++++++++
src/pages/_app.tsx | 5 --
src/pages/_document.tsx | 13 ---
src/pages/api/clothes.ts | 24 ++++++
src/pages/api/v1/index.ts | 15 ----
src/pages/index.tsx | 43 +++++++++-
src/type.ts | 18 ++--
14 files changed, 272 insertions(+), 152 deletions(-)
delete mode 100644 .dumirc.ts
delete mode 100644 .fatherrc.ts
delete mode 100644 public/manifest.json
create mode 100644 src/data.ts
delete mode 100644 src/pages/_app.tsx
delete mode 100644 src/pages/_document.tsx
create mode 100644 src/pages/api/clothes.ts
delete mode 100644 src/pages/api/v1/index.ts
diff --git a/.dumirc.ts b/.dumirc.ts
deleted file mode 100644
index b0981c2..0000000
--- a/.dumirc.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import { defineConfig } from 'dumi';
-import { Github } from 'lucide-react';
-
-import { homepage } from './package.json';
-
-const themeConfig = {
- actions: [
- {
- icon: Github,
- link: homepage,
- openExternal: true,
- text: 'Github',
- },
- {
- link: '/components/action-icon',
- text: 'Get Started',
- type: 'primary',
- },
- ],
- footer: 'Made with 🤯 by LobeHub',
- name: 'Realtime Weather',
- socialLinks: {
- discord: 'https://discord.gg/AYFPHvv2jT',
- github: homepage,
- },
-};
-
-export default defineConfig({
- extraBabelPlugins: ['babel-plugin-antd-style'],
- favicons: [
- 'https://registry.npmmirror.com/@lobehub/assets-emoji/1.3.0/files/assets/rainbow.webp',
- ],
- // locales: [{ id: 'en-US', name: 'English' }],
- mfsu: {},
- npmClient: 'pnpm',
- outputPath: 'docs-dist',
- // ssr: isProduction ? {} : false,
- styles: [
- `html, body { background: transparent; }
-
- @media (prefers-color-scheme: dark) {
- html, body { background: #000; }
- }`,
- ],
- themeConfig,
- title: 'RealTime Weather - Lobe Chat Plugin',
-});
diff --git a/.fatherrc.ts b/.fatherrc.ts
deleted file mode 100644
index 52193e5..0000000
--- a/.fatherrc.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { defineConfig } from 'father';
-
-export default defineConfig({
- umd: {
- output: { path: 'dist', filename: 'index' },
- externals: {
- 'react': 'React',
- 'react-dom': 'ReactDOM',
- 'antd': 'antd',
- 'antd-style': 'antd-style',
- },
-
- chainWebpack: (memo) => {
- // use https://github.com/systemjs/systemjs to dynamic load
- memo.output.libraryTarget('system');
- return memo;
- },
- },
-});
diff --git a/.prettierignore b/.prettierignore
index a039fc2..49a56db 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -20,4 +20,3 @@ yarn-error.log
.history
CNAME
/build
-/public
diff --git a/README.md b/README.md
index 1b6db1c..2f8e4fb 100644
--- a/README.md
+++ b/README.md
@@ -66,7 +66,7 @@ TOBE DONE
## ⌨️ Local Development
You can use Gitpod for online development:
-
+``
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)][gitpod-url]
Or clone it for local development:
diff --git a/package.json b/package.json
index 235c4df..31eba33 100644
--- a/package.json
+++ b/package.json
@@ -35,11 +35,14 @@
"not ie <= 10"
],
"dependencies": {
- "@lobehub/chat-plugin-sdk": "^1",
+ "@lobehub/chat-plugin-sdk": "^1.15.1",
"@lobehub/chat-plugins-gateway": "^1",
+ "@lobehub/ui": "latest",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"antd": "^5",
+ "antd-style": "^3",
+ "dayjs": "^1",
"next": "^13.4.19",
"react": "^18.2.0",
"react-dom": "^18.2.0",
@@ -47,21 +50,17 @@
},
"devDependencies": {
"@lobehub/lint": "latest",
- "@lobehub/ui": "latest",
"@vercel/node": "^2",
"@vitest/coverage-v8": "latest",
- "babel-plugin-antd-style": "^1.0.4",
"commitlint": "^17",
"cross-env": "^7",
"eslint": "^8",
"father": "^4.3.1",
"husky": "^8",
"lint-staged": "^13",
- "lucide-react": "latest",
"prettier": "^3",
"semantic-release": "^21",
"typescript": "^5",
- "vercel": "^32",
"vitest": "latest"
}
}
diff --git a/public/manifest-dev.json b/public/manifest-dev.json
index be509c4..fc1ef07 100644
--- a/public/manifest-dev.json
+++ b/public/manifest-dev.json
@@ -1,27 +1,32 @@
{
- "identifier": "chat-plugin-template",
- "version": "1",
"api": [
{
- "url": "http://localhost:3400/api/v1",
- "name": "greetUser",
- "description": "当用户说出 hello 后,你需要问候用户,并祝他开心",
+ "url": "http://localhost:3400/api/clothes",
+ "name": "recommendClothes",
+ "description": "根据用户的心情,给用户推荐他有的衣服",
"parameters": {
"properties": {
- "nickname": {
- "description": "用户的名字,例如:张三 等",
+ "mood": {
+ "description": "用户当前的心情,可选值有:开心(happy), 难过(sad),生气 (anger),害怕(fear),惊喜( surprise),厌恶 (disgust)",
+ "enums": ["happy", "sad", "anger", "fear", "surprise", "disgust"],
"type": "string"
+ },
+ "gender": {
+ "type": "string",
+ "enum": ["man", "woman"],
+ "description": "用户的性别"
}
},
- "required": [
- "nickname"
- ],
+ "required": ["mood", "gender"],
"type": "object"
}
}
],
"gateway": "http://localhost:3400/api/gateway",
+ "identifier": "chat-plugin-template",
"ui": {
-
- }
+ "url": "http://localhost:3400",
+ "height": 200
+ },
+ "version": "1"
}
diff --git a/public/manifest.json b/public/manifest.json
deleted file mode 100644
index 341464d..0000000
--- a/public/manifest.json
+++ /dev/null
@@ -1,26 +0,0 @@
-{
- "identifier": "chat-plugin-template",
- "version": "1",
- "api": [
- {
- "url": "https://template.chat-plugin.lobehub.com/api/v1",
- "name": "hello",
- "description": "问候用户,当用户说出 hello plugin 后,将会调用该方法,并将结果返回给用户",
- "parameters": {
- "properties": {
- "city": {
- "description": "城市名称",
- "type": "string"
- }
- },
- "required": [
- "city"
- ],
- "type": "object"
- }
- }
- ],
- "ui": {
- "url": "https://registry.npmmirror.com/@lobehub/chat-plugin-template/latest/files"
- }
-}
diff --git a/src/data.ts b/src/data.ts
new file mode 100644
index 0000000..78947a8
--- /dev/null
+++ b/src/data.ts
@@ -0,0 +1,173 @@
+export const manClothes = {
+ anger: [
+ {
+ description: '这款黑色皮夹克可以让你在生气时释放压力。',
+ name: '黑色皮夹克',
+ },
+ {
+ description: '这款深红色的衬衫可以让你在生气时感到力量。',
+ name: '深红色长袖衬衫',
+ },
+ {
+ description: '这款军绿色的工装裤可以让你在生气时感到坚韧。',
+ name: '军绿色工装裤',
+ },
+ ],
+ disgust: [
+ {
+ description: '这款黑色的T恤可以让你在厌恶时感到冷静。',
+ name: '黑色修身T恤',
+ },
+ {
+ description: '这款深色的裤子可以让你在厌恶时感到自在。',
+ name: '深色直筒休闲裤',
+ },
+ {
+ description: '这款军绿色的夹克可以让你在厌恶时感到坚定。',
+ name: '军绿色工装夹克',
+ },
+ ],
+ fear: [
+ {
+ description: '这款宽松的卫衣可以让你在害怕时感到安全。',
+ name: '灰色宽松连帽卫衣',
+ },
+ {
+ description: '这款黑色的裤子可以让你在害怕时感到舒适。',
+ name: '黑色直筒休闲裤',
+ },
+ {
+ description: '这款深色的夹克可以让你在害怕时感到保护。',
+ name: '深蓝色牛仔夹克',
+ },
+ ],
+ happy: [
+ {
+ description: '这款明亮的T恤可以增强你的快乐气氛。',
+ name: '亮黄色夏日T恤',
+ },
+ {
+ description: '这款活泼的短裤可以让你的心情保持愉快。',
+ name: '卡通图案运动短裤',
+ },
+ {
+ description: '这款色彩明亮的衬衫可以让你看起来更加开朗。',
+ name: '彩色条纹休闲衬衫',
+ },
+ ],
+ sad: [
+ {
+ description: '舒适的卫衣可以让你在难过的时候感到舒适。',
+ name: '深色宽松卫衣',
+ },
+ {
+ description: '这款深色的夹克可以让你在难过的时候感到安慰。',
+ name: '黑色牛仔夹克',
+ },
+ {
+ description: '简单的黑色T恤可以让你在难过的时候感到平静。',
+ name: '简洁黑色长袖T恤',
+ },
+ ],
+ surprise: [
+ {
+ description: '这款亮色的T恤可以让你在惊喜时感到愉悦。',
+ name: '亮色图案T恤',
+ },
+ {
+ description: '这款鲜艳的短裤可以让你在惊喜时感到活力。',
+ name: '鲜艳色彩运动短裤',
+ },
+ {
+ description: '这款多彩条纹的衬衫可以让你在惊喜时感到快乐。',
+ name: '多彩条纹衬衫',
+ },
+ ],
+};
+
+export const womanClothes = {
+ anger: [
+ {
+ description: '这款黑色皮夹克可以让你在生气时释放压力。',
+ name: '黑色皮夹克',
+ },
+ {
+ description: '这款深红色的衬衫可以让你在生气时感到力量。',
+ name: '深红色长袖衬衫',
+ },
+ {
+ description: '这款军绿色的工装裤可以让你在生气时感到坚韧。',
+ name: '军绿色工装裤',
+ },
+ ],
+ disgust: [
+ {
+ description: '这款黑色的连衣裙可以让你在厌恶时感到冷静。',
+ name: '黑色修身连衣裙',
+ },
+ {
+ description: '这款深色的裤子可以让你在厌恶时感到自在。',
+ name: '深色直筒休闲裤',
+ },
+ {
+ description: '这款军绿色的夹克可以让你在厌恶时感到坚定。',
+ name: '军绿色工装夹克',
+ },
+ ],
+ fear: [
+ {
+ description: '这款宽松的卫衣可以让你在害怕时感到安全。',
+ name: '灰色宽松连帽卫衣',
+ },
+ {
+ description: '这款黑色的裤子可以让你在害怕时感到舒适。',
+ name: '黑色直筒休闲裤',
+ },
+ {
+ description: '这款深色的夹克可以让你在害怕时感到保护。',
+ name: '深蓝色牛仔夹克',
+ },
+ ],
+ happy: [
+ {
+ description: '这款明亮的连衣裙可以增强你的快乐气氛。',
+ name: '亮黄色夏日连衣裙',
+ },
+ {
+ description: '这款活泼的短裤可以让你的心情保持愉快。',
+ name: '卡通图案运动短裤',
+ },
+ {
+ description: '这款色彩明亮的衬衫可以让你看起来更加开朗。',
+ name: '彩色条纹休闲衬衫',
+ },
+ ],
+ sad: [
+ {
+ description: '舒适的连衣裙可以让你在难过的时候感到舒适。',
+ name: '深色宽松连衣裙',
+ },
+ {
+ description: '这款深色的夹克可以让你在难过的时候感到安慰。',
+ name: '黑色牛仔夹克',
+ },
+ {
+ description: '简单的黑色T恤可以让你在难过的时候感到平静。',
+ name: '简洁黑色长袖T恤',
+ },
+ ],
+ surprise: [
+ {
+ description: '这款亮色的连衣裙可以让你在惊喜时感到愉悦。',
+ name: '亮色图案连衣裙',
+ },
+ {
+ description: '这款鲜艳的短裤可以让你在惊喜时感到活力。',
+ name: '鲜艳色彩运动短裤',
+ },
+ {
+ description: '这款多彩条纹的衬衫可以让你在惊喜时感到快乐。',
+ name: '多彩条纹衬衫',
+ },
+ ],
+};
diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx
deleted file mode 100644
index da826ed..0000000
--- a/src/pages/_app.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import type { AppProps } from 'next/app';
-
-export default function App({ Component, pageProps }: AppProps) {
- return ;
-}
diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx
deleted file mode 100644
index af2f1ab..0000000
--- a/src/pages/_document.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-import { Head, Html, Main, NextScript } from 'next/document';
-
-export default function Document() {
- return (
-
-
-
-
-
-
-
- );
-}
diff --git a/src/pages/api/clothes.ts b/src/pages/api/clothes.ts
new file mode 100644
index 0000000..af9e0c9
--- /dev/null
+++ b/src/pages/api/clothes.ts
@@ -0,0 +1,24 @@
+import { PluginErrorType, createErrorResponse } from '@lobehub/chat-plugin-sdk';
+
+import { manClothes, womanClothes } from '@/data';
+import { RequestData, ResponseData } from '@/type';
+
+export const config = {
+ runtime: 'edge',
+};
+
+export default async (req: Request) => {
+ if (req.method !== 'POST') return createErrorResponse(PluginErrorType.MethodNotAllowed);
+
+ const { gender, mood } = (await req.json()) as RequestData;
+
+ const clothes = gender === 'man' ? manClothes : womanClothes;
+
+ const result: ResponseData = {
+ clothes: clothes[mood] || [],
+ mood,
+ today: Date.now(),
+ };
+
+ return new Response(JSON.stringify(result));
+};
diff --git a/src/pages/api/v1/index.ts b/src/pages/api/v1/index.ts
deleted file mode 100644
index f23a65b..0000000
--- a/src/pages/api/v1/index.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { PluginErrorType, createErrorResponse } from '@lobehub/chat-plugin-sdk';
-
-export const config = {
- runtime: 'edge',
-};
-
-export default async (req: Request) => {
- if (req.method !== 'POST') return createErrorResponse(PluginErrorType.MethodNotAllowed);
-
- const args = await req.json();
-
- const result = { hello: args };
-
- return new Response(JSON.stringify(result));
-};
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 285b5ce..5594f42 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -1,7 +1,46 @@
-import { memo } from 'react';
+import { fetchPluginMessage } from '@lobehub/chat-plugin-sdk';
+import { Card } from 'antd';
+import { createStyles } from 'antd-style';
+import dayjs from 'dayjs';
+import { memo, useEffect, useState } from 'react';
+import { Flexbox } from 'react-layout-kit';
+
+import { ResponseData } from '@/type';
+
+const useStyles = createStyles(({ css, token }) => ({
+ date: css`
+ color: ${token.colorTextQuaternary};
+ `,
+}));
const Render = memo(() => {
- return word
;
+ const [data, setData] = useState();
+ const { styles } = useStyles();
+
+ useEffect(() => {
+ fetchPluginMessage().then((e: ResponseData) => {
+ setData(e);
+ });
+ }, []);
+
+ return (
+
+
+ 🌟心情:{data?.mood}
+ {dayjs(data?.today).format('YYYY/MM/DD')}
+
+
+ 推荐衣物
+
+ {data?.clothes?.map((item) => (
+
+ {item.description}
+
+ ))}
+
+
+
+ );
});
export default Render;
diff --git a/src/type.ts b/src/type.ts
index 38f75f5..1d82a23 100644
--- a/src/type.ts
+++ b/src/type.ts
@@ -1,8 +1,14 @@
-export interface WeatherParams {
- city: string;
- extensions?: 'base' | 'all';
+export interface ClothesItem {
+ description: string;
+ name: string;
+}
+export interface ResponseData {
+ clothes: ClothesItem[];
+ mood: string;
+ today: number;
}
-export type ResponseResult = {
- hello: string;
-};
+export interface RequestData {
+ gender: 'man' | 'woman';
+ mood: string;
+}