MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / updateStats

Function updateStats

shift/shift.ts:2100–2151  ·  view source on GitHub ↗
(
  sourceId: number,
  targetId: number,
  messageType: string
)

Source from the content-addressed store, hash-verified

2098 { "value": "Europe/Berlin", "label": "柏林时间 (UTC+1)" },
2099 { "value": "Australia/Sydney", "label": "悉尼时间 (UTC+10)" },
2100 { "value": "Pacific/Auckland", "label": "奥克兰时间 (UTC+12)" },
2101 { "value": "UTC", "label": "协调世界时 (UTC+0)" }
2102 ],
2103 "default": "Asia/Shanghai"
2104 },
2105 {
2106 "key": "reminderTime",
2107 "label": "提醒时间",
2108 "type": "string",
2109 "default": "09:00",
2110 "description": "每日提醒时间,格式 HH:MM(24小时制)"
2111 }
2112],
2113 getValues: async (): Promise<Record<string, unknown>> => {
2114 const db = await JSONFilePreset<any>(path.join(createDirectoryInAssets("shift"), "config.json"), {} as any);
2115 return db.data as Record<string, unknown>;
2116 },
2117 setValues: async (patch: Record<string, unknown>): Promise<void> => {
2118 const db = await JSONFilePreset<any>(path.join(createDirectoryInAssets("shift"), "config.json"), {} as any);
2119 Object.assign(db.data, patch);
2120 await db.write();
2121 },
2122 };
2123 };
2124 listenMessageHandlerIgnoreEdited: boolean = false;
2125 listenMessageHandler?:
2126 | ((msg: Api.Message, options?: { isEdited?: boolean }) => Promise<void>)
2127 | undefined = shiftMessageListener;
2128}
2129
2130// Update stats function
2131function updateStats(
2132 sourceId: number,
2133 targetId: number,
2134 messageType: string
2135): void {
2136 try {
2137 const today = new Date().toISOString().split("T")[0];
2138 const statsKey = `shift.stats.${sourceId}.${today}`;
2139
2140 if (useLowdb && lowdb) {
2141 // 更新 lowdb 统计
2142 if (!lowdb.data.stats[today]) {
2143 lowdb.data.stats[today] = {};
2144 }
2145 if (!lowdb.data.stats[today][String(sourceId)]) {
2146 lowdb.data.stats[today][String(sourceId)] = { total: 0 };
2147 }
2148
2149 const stats = lowdb.data.stats[today][String(sourceId)];
2150 stats.total = (stats.total || 0) + 1;
2151 stats[messageType] = (stats[messageType] || 0) + 1;
2152
2153 // 批量写入优化
2154 if (stats.total % 10 === 0) {

Callers 2

callbackFunction · 0.85
handleIncomingMessageFunction · 0.85

Calls 4

writeMethod · 0.80
runMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected