Skip to content

Commit

Permalink
style: 代码格式化
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengxs2018 committed Dec 23, 2023
1 parent a56fdd6 commit 1109cd5
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 100 deletions.
26 changes: 12 additions & 14 deletions examples/wechaty-file.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import os from 'node:os'
import path from 'node:path';
import { unlinkSync } from 'node:fs';

import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { PuppetDingTalk } from '@zhengxs/wechaty-puppet-dingtalk';
import { FileBox } from 'file-box';
import { getAudioDurationInSeconds } from 'get-audio-duration';
import { WechatyBuilder } from 'wechaty';

import { getAudioDurationInSeconds } from 'get-audio-duration'

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const puppet = new PuppetDingTalk({
clientId: process.env.DINGTALK_CLIENT_ID,
clientSecret: process.env.DINGTALK_CLIENT_SECRET,
async getAudioDurationInSeconds(fileBox) {
const saveTo = path.resolve(os.tmpdir(), fileBox.name)
const saveTo = path.resolve(os.tmpdir(), fileBox.name);

await fileBox.toFile(saveTo)
await fileBox.toFile(saveTo);

try {
return await getAudioDurationInSeconds(saveTo)
return await getAudioDurationInSeconds(saveTo);
} finally {
unlinkSync(saveTo)
unlinkSync(saveTo);
}
},
})
});

const bot = WechatyBuilder.build({
puppet
puppet,
});

bot.on('message', async msg => {
Expand All @@ -41,17 +39,17 @@ bot.on('message', async msg => {
case MessageTypes.Video:
case MessageTypes.Image: {
const fileBox = await msg.toFileBox();
const saveTo = path.resolve(__dirname, 'data', fileBox.name)
const saveTo = path.resolve(__dirname, 'data', fileBox.name);

await fileBox.toFile(saveTo)
await fileBox.toFile(saveTo);

await msg.say(`File saved to: ${saveTo}`);
break;
}

case MessageTypes.Text: {
if (msg.text() === 'ding') {
await msg.say('dong')
await msg.say('dong');
}

await msg.say(FileBox.fromUrl('https://downsc.chinaz.net/Files/DownLoad/sound1/202311/y2300.mp3'));
Expand Down
14 changes: 6 additions & 8 deletions examples/wechaty.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@

import path from 'node:path';

import { PuppetDingTalk } from '@zhengxs/wechaty-puppet-dingtalk';
import { FileBox } from 'file-box';
import { WechatyBuilder } from 'wechaty';


const puppet = new PuppetDingTalk({
clientId: process.env.DINGTALK_CLIENT_ID,
clientSecret: process.env.DINGTALK_CLIENT_SECRET,
})
});

const bot = WechatyBuilder.build({
puppet
puppet,
});

bot.on('message', async msg => {
Expand All @@ -24,17 +22,17 @@ bot.on('message', async msg => {
case MessageTypes.Video:
case MessageTypes.Image: {
const fileBox = await msg.toFileBox();
const saveTo = path.resolve(__dirname, 'data', fileBox.name)
const saveTo = path.resolve(__dirname, 'data', fileBox.name);

await fileBox.toFile(saveTo)
await fileBox.toFile(saveTo);
await msg.say(`File saved to: ${saveTo}`);
break;
}

case MessageTypes.Text: {
if (msg.text() === 'ding') {
await msg.say('dong')
break
await msg.say('dong');
break;
}

await msg.say(FileBox.fromUrl('https://www.baidu.com/img/PCfb_5bf082d29588c07f842ccde3f97243ea.png'));
Expand Down
8 changes: 7 additions & 1 deletion packages/wechaty-puppet-dingtalk/src/dingtalk/sayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { type MarkdownMessagePayload, type MessagePayload, MessageType, type Sayable, type TextMessagePayload } from './payloads';
import {
type MarkdownMessagePayload,
type MessagePayload,
MessageType,
type Sayable,
type TextMessagePayload,
} from './payloads';
import { Sender } from './sender';

export class SayableSayer extends Sender {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface DTContactRawPayload {
/**
* 用户类型
*/
type: DTContactType
type: DTContactType;

/**
* Webhook 地址
Expand Down
Loading

0 comments on commit 1109cd5

Please sign in to comment.