Skip to content

Commit

Permalink
lint: semicolon & quote
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Mar 27, 2022
1 parent 81ac90f commit 59c2f59
Show file tree
Hide file tree
Showing 34 changed files with 1,379 additions and 1,364 deletions.
36 changes: 18 additions & 18 deletions demo/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import fs from "fs";
import path from "path";
import { Mirai } from "mirai-ts";
import type { MiraiApiHttpSetting } from "mirai-ts";
import yaml from "js-yaml";
import fs from 'fs'
import path from 'path'
import { Mirai } from 'mirai-ts'
import type { MiraiApiHttpSetting } from 'mirai-ts'
import yaml from 'js-yaml'

const qq = 712727946;
const qq = 712727946
// setting 可直接读取 setting.yml 或参考 `src/types/setting.ts`
const setting = yaml.load(
fs.readFileSync(
path.resolve(
__dirname,
"../mcl/config/net.mamoe.mirai-api-http/setting.yml"
'../mcl/config/net.mamoe.mirai-api-http/setting.yml',
),
"utf8"
)
) as MiraiApiHttpSetting;
'utf8',
),
) as MiraiApiHttpSetting

const mirai = new Mirai(setting);
const mirai = new Mirai(setting)

async function app() {
await mirai.link(qq);
mirai.on("message", (msg) => {
await mirai.link(qq)
mirai.on('message', (msg) => {
// eslint-disable-next-line no-console
console.log(msg);
console.log(msg)
// 复读
msg.reply(msg.messageChain);
});
mirai.listen();
msg.reply(msg.messageChain)
})
mirai.listen()
}

app();
app()
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
},
"lint-staged": {
"*.ts": [
"eslint --fix",
"prettier --write"
"eslint --fix"
]
},
"repository": {
Expand Down
20 changes: 10 additions & 10 deletions src/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
* @packageDocumentation
*/

import type { AxiosStatic } from "axios";
import axios from "axios";
import type { AxiosStatic } from 'axios'
import axios from 'axios'

/**
* 初始化 axios
* @param baseURL 请求的基础 URL
* @param timeout 请求超时时间
*/
export function init(baseURL?: string, timeout = 0): AxiosStatic {
if (baseURL) axios.defaults.baseURL = baseURL;
if (baseURL) axios.defaults.baseURL = baseURL

axios.defaults.timeout = timeout;
axios.defaults.timeout = timeout

axios.interceptors.request.use(
(config) => {
return config;
return config
},
(err) => {
if (process.env.NODE_ENV !== "production") console.error(err);
if (process.env.NODE_ENV !== 'production') console.error(err)

return Promise.reject(err);
}
);
return Promise.reject(err)
},
)

return axios;
return axios
}
14 changes: 7 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import type { MiraiApiHttpSetting, MiraiOptions } from ".";
import type { MiraiApiHttpSetting, MiraiOptions } from '.'

export const defaultMahSetting: MiraiApiHttpSetting = {
adapters: ["http", "ws"],
adapters: ['http', 'ws'],
enableVerify: true,
verifyKey: "el-psy-congroo",
verifyKey: 'el-psy-congroo',
debug: true,
singleMode: false,
cacheSize: 4096,
adapterSettings: {
http: {
host: "localhost",
host: 'localhost',
port: 4859,
},
ws: {
host: "localhost",
host: 'localhost',
port: 4859,
},
},
};
}

export const defaultMiraiOptions: MiraiOptions = {
ws: {
heartbeatInterval: 60000,
},
};
}
88 changes: 45 additions & 43 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,94 @@
* @packageDocumentation
*/

import type { Mirai } from "./mirai";
import type { Mirai } from './mirai'

import { getPlain } from "./utils/internal";
import { isAt, isChatMessage } from "./utils/check";
import { getPlain } from './utils/internal'
import { isAt, isChatMessage } from './utils/check'

import type {
BotInvitedJoinGroupRequestOperationType,
MemberJoinRequestOperationType,
NewFriendRequestOperationType,
} from "./mirai-api-http/resp";
import type { SingleMessage } from "./types/message-type";
import type { EventType, MessageType } from ".";
} from './mirai-api-http/resp'
import type { SingleMessage } from './types/message-type'
import type { EventType, MessageType } from '.'

