diff --git a/README.md b/README.md index d797166..803d60b 100644 --- a/README.md +++ b/README.md @@ -84,11 +84,12 @@ Create a file called `config.json` in the project directory with the contents: { "prefix":"!mark", "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 diff --git a/index.ts b/index.ts index f02a3e4..c74a539 100644 --- a/index.ts +++ b/index.ts @@ -34,6 +34,7 @@ interface MarkbotConfig { prefix?: string; game?: string; token?: string; + role?: string; } 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 connected = -1; let GAME = '!mark help'; +let ROLE: string | null; let PREFIX = '!mark'; let STATE_SIZE = 2; // Value of 1 to 3, based on corpus quality let MAX_TRIES = 1000; @@ -147,6 +149,7 @@ function loadConfig(): void { STATE_SIZE = cfg.stateSize || STATE_SIZE; MIN_SCORE = cfg.minScore || MIN_SCORE; MAX_TRIES = cfg.maxTries || MAX_TRIES; + ROLE = cfg.role || null; } catch (e) { console.warn('Failed to read config.json.'); token = process.env.TOKEN || token; @@ -366,7 +369,15 @@ client.on('message', message => { } } 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') { generateResponse(message, false, true);