Merge pull request #19 from sokolas/master

Restrict "respond" action based on roles (optional)
This commit is contained in:
Charlie Laabs
2021-07-12 13:05:28 -05:00
committed by GitHub
2 changed files with 15 additions and 3 deletions

View File

@@ -84,11 +84,12 @@ Create a file called `config.json` in the project directory with the contents:
{ {
"prefix":"!mark", "prefix":"!mark",
"game":"\"!mark help\" for help", "game":"\"!mark help\" for help",
"token":"k5NzE2NDg1MTIwMjc0ODQ0Nj.DSnXwg.ttNotARealToken5p3WfDoUxhiH" "token":"k5NzE2NDg1MTIwMjc0ODQ0Nj.DSnXwg.ttNotARealToken5p3WfDoUxhiH",
"role": "Bot users"
} }
``` ```
Feel free to change the command prefix, game display. Add your bot token. Feel free to change the command prefix, game display. Add your bot token. Role is optional, if it is set, only the users who have that role can use text generation.
#### Install and Run #### Install and Run

View File

@@ -34,6 +34,7 @@ interface MarkbotConfig {
prefix?: string; prefix?: string;
game?: string; game?: string;
token?: string; token?: string;
role?: string;
} }
const version: string = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version || '0.0.0'; const version: string = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version || '0.0.0';
@@ -46,6 +47,7 @@ const PAGE_SIZE = 100;
// let guilds = []; // let guilds = [];
// let connected = -1; // let connected = -1;
let GAME = '!mark help'; let GAME = '!mark help';
let ROLE: string | null;
let PREFIX = '!mark'; let PREFIX = '!mark';
let STATE_SIZE = 2; // Value of 1 to 3, based on corpus quality let STATE_SIZE = 2; // Value of 1 to 3, based on corpus quality
let MAX_TRIES = 1000; let MAX_TRIES = 1000;
@@ -147,6 +149,7 @@ function loadConfig(): void {
STATE_SIZE = cfg.stateSize || STATE_SIZE; STATE_SIZE = cfg.stateSize || STATE_SIZE;
MIN_SCORE = cfg.minScore || MIN_SCORE; MIN_SCORE = cfg.minScore || MIN_SCORE;
MAX_TRIES = cfg.maxTries || MAX_TRIES; MAX_TRIES = cfg.maxTries || MAX_TRIES;
ROLE = cfg.role || null;
} catch (e) { } catch (e) {
console.warn('Failed to read config.json.'); console.warn('Failed to read config.json.');
token = process.env.TOKEN || token; token = process.env.TOKEN || token;
@@ -366,7 +369,15 @@ client.on('message', message => {
} }
} }
if (command === 'respond') { if (command === 'respond') {
generateResponse(message); let send = true;
if (ROLE != null) {
let roles = message.member?.roles.cache.map(role => role.name);
send = roles?.includes(ROLE) || false;
}
if (send) {
generateResponse(message);
}
} }
if (command === 'tts') { if (command === 'tts') {
generateResponse(message, false, true); generateResponse(message, false, true);