-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregulars.js
67 lines (61 loc) · 1.99 KB
/
regulars.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const database = require('./database.js');
const functions = require('./functions.js');
class Regulars {
async call(props) {
if (props.messageParams[1] === 'add') {
return this.add(props);
} else if (props.messageParams[1] === 'remove' || props.messageParams[1] === 'delete') {
return this.remove(props);
}
}
async checkIfUserIsRegular(props) {
const propsForSelect = {
table: 'regulars',
query: {channel: props.channel, username: props.userstate.username}
};
const results = await database.select(propsForSelect);
if (results) {
return true;
}
return false;
}
async add(props) {
props.ignoreMessageParamsForUserString = true;
const propsForSelect = {
table: 'regulars',
query: {channel: props.channel, username: props.messageParams[2]}
};
const results = await database.select(propsForSelect);
if (results) {
return functions.buildUserString(props) + props.messageParams[2] + ' is already a regular!';
}
const regularToAdd = props.messageParams[2];
const dataToUse = {};
dataToUse.username = regularToAdd.toLowerCase();
dataToUse.channel = props.channel;
const propsForAdd = {
table: 'regulars',
dataToUse
};
await database.add(propsForAdd);
return functions.buildUserString(props) + props.messageParams[2] + ' has been added as a regular!';
}
async remove(props) {
props.ignoreMessageParamsForUserString = true;
const propsForSelect = {
table: 'regulars',
query: {channel: props.channel, username: props.messageParams[2].toLowerCase()}
};
const results = await database.select(propsForSelect);
if (results) {
const propsForDelete = {
table: 'regulars',
query: {channel: props.channel, username: props.messageParams[2].toLowerCase()}
};
await database.delete(propsForDelete);
return functions.buildUserString(props) + props.messageParams[2] + ' has been removed as a regular!';
}
return functions.buildUserString(props) + props.messageParams[2] + ' isn\'t a regular!';
}
}
module.exports = new Regulars();