From ee931978758f819eed9bf8865b44974857ae26a8 Mon Sep 17 00:00:00 2001 From: Sad Date: Mon, 26 Feb 2024 04:20:30 +0800 Subject: [PATCH 1/2] add __checkUserRole userrole --- modules/discord_bot.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/discord_bot.js b/modules/discord_bot.js index d588a5b2..6cc59d61 100644 --- a/modules/discord_bot.js +++ b/modules/discord_bot.js @@ -1314,6 +1314,11 @@ function multiServerTarget(message) { } function __checkUserRole(groupid, message) { + /** + * 1 - 一般使用者 + * 2 - 頻道管理員 + * 3 - 群組管理員 + */ try { if (groupid && message.member && message.member.permissions.has(PermissionsBitField.Flags.Administrator)) return 3; From b9a87a42b69b6f6eab72177c0bac014bb0770dad Mon Sep 17 00:00:00 2001 From: Sad Date: Mon, 26 Feb 2024 05:21:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20admin=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E7=9C=8B=E5=88=B0=E6=95=B4=E5=80=8Bserver=20=E7=9A=84?= =?UTF-8?q?cron=20=E5=92=8Cat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roll/z_schedule.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/roll/z_schedule.js b/roll/z_schedule.js index b0274a86..ef5c5f25 100644 --- a/roll/z_schedule.js +++ b/roll/z_schedule.js @@ -117,7 +117,7 @@ const rollDiceCommand = async function ({ return rply } let check = {} - if (botname == "Discord") { + if (botname == "Discord" && userrole < 3) { check = { name: differentPeformAt(botname), "data.channelid": channelid, @@ -131,6 +131,18 @@ const rollDiceCommand = async function ({ check ).catch(error => console.error('agenda error: ', error.name, error.reson)) rply.text = showJobs(jobs); + if (userrole == 3 && botname == "Discord") { + rply.text = `\n本頻道列表\n\n${rply.text}` + check = { + name: differentPeformAt(botname), + "data.groupid": groupid + } + const jobs = await agenda.agenda.jobs( + check + ).catch(error => console.error('agenda error: ', error.name, error.reson)) + rply.text = `本群組列表\n\n${showJobs(jobs)} \n\n${rply.text + } `; + } return rply; } case /^\.at+$/i.test(mainMsg[0]) && /^delete$/i.test(mainMsg[1]): { @@ -144,7 +156,7 @@ const rollDiceCommand = async function ({ return rply } let check = {} - if (botname == "Discord") { + if (botname == "Discord" && userrole < 3) { check = { name: differentPeformAt(botname), "data.channelid": channelid, @@ -233,7 +245,7 @@ const rollDiceCommand = async function ({ } let check = {} - if (botname == "Discord") { + if (botname == "Discord" && userrole < 3) { check = { name: differentPeformCron(botname), "data.channelid": channelid, @@ -247,6 +259,18 @@ const rollDiceCommand = async function ({ check ).catch(error => console.error('agenda error: ', error.name, error.reson)) rply.text = showCronJobs(jobs); + if (userrole == 3 && botname == "Discord") { + rply.text = `\n本頻道列表\n\n${rply.text}` + check = { + name: differentPeformCron(botname), + "data.groupid": groupid + } + const jobs = await agenda.agenda.jobs( + check + ).catch(error => console.error('agenda error: ', error.name, error.reson)) + rply.text = `本群組列表\n\n${showCronJobs(jobs)} \n\n${rply.text + } `; + } return rply; } case /^\.cron$/i.test(mainMsg[0]) && /^delete$/i.test(mainMsg[1]): { @@ -263,13 +287,14 @@ const rollDiceCommand = async function ({ return rply } let check = {} - if (botname == "Discord") { + if (botname == "Discord" && userrole < 3) { check = { name: differentPeformCron(botname), "data.channelid": channelid, "data.groupid": groupid } - } else check = { + } + else check = { name: differentPeformCron(botname), "data.groupid": groupid } @@ -279,7 +304,7 @@ const rollDiceCommand = async function ({ try { let data = jobs[Number(mainMsg[2]) - 1]; await jobs[Number(mainMsg[2]) - 1].remove(); - rply.text = `已刪除序號#${Number(mainMsg[2])} \n${data.attrs.data.replyText}`; + rply.text = `已刪除序號#${Number(mainMsg[2])} \n${data.attrs.data.replyText} `; } catch (e) { console.error("Remove Cron Error removing job from collection, input: ", inputStr); @@ -317,7 +342,7 @@ const rollDiceCommand = async function ({ let checkTime = checkCronTime(mainMsg[1]); if (!checkTime || !checkTime.min || !checkTime.hour) { - rply.text = `輸入出錯\n ${this.getHelpMessage()}`; + rply.text = `輸入出錯\n ${this.getHelpMessage()} `; return rply; } if (roleName.roleName || roleName.imageLink) {