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

Function getShiftRule

shift/shift.ts:297–342  ·  view source on GitHub ↗
(sourceId: number)

Source from the content-addressed store, hash-verified

295 if (useLowdb && lowdb) {
296 // 从 lowdb 读取
297 const data = lowdb.data.rules[String(sourceId)];
298 rule = data || null;
299 } else if (sqliteDb) {
300 // 从 SQLite 读取
301 const stmt = sqliteDb.prepare(
302 "SELECT * FROM shift_rules WHERE source_id = ?"
303 );
304 const row = stmt.get(sourceId) as any;
305
306 if (!row) {
307 ruleCache.set(sourceId, { rule: null, timestamp: now });
308 return null;
309 }
310
311 rule = {
312 target_id: row.target_id,
313 options: JSON.parse(row.options || "[]"),
314 target_type: row.target_type,
315 paused: row.paused === 1,
316 created_at: row.created_at,
317 filters: JSON.parse(row.filters || "[]"),
318 };
319 }
320
321 if (rule) {
322 ruleCache.set(sourceId, { rule, timestamp: now });
323 }
324 return rule;
325 } catch (error) {
326 console.error(`[SHIFT] Error getting rule for ${sourceId}:`, error);
327 return null;
328 }
329}
330
331// Save shift rule
332function saveShiftRule(sourceId: number, rule: ShiftRule): boolean {
333 try {
334 if (useLowdb && lowdb) {
335 // 保存到 lowdb
336 lowdb.data.rules[String(sourceId)] = rule;
337 lowdb.write();
338 ruleCache.set(sourceId, { rule, timestamp: Date.now() });
339 return true;
340 } else if (sqliteDb) {
341 // 保存到 SQLite
342 const stmt = sqliteDb.prepare(`
343 INSERT OR REPLACE INTO shift_rules
344 (source_id, target_id, options, target_type, paused, created_at, filters)
345 VALUES (?, ?, ?, ?, ?, ?, ?)

Callers 4

isCircularForwardFunction · 0.85
isMessageFilteredFunction · 0.85
shiftForwardMessageFunction · 0.85
handleIncomingMessageFunction · 0.85

Calls 3

errorMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected