Skip to content

Commit

Permalink
Merge pull request #721 from hktrpg/cron-and-at-admin-list
Browse files Browse the repository at this point in the history
Cron and at admin list
  • Loading branch information
zeteticl authored Feb 25, 2024
2 parents de2da5d + b9a87a4 commit 185e053
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions modules/discord_bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 32 additions & 7 deletions roll/z_schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]): {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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]): {
Expand All @@ -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
}
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 185e053

Please sign in to comment.