mirror of
https://github.com/pacnpal/markov-discord.git
synced 2025-12-20 11:01:04 -05:00
Merge pull request #19 from sokolas/master
Restrict "respond" action based on roles (optional)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
11
index.ts
11
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,8 +369,16 @@ client.on('message', message => {
|
||||
}
|
||||
}
|
||||
if (command === 'respond') {
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user