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

Class PanguPlugin

pangu/pangu.ts:186–682  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184 }
185
186 async setup(): Promise<void> {
187 await this.initDB();
188 this.updateStats();
189 }
190
191 name = "pangu";
192 description: string = `📝 Pangu 消息格式化插件\n\n${help_text}`;
193 private db: any;
194 private prefixes: string[];
195
196 constructor() {
197 super();
198 this.prefixes = getPrefixes();
199 }
200
201 // 初始化数据库
202 private async initDB(): Promise<void> {
203 const dir = createDirectoryInAssets("pangu");
204 const dbPath = path.join(dir, "config.json");
205
206 const defaultConfig: PanguConfig = {
207 version: "1.0.0",
208 chats: {},
209 whitelist: [],
210 blacklist: [],
211 globalMode: false,
212 stats: {
213 formattedMessages: 0,
214 lastFormatted: null,
215 enabledChats: 0
216 }
217 };
218
219 this.db = await JSONFilePreset<PanguConfig>(dbPath, defaultConfig);
220 this.updateStats();
221 }
222
223 // 获取会话ID
224 private getChatId(msg: Api.Message): string {
225 return msg.peerId.toString();
226 }
227
228 // 获取会话模式
229 private getChatMode(chatId: string): boolean | null {
230 return this.db.data.chats.hasOwnProperty(chatId) ?
231 this.db.data.chats[chatId] : null;
232 }
233
234 // 设置会话模式
235 private async setChatMode(chatId: string, enabled: boolean): Promise<void> {
236 this.db.data.chats[chatId] = enabled;
237 this.updateStats();
238 await this.db.write();
239 }
240
241 // 检查是否为白名单
242 private isWhite(chatId: string): boolean {
243 return this.db.data.whitelist.includes(chatId);

Callers

nothing calls this directly

Calls 15

getChatIdMethod · 0.95
showStatusMethod · 0.95
handleTestMethod · 0.95
handleWhiteListMethod · 0.95
handleBlackListMethod · 0.95
handleGlobalModeMethod · 0.95
showStatsMethod · 0.95
setChatModeMethod · 0.95
updateStatsMethod · 0.95
isWhiteMethod · 0.95
isBlackMethod · 0.95
getChatModeMethod · 0.95

Tested by

no test coverage detected