Skip to content

Commit

Permalink
fix: 修复已知错误
Browse files Browse the repository at this point in the history
  • Loading branch information
yusheng929 committed Feb 2, 2025
1 parent 81a1133 commit c562855
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 146 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pnpm install --filter=karin-plugin-ling

</details>

### 2. 使用包管理器安装
### 2. 使用包管理器安装(推荐)

<details> <summary>点击展开</summary>

Expand Down Expand Up @@ -95,7 +95,7 @@ pnpm install --filter=karin-plugin-ling -P
* 克隆仓库到本地

```bash
git clone --depth=1 -b npm https://github.com/yusheng929/karin-plugin-ling.git ./plugins/karin-plugin-ling
git clone --depth=1
```

* 进入仓库目录
Expand Down Expand Up @@ -130,10 +130,9 @@ pnpm run build
Karin/@karinjs/karin-plugin-ling/config
```

# 未来计划
## 后续计划

- [X] Bot的前缀快捷设置
- [ ] 增加进群申请通知
暂无喵~

# 负责声明

Expand Down
107 changes: 21 additions & 86 deletions src/apps/GroupAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ import { translateChinaNum } from '../components/Number'
* 全体禁言
*/
export const muteAll = karin.command(/^#?(|)$/, async (e) => {
if (!e.isGroup) {
e.reply('请在群聊中执行')
return true
}
/** 只有主人 群管理员可以使用 */
if (!(['owner', 'admin'].includes(e.sender.role) || e.isMaster)) {
await e.reply('暂无权限,只有管理员才能操作')
return true
}

/** 检查bot自身是否为管理员、群主 */
const info = await e.bot.getGroupMemberInfo(e.groupId, e.selfId)
if (!(['owner', 'admin'].includes(info.role))) {
Expand All @@ -31,33 +21,23 @@ export const muteAll = karin.command(/^#?全体(禁言|解禁)$/, async (e) => {
return true
} catch (error) {
await e.reply('\n错误: 未知原因❌', { at: true })
logger.error(error)
return true
}
}, { name: '全体禁言', priority: -1, perm: 'group.admin' })
}, { name: '全体禁言', priority: -1, perm: 'group.admin', event: 'message.group' })

/**
* 设置/取消管理员
*/
export const setAdmin = karin.command(/^#(|)/, async (e) => {
if (!e.isGroup) {
e.reply('请在群聊中执行')
return true
}
/** 只有bot为群主才可以使用 */
const info = await e.bot.getGroupMemberInfo(e.groupId, e.selfId)
if (!(['owner'].includes(info.role))) {
await e.reply('少女不是群主,做不到呜呜~(>_<)~')
return true
}

let userId = ''

/** 存在at */
if (e.at.length) {
userId = e.at[0]
} else {
userId = e.msg.replace(/#|(|)/, '').trim()
}
const userId = e.at[0] || e.msg.replace(/#(|)/, '').trim()

if (!userId || !(/\d{5,}/.test(userId))) {
await e.reply('\n貌似这个QQ号不对哦~', { at: true })
Expand All @@ -83,18 +63,15 @@ export const setAdmin = karin.command(/^#(设置|取消)管理/, async (e) => {
return true
} catch (error) {
await e.reply('\n错误: 未知原因❌', { at: true })
logger.error(error)
return true
}
}, { name: '设置管理', priority: -1, permission: 'master' })
}, { name: '设置管理', priority: -1, permission: 'master', event: 'message.group' })

/**
* 设置群头衔
*/
export const ApplyGroupTitle = karin.command(/^#(|)/, async (e) => {
if (!e.isGroup) {
e.reply('请在群聊中执行')
return true
}
/** 只有bot为群主才可以使用 */
const info = await e.bot.getGroupMemberInfo(e.groupId, e.selfId)
if (!(['owner'].includes(info.role))) {
Expand All @@ -105,19 +82,20 @@ export const ApplyGroupTitle = karin.command(/^#(申请|我要)头衔/, async (e
const title = e.msg.replace(/#(|)/, '').trim()
try {
if (!title) {
await e.bot.setGroupMemberTitle(e.groupId, e.userId, title)
await e.bot.setGroupMemberTitle(e.groupId, e.userId, '')
await e.reply('\n已经将你的头衔取消了~', { at: true })
return true
}

await e.bot.setGroupMemberTitle(e.groupId, e.userId, title)
await e.reply('\n换上了哦', { at: true })
return true
} catch (error: any) {
await e.reply(`\n错误:\n${error.message}`, { at: true })
} catch (error) {
await e.reply('\n未知原因❌', { at: true })
logger.error(error)
return true
}
}, { name: '申请头衔', priority: -1 })
}, { name: '申请头衔', priority: -1, event: 'message.group' })

/**
* 设置头衔
Expand All @@ -138,7 +116,7 @@ export const setGroupTitle = karin.command(/^#设置头衔/, async (e) => {
}
try {
if (!title) {
await e.bot.setGroupMemberTitle(e.groupId, userId, title)
await e.bot.setGroupMemberTitle(e.groupId, userId, '')
await e.reply(`已经将用户[${userId}]的头衔取消了`, { at: true })
return true
}
Expand All @@ -156,24 +134,7 @@ export const setGroupTitle = karin.command(/^#设置头衔/, async (e) => {
* 踢人
*/
export const kickMember = karin.command(/^#/, async (e) => {
if (!e.isGroup) {
e.reply('请在群聊中执行')
return true
}
/** 只有主人、群主、管理员可以使用 */
if (!(['owner', 'admin'].includes(e.sender.role) || e.isMaster)) {
await e.reply('暂无权限,只有管理员才能操作')
return true
}

let userId = ''

/** 存在at */
if (e.at.length) {
userId = e.at[0]
} else {
userId = e.msg.replace(/#/g, '').trim()
}
const userId = e.at[0] || e.msg.replace(/#/, '').trim()

if (!userId || !(/\d{5,}/.test(userId))) {
await e.reply('\n貌似这个QQ号不对哦~', { at: true })
Expand All @@ -195,13 +156,8 @@ export const kickMember = karin.command(/^#踢/, async (e) => {
}

/** 检查对方的角色 */
if (res.role === 'owner') {
await e.reply('\n这个人是群主,少女做不到呜呜~(>_<)~', { at: true })
return true
}

if (res.role === 'admin') {
await e.reply('\n少女不能踢出管理员呜呜~(>_<)~', { at: true })
if (res.role === 'owner' || res.role === 'admin' || res.role === 'member') {
await e.reply('\n这个人太强大了,少女做不到呜呜~(>_<)~', { at: true })
return true
}
} catch {
Expand All @@ -215,40 +171,27 @@ export const kickMember = karin.command(/^#踢/, async (e) => {
return true
} catch (error) {
await e.reply('\n错误: 未知原因❌', { at: true })
logger.error(error)
return true
}
}, { name: '踢', priority: -1 })
}, { name: '踢', priority: -1, event: 'message.group', perm: 'group.admin' })

/**
* 解禁
*/
export const UnBanMember = karin.command(/^#/, async (e) => {
if (!e.isGroup) {
e.reply('请在群聊中执行')
return true
}
if (!(['owner', 'admin'].includes(e.sender.role) || e.isMaster)) {
await e.reply('暂无权限,只有管理员才能操作')
return true
}
const info = await e.bot.getGroupMemberInfo(e.groupId, e.selfId)
if (!(['owner', 'admin'].includes(info.role))) {
await e.reply('少女做不到呜呜~(>_<)~')
return true
}
let userId = ''

/** 存在at */
if (e.at.length) {
userId = e.at[0]
} else {
userId = e.msg.replace(/#/g, '').trim()
}
const userId = e.at[0] || e.msg.replace(/#/, '').trim()

if (!userId || !(/\d{5,}/.test(userId))) {
await e.reply('\n貌似这个QQ号不对哦~', { at: true })
return true
}

try {
const res = await e.bot.getGroupMemberInfo(e.groupId, userId)
if (!res) {
Expand Down Expand Up @@ -279,22 +222,14 @@ export const UnBanMember = karin.command(/^#解禁/, async (e) => {
return true
} catch (error) {
await e.reply('\n错误: 未知原因❌', { at: true })
logger.error(error)
return true
}
}, { name: '解禁', priority: -1 })
}, { name: '解禁', priority: -1, event: 'message.group', perm: 'group.admin' })

export const BanMember = karin.command(
/^#?(\d+|[亿]+)?(|||||)?/,
async (e) => {
if (!e.isGroup) {
e.reply('请在群聊中执行')
return true
}
if (!(['owner', 'admin'].includes(e.sender.role) || e.isMaster)) {
await e.reply('暂无权限,只有管理员才能操作')
return true
}

const info = await e.bot.getGroupMemberInfo(e.groupId, e.selfId)
if (!(['owner', 'admin'].includes(info.role))) {
await e.reply('少女做不到呜呜~(>_<)~')
Expand Down Expand Up @@ -371,5 +306,5 @@ export const BanMember = karin.command(
}
return false
},
{ name: '禁言', priority: -1 }
{ name: '禁言', priority: -1, event: 'message.group', perm: 'group.admin' }
)
2 changes: 1 addition & 1 deletion src/apps/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ export const QuitGroup = karin.command(/^#?退群/, async (e) => {
if (groupId === e.groupId) {
await e.reply('3秒后退出本群聊')
await common.sleep(3000)
await e.bot.setGroupQuit(groupId, false)
} else {
await e.reply(`已退出群聊『${groupId}』`)
}
await e.bot.setGroupQuit(groupId, false)

return true
} catch (error) {
Expand Down
35 changes: 6 additions & 29 deletions src/apps/groupOther.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import moment from 'node-karin/moment'
import { karin, segment, common } from 'node-karin'
import { karin, segment, common, logger } from 'node-karin'

/**
* 改群名
*/
export const ModifyGroupName = karin.command(/^#/, async (e) => {
if (!e.isGroup) {
e.reply('请在群聊中执行')
return true
}
if (!(['owner', 'admin'].includes(e.sender.role) || e.isMaster)) {
await e.reply('暂无权限,只有管理员才能操作')
return true
}
const info = await e.bot.getGroupMemberInfo(e.groupId, e.selfId)
if (!info.role || !(['owner', 'admin'].includes(info.role))) {
await e.reply('少女做不到呜呜~(>_<)~')
Expand All @@ -29,19 +21,16 @@ export const ModifyGroupName = karin.command(/^#改群名/, async (e) => {
e.reply(`已经将群名修改为『${Name}』`)
} catch (error) {
await e.reply('\n错误: 未知原因❌', { at: true })
logger.error(error)
return true
}
return true
}, { name: '改群名', priority: -1 })
}, { name: '改群名', priority: -1, event: 'message.group', perm: 'group.admin' })

/**
* 获取禁言列表
*/
export const MuteList = karin.command(/^#?(|)?$/, async (e) => {
if (!e.isGroup) {
e.reply('请在群聊中执行')
return true
}
const lsit = []
const result = await e.bot.getGroupMuteList(e.groupId)
if (!result.length) {
Expand All @@ -62,13 +51,9 @@ export const MuteList = karin.command(/^#?(获取|查看)?禁言列表$/, async
const content = common.makeForward(lsit, e.selfId, e.bot.account.name)
await e.bot.sendForwardMsg(e.contact, content)
return true
})
}, { name: '获取禁言列表', priority: -1, event: 'message.group' })

export const ModifyMemberCard = karin.command(/^#/, async (e) => {
if (!e.isGroup) {
e.reply('请在群聊中执行')
return true
}
const Name = e.msg.replace(/^#/, '').trim()
if (!Name) {
e.reply('群昵称不能为空', { at: true })
Expand All @@ -83,17 +68,9 @@ export const ModifyMemberCard = karin.command(/^#改群昵称/, async (e) => {
return true
}
return true
}, { name: '改群昵称', priority: -1, permission: 'master' })
}, { name: '改群昵称', priority: -1, permission: 'master', event: 'message.group' })

export const SetEssence = karin.command(/^#?(||)$/, async (e) => {
if (!e.isGroup) {
e.reply('请在群聊中执行')
return true
}
if (!(['owner', 'admin'].includes(e.sender.role) || e.isMaster)) {
await e.reply('暂无权限,只有管理员才能操作')
return true
}
const info = await e.bot.getGroupMemberInfo(e.groupId, e.selfId)
if (!info.role || !(['owner', 'admin'].includes(info.role))) {
await e.reply('少女做不到呜呜~(>_<)~')
Expand All @@ -113,4 +90,4 @@ export const SetEssence = karin.command(/^#?(加|设|移)精$/, async (e) => {
}

return true
}, { name: '处理精华消息', priority: -1 })
}, { name: '处理精华消息', priority: -1, event: 'message.group', perm: 'group.admin' })
25 changes: 0 additions & 25 deletions src/apps/quickCode/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,3 @@ export const UploadDownload = karin.command(/^文件上传/, async (e) => {
}
return true
}, { name: '文件上传', priority: -1, permission: 'master' })

export const FileMove = karin.command(/^/, async (e) => {
await e.reply('请发送文件路径', { at: true })
const Path1 = await karin.ctx(e)
const Path = Path1.msg
const name = path.basename(Path)
await e.reply('请发送移动路径', { reply: true })
const Path2 = await karin.ctx(e)
let FinalPath = Path2.msg
if (FinalPath === '') FinalPath = process.cwd()
if (!(fs.existsSync(Path))) {
e.reply('文件不存在', { reply: true })
return true
}
await e.reply('开始移动文件', { reply: true })
try {
await fs.promises.rename(Path, `${FinalPath}/${name}`)
await e.reply(`移动完成,文件原位置:\n${process.cwd()}/${Path}\n文件当前位置:\n${FinalPath}/${name}`, { reply: true })
} catch (error) {
logger.error('文件移动错误:')
logger.error(error)
await e.reply('文件下载错误:请前往控制台查询', { reply: true })
}
return true
}, { name: '文件上传', priority: -1, permission: 'master' })
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"outDir": "./lib",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"@/*": [
Expand Down

0 comments on commit c562855

Please sign in to comment.