/**
* 为消息和事件类型挂载辅助函数
* @param msg
*/
export function createHelperForMsg(
mirai: Mirai,
msg: MessageType.ChatMessage | EventType.Event
msg: MessageType.ChatMessage | EventType.Event,
) {
mirai.curMsg = msg;
mirai.curMsg = msg

// 消息类型添加直接获取消息内容的参数
if (isChatMessage(msg)) {
msg.plain = getPlain(msg.messageChain);
msg.plain = getPlain(msg.messageChain)

if (msg.type === "GroupMessage") {
if (msg.type === 'GroupMessage') {
// 添加判断是否被艾特的辅助函数
msg.isAt = (qq?: number) => {
return isAt(msg, qq || mirai.qq) as boolean;
};
return isAt(msg, qq || mirai.qq) as boolean
}
}

// 语法糖
msg.group = (...groupIds) => {
return groupIds.includes(
(msg as MessageType.GroupMessage).sender.group.id
);
};
(msg as MessageType.GroupMessage).sender.group.id,
)
}
msg.friend = (...qqs) => {
return qqs.includes(msg.sender.id);
};
return qqs.includes(msg.sender.id)
}

msg.get = (type) => {
let curSingleMessage: SingleMessage | null = null;
let curSingleMessage: SingleMessage | null = null
msg.messageChain.some((singleMessage) => {
if (singleMessage.type === type) {
curSingleMessage = singleMessage;
return true;
curSingleMessage = singleMessage
return true
}
return false;
});
return curSingleMessage;
};
return false
})
return curSingleMessage
}
}

// 为各类型添加 reply 辅助函数
(msg as any).reply = async (
(msg as any).reply = async(
msgChain: string | MessageType.MessageChain,
quote = false
quote = false,
) => {
return mirai.reply(msgChain, msg, quote);
};
return mirai.reply(msgChain, msg, quote)
}

// 为请求类事件添加 respond 辅助函数
if (msg.type === "NewFriendRequestEvent") {
msg.respond = async (
if (msg.type === 'NewFriendRequestEvent') {
msg.respond = async(
operate: NewFriendRequestOperationType,
message?: string
message?: string,
) => {
return mirai.api.resp.newFriendRequest(msg, operate, message);
};
} else if (msg.type === "MemberJoinRequestEvent") {
msg.respond = async (
return mirai.api.resp.newFriendRequest(msg, operate, message)
}
}
else if (msg.type === 'MemberJoinRequestEvent') {
msg.respond = async(
operate: MemberJoinRequestOperationType,
message?: string
message?: string,
) => {
return mirai.api.resp.memberJoinRequest(msg, operate, message);
};
} else if (msg.type === "BotInvitedJoinGroupRequestEvent") {
msg.respond = async (
return mirai.api.resp.memberJoinRequest(msg, operate, message)
}
}
else if (msg.type === 'BotInvitedJoinGroupRequestEvent') {
msg.respond = async(
operate: BotInvitedJoinGroupRequestOperationType,
message?: string
message?: string,
) => {
return mirai.api.resp.botInvitedJoinGroupRequest(msg, operate, message);
};
return mirai.api.resp.botInvitedJoinGroupRequest(msg, operate, message)
}
}
}
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
* @packageDocumentation
*/

import { Mirai } from "./mirai";
export * from "./mirai";
import { Mirai } from './mirai'
export * from './mirai'

export type MiraiInstance = Mirai;
export type MiraiInstance = Mirai

export * as Message from "./message";
export * from "./mirai-api-http";
export * as Message from './message'
export * from './mirai-api-http'

// 工具
export * from "./utils";
export * from './utils'
// https://www.npmjs.com/package/@yunyoujun/logger
export { Logger } from "@yunyoujun/logger";
export { Logger } from '@yunyoujun/logger'

// 类型
export * from "./types";
export * from './types'

export default Mirai;
export default Mirai
Loading

0 comments on commit 59c2f59

Please sign in to comment.