1 Star 7 Fork 0

硫酸钡Barite / 云崽Bot头衔插件.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
giveTitle.js 3.44 KB
一键复制 编辑 原始数据 按行查看 历史
硫酸钡Barite 提交于 2023-04-18 03:30 . 加了个随机回复功能
//改写自旧版小雪插件https://gitee.com/XueWerY/xiaoxue-plugin
//2023年4月18日11:28:32
//头衔设置回复模板 可自行增添删改,注意格式。
let TitleTemplete = [["你好呀!", ""], ["很高兴认识你!", ""], ["原来是", ",失敬失敬!"], ["头衔设置", "成功啦!"], ["你就是大名鼎鼎的", ""],]
//头衔匹配正则 不喜欢可自行增添删改。
let reg = "^#?(我要|(给|赐|赠|赏|送)(我|咱|朕|俺|愚|私|吾|鄙|敝|卑|爹|娘|爸|妈|爷|奶|哥|姐|弟|妹))?头衔"
let regex = new RegExp(reg)
let random = 0
export class Givetitle extends plugin {
constructor() {
super({
name: '给头衔',
dsc: '给群成员一个头衔',
event: 'message',
priority: 233,
rule: [
{
reg: `${reg}.{1,30}$`,
fnc: 'giveTitle'
},
{
reg: '^#?(我不要|取消|撤销|删除)头衔了?$',
fnc: 'delTitle'
}
]
})
}
/**
* 获取头衔关键词
*/
async getTitleKeyMain(e) {
/** 判断消息内容是否非法 */
let message = e.message
for (let i in message) {
/** 判断消息中是否有除了文字以外的东西 */
/** 如果有就返回假 */
if (message[i].type !== 'text') {
await this.reply('请不要发除文字以外的东西啦~', true)
return false
}
}
/** 没有再截取头衔关键词 */
return true
}
/**
* 给头衔
*/
async giveTitleMain(e, title) {
if (title == "") returntou
if (e.group.is_owner) {
let len = 0, p = 0
if (title.length >= 6) {
while (p < title.length) {
if (title[p].search(/[\u4e00-\u9fa5]/i) + 1)
len += 3
else
len++
if (len > 18) {
title = title.slice(0, p) + ""
break
}
p++
}
}
e.group.setTitle(e.sender.user_id, title)
random = (random + Math.floor(Math.random() * (TitleTemplete.length - 1)) + 1) % TitleTemplete.length
title = TitleTemplete[random][0] + title + TitleTemplete[random][1]
if (len > 18) title += "\n你要的头衔太长了~专属头衔最多六个汉字或者18个字母哦"
await this.reply(`${title}`, true, { at: false })
return true
}
else {
await this.reply(`抱歉啦~群主才可以设置专属头衔哦~`, false, { at: false })
return true
}
}
async giveTitle(e) {
if (this.getTitleKeyMain(e)) {
let title = e.msg.replace(regex, "")
return this.giveTitleMain(e, title)
}
}
/**
* 撤销头衔
*/
async delTitle(e) {
if (e.group.is_owner) {
await e.group.setTitle(e.sender.user_id, '')
await this.reply('头衔撤销成功啦~', true, { at: true })
} else {
await this.reply(`抱歉啦~群主才可以撤销专属头衔哦~`, false, { at: false })
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/CUZNIL/Yunzai-giveTitle.git
git@gitee.com:CUZNIL/Yunzai-giveTitle.git
CUZNIL
Yunzai-giveTitle
云崽Bot头衔插件.js
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891