-
Notifications
You must be signed in to change notification settings - Fork 10
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
1 parent
1f481bf
commit 664ca21
Showing
4 changed files
with
55 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { CustomEmail, Dingtalk, Discord, IGot, OneBot, PushDeer, PushPlus, Qmsg, ServerChanTurbo, ServerChanV3, Telegram, WechatApp, WechatRobot, XiZhi } from '../src' | ||
import { SendResponse } from '../src/interfaces/response' | ||
|
||
const PushAllInOne = { | ||
CustomEmail, | ||
Dingtalk, | ||
Discord, | ||
IGot, | ||
OneBot, | ||
PushDeer, | ||
PushPlus, | ||
Qmsg, | ||
ServerChanTurbo, | ||
ServerChanV3, | ||
Telegram, | ||
WechatApp, | ||
WechatRobot, | ||
XiZhi, | ||
} as const | ||
|
||
export type IPushAllInOne = typeof PushAllInOne | ||
|
||
export type PushType = keyof IPushAllInOne | ||
|
||
export type MetaPushConfig<T extends PushType = PushType> = { | ||
type: T | ||
config: ConstructorParameters<IPushAllInOne[T]>[0] | ||
option: Parameters<IPushAllInOne[T]['prototype']['send']>[2] | ||
} | ||
|
||
/** | ||
* 从传入变量中读取配置,并选择一个渠道推送 | ||
* | ||
* @author CaoMeiYouRen | ||
* @date 2024-11-09 | ||
* @export | ||
* @template T | ||
* @param title 推送标题 | ||
* @param desp 推送内容 | ||
* @param pushConfig 推送配置 | ||
*/ | ||
export async function runPushAllInOne<T extends PushType>(title: string, desp: string, pushConfig: MetaPushConfig<T>): Promise<SendResponse<any>> { | ||
const { type, config, option } = pushConfig | ||
if (PushAllInOne[type]) { | ||
const push = new PushAllInOne[type](config as any) | ||
return push.send(title, desp, option as any) | ||
} | ||
throw new Error('未匹配到任何推送方式!') | ||
} |
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