| 36 | this.db = null; |
| 37 | this.stickerSet = null; |
| 38 | } |
| 39 | |
| 40 | async setup(): Promise<void> { |
| 41 | await this.initDB(); |
| 42 | await this.loadStickerSet(); |
| 43 | } |
| 44 | |
| 45 | private db: any = null; |
| 46 | private stickerSet: any = null; |
| 47 | private readonly PLUGIN_NAME = "lu_bs"; |
| 48 | |
| 49 | description = HELP_TEXT; |
| 50 | |
| 51 | // 定时任务 - 每小时整点执行 |
| 52 | cronTasks = { |
| 53 | hourlyReport: { |
| 54 | cron: "0 * * * *", // 每小时整点 |
| 55 | description: "鲁小迅整点报时", |
| 56 | handler: async (client: any) => { |
| 57 | await this.sendHourlyStickers(client); |
| 58 | } |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | constructor() { |
| 63 | super(); |
| 64 | } |
| 65 | |
| 66 | // 初始化数据库 |
| 67 | private async initDB() { |
| 68 | const dbPath = path.join(createDirectoryInAssets(this.PLUGIN_NAME), "subscriptions.json"); |
| 69 | this.db = await JSONFilePreset(dbPath, { |
| 70 | subscriptions: [], |
| 71 | lastMessages: {} // 存储最后发送的消息ID,用于删除 |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | // 加载贴纸包 |
| 76 | private async loadStickerSet() { |
| 77 | try { |
| 78 | const client = await getGlobalClient(); |
| 79 | if (!client) return; |
| 80 | |
| 81 | // 使用Telegram原始API获取贴纸包 |
| 82 | this.stickerSet = await client.invoke( |
| 83 | new Api.messages.GetStickerSet({ |
| 84 | stickerset: new Api.InputStickerSetShortName({ |
| 85 | shortName: "luxiaoxunbs" |
| 86 | }), |
| 87 | hash: 0 |
| 88 | }) |
| 89 | ); |
| 90 | |
| 91 | console.log(`[${this.PLUGIN_NAME}] 贴纸包加载成功`); |
| 92 | } catch (error) { |
| 93 | console.error(`[${this.PLUGIN_NAME}] 贴纸包加载失败:`, error); |
| 94 | this.stickerSet = null; |
| 95 | } |
nothing calls this directly
no test coverage detected