-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
125 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { App } from '#components' | ||
import { segment } from '#lib' | ||
import { db, utils, task } from '#models' | ||
|
||
task.startTimer() | ||
|
||
const app = { | ||
id: 'push', | ||
name: '推送' | ||
} | ||
|
||
export const rule = { | ||
push: { | ||
reg: /^#?steam(?:开启|关闭)推送\s*(\d+)?$/i, | ||
fnc: async e => { | ||
if (!e.group_id) { | ||
return true | ||
} | ||
const textId = rule.push.reg.exec(e.msg)[1] | ||
const open = e.msg.includes('开启') | ||
// 如果附带了steamId | ||
if (textId) { | ||
const steamId = utils.getSteamId(textId) | ||
const user = await db.UserTableGetDataBySteamId(steamId) | ||
// 如果没有人绑定这个steamId则判断是否为主人,主人才能添加推送 | ||
if (((!user && e.isMaster) || (user && user.userId == e.user_id))) { | ||
const uid = e.isMaster ? utils.getAtUid(e.at, '0') : e.user_id | ||
if (open) { | ||
await db.PushTableAddData(uid, steamId, e.self_id, e.group_id) | ||
await e.reply([uid == '0' ? '' : segment.at(uid), `已开启推送: ${steamId}`]) | ||
} else { | ||
await db.PushTableDelData(uid, steamId, e.self_id, e.group_id) | ||
await e.reply([uid == '0' ? '' : segment.at(uid), `已关闭推送: ${steamId}`]) | ||
} | ||
} else { | ||
await e.reply('只能开启或关闭自己的推送哦') | ||
} | ||
} else { | ||
const uid = utils.getAtUid(e.isMaster ? e.at : '', e.user_id) | ||
// 没有附带steamId则使用绑定的steamId | ||
const steamId = await db.UserTableGetBindSteamIdByUserId(uid) | ||
if (steamId) { | ||
if (open) { | ||
await db.PushTableAddData(uid, steamId, e.self_id, e.group_id) | ||
await e.reply([segment.at(uid), `已开启推送: ${steamId}`]) | ||
} else { | ||
await db.PushTableDelData(uid, steamId, e.self_id, e.group_id) | ||
await e.reply([segment.at(uid), `已关闭推送: ${steamId}`]) | ||
} | ||
} else { | ||
await e.reply('你还没有steamId哦') | ||
} | ||
} | ||
return true | ||
} | ||
} | ||
} | ||
|
||
export const pushApp = new App(app, rule).create() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters