diff --git a/.gitignore b/.gitignore index 0001524..55494c8 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,5 @@ crashlytics-build.properties # Created by .ignore support plugin (hsz.mobi) config.js + +sql_init.js \ No newline at end of file diff --git a/bot.js b/bot.js index 802bd91..a3611d9 100644 --- a/bot.js +++ b/bot.js @@ -4,44 +4,43 @@ var fs = require('fs'); var config = require('./lib/load_config.js'); var langfile = require('./langfile.js'); +var plugged = require('./lib/client'); +var redis = require('./lib/db/redis_db'); var story = storyboard.mainStory; -storyboard.config({filter: '*:' + config.options.loglevel}); -storyboard.mainStory.info('Starting plugbot version ' + require('./package.json').version); +storyboard.config({filter: `*:${config.options.loglevel}`}); +storyboard.addListener(require('storyboard/lib/listeners/console').default); +story.info(`Starting plugbot version ${require('./package.json').version}`); moment.locale(langfile.moment_locale); -var plugged = require('./lib/client'); -var redis = require('./lib/db/redis_db'); -var db = require('./lib/db/sql_db'); - //noinspection JSUnresolvedFunction redis.del('user:roles'); -redis.exists('meta:data:staff:active').then(function (ex) { +redis.exists('meta:data:staff:active').then(ex => { if (ex === 0) redis.set('meta:data:staff:active', 1); }); -fs.readdir('./lib/eventhandlers', function (err, files) { +fs.readdir('./lib/eventhandlers', (err, files) => { if (err) { story.fatal('Cannot load eventhandlers.', {attach: err}); process.exit(1); } else { - files.forEach(function (file) { + files.forEach(file => { try { - var h = require('./lib/eventhandlers/' + file); + var h = require(`./lib/eventhandlers/${file}`); if (Array.isArray(h.event)) { - h.event.forEach(function (event) { + h.event.forEach(event => { plugged.on(event, h.handler); }); } else plugged.on(h.event, h.handler); - story.debug('EventHandlers', 'Loaded Handler for Event ' + (Array.isArray(h.event) ? h.event.join() : h.event)); + story.debug('EventHandlers', `Loaded Handler for Event ${Array.isArray(h.event) ? h.event.join() : h.event}`); } catch (e) { - story.error('Failed to load eventhandler ' + file, {attach: e}); + story.error(`Failed to load eventhandler ${file}`, {attach: e}); process.exit(1); } }); } }); -module.exports = {plugged: plugged, app: (config.web.enabled ? require('./web/index').app : null)}; +module.exports = {plugged, app: (config.web.enabled ? require('./web/index').app : null)}; diff --git a/config.example.js b/config.example.js index b727cfc..1e5c11e 100644 --- a/config.example.js +++ b/config.example.js @@ -116,6 +116,7 @@ module.exports = { titleguard: { enabled: true, not_contain: ['big dick'], + regex_match: null, lockskip: false }, playlists: { @@ -174,6 +175,7 @@ module.exports = { }, userfilter: { enabled: false, - username_disallowed: [] + username_disallowed: [], + regex:null } }; \ No newline at end of file diff --git a/docs/commands.md b/docs/commands.md index bb901cc..b4e4a16 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -2,105 +2,106 @@ ## User Commands -|Command|Alias|Arguments|Description| -|---|---|---|---| -|!link| | |Gives a link to the current song| -|!define| |(word)|Defines the given word| -|!songinfo|!sinfo|[format:cid / media-url]|Gives information about the song| -|!catfact|!catfacts| |Gives a catfact| -|!join| | |Joins an open roulette| -|!leave| | |Leaves an open roulette| -|!disconnected|!dc| |Places you back in the waitlist if you lost your spot| +|Command|Alias|Arguments|Flags|Description| +|---|---|---|---|---| +|!link| | | |Gives a link to the current song| +|!define| | |(word)|Defines the given word| +|!songinfo|!sinfo|[format:cid / media-url]| |Gives information about the song| +|!catfact|!catfacts| | |Gives a catfact| +|!join| | | |Joins an open roulette| +|!leave| | | |Leaves an open roulette| +|!disconnected|!dc| | |Places you back in the waitlist if you lost your spot| ## RDj Commands RDj commands include user commands -|Command|Alias|Arguments|Description| -|---|---|---|---| -|!demote| | |Removes you as staff| -|!promote| | |Adds you back as staff| -|!ping| | |Pong!| -|!skip|!fs| |Votes for skip| -|!uptime| | |Displays uptime| -|!next| | |Gives the next song on the bot's playlist| +|Command|Alias|Arguments|Flags|Description| +|---|---|---|---|---| +|!demote| | | |Removes you as staff| +|!promote| | | |Adds you back as staff| +|!ping| | | |Pong!| +|!skip|!fs| | |Votes for skip| +|!uptime| | | |Displays uptime| +|!next| | | |Gives the next song on the bot's playlist| ## Bouncer Commands Bouncer commands include Rdj commands -|Command|Alias|Arguments|Description| -|---|---|---|---| -|!skip|!fs|[reason]|Skips the current song and sends an optional reason.| -|!lockskip|!ls|[reason]|Skips the current songs, moves the dj back and sends an optional reason| -|!blacklist|!bl|[reason]|Skips the curent song, adds it to the blacklist and sends an optional reason| -|!idblacklist|!idbl|(format:cid)[reason]|Adds the given media to the blacklist with the given, optional reason| -|!cycleskip|!cs|[reason]|Disables the DJ-Cycle, skips the current song and sends an optional reason| -|!remove|!rm/!rem/!rmwl|(@user)|Removes the given user from the waitlist| -|!delchat| |[@user]|Deletes every chat message or removes messages from the given user| -|!kick| |(@user)|Kicks the given user| -|!mute| |(@user)|Mutes the given user| -|!joinwl| | |Let's the bot join the waitlist| -|!leavewl| | |Let's the bot leave the waitlist| -|!state| | |Gives the current settings| -|!wlban| |(@user)|Bans the given user from the waitlist| -|!shuffleplaylist|!shufflepl| |Shuffles the bot's playlist| +|Command|Alias|Arguments|Flags|Description| +|---|---|---|---|---| +|!skip|!fs|[reason]| |Skips the current song and sends an optional reason.| +|!lockskip|!ls|[reason]| |Skips the current songs, moves the dj back and sends an optional reason| +|!blacklist|!bl|[reason]| |Skips the curent song, adds it to the blacklist and sends an optional reason| +|!idblacklist|!idbl|(format:cid)[reason]| |Adds the given media to the blacklist with the given, optional reason| +|!cycleskip|!cs|[reason]| |Disables the DJ-Cycle, skips the current song and sends an optional reason| +|!remove|!rm/!rem/!rmwl|(@user)| |Removes the given user from the waitlist| +|!delchat| |[@user]| |Deletes every chat message or removes messages from the given user| +|!kick| |(@user)| |Kicks the given user| +|!mute| |(@user)| |Mutes the given user| +|!joinwl| | | |Let's the bot join the waitlist| +|!leavewl| | | |Let's the bot leave the waitlist| +|!state| | | |Gives the current settings| +|!wlban| |(@user)| |Bans the given user from the waitlist| +|!shuffleplaylist|!shufflepl| | |Shuffles the bot's playlist| ## Bouncer+ Commands These commands are only available for bouncers when bouncer+ is enabled. -|Command|Alias|Arguments|Description| -|---|---|---|---| -|!add|!addwl|(@user)|Adds the given user to the waitlist| -|!move|!mv|(@user)(position)|Moves the given user to the given position| -|!unblacklist|!unbl/!rmbl|(format:cid / media-url)|Removes the given song from the blacklist| -|!unmute| |(@user)|Unmutes the given user| -|!wlunban| |(@user)|Unbans the given user from the waitlist| -|!cleanwl| | |Clears and rebuilds the waitlist to remove ghost users| -|!lock| | |Locks the waitlist| -|!unlock| | |Unlocks the waitlist| -|!cycle| | |Toggles the DJ cycle| -|!clear|!clearwl| |Locks and clears the waitlist| -|!historyskip| | |Toggles historyskip| -|!voteskip| | |Toggles voteskip| -|!timeguard| | |Toggles timeguard| -|!cleverbot| | |Toggles cleverbot| -|!eventmode| |[-c/-l/-u][-dc/-ec]|Toggles eventmode| -|!lockdown| | |Toggles lockdown| -|!dcmoveback| | |Toggles DCMoveback| -|!chatfilter| | |Toggles chatfilter| -|!filterreset| |(@user)|Resets all chatfilterscores for the given user| -|!clearhistory| | |Clears the songhistory| -|!removehistory|!rmh|(format:cid / media-url)|Removes the given media from the history| -|!reloadblacklist|!reloadbl| |Reloads the blacklist from the database| -|!reloadroles| | |Reloads all roles from the database| -|!reloadcustomcommands|!reloadcc| |Reloads all CustomCommands from the database| -|!lockskippos|!lspos|(position)|Sets the position for lockskip| -|!chatlevel|!chatlvl/!clvl|(level)|Sets the room chat level to the given level| -|!youtubeguard|!ytguard| |Toggles YouTubeGuard| -|!soundcloudguard|!scguard| |Toggles SoundCloudGuard| -|!titleguard| | |Toggles TitleGuard| -|!togglecustomcommands|!togglecc| |Toggles CustomCommands| -|!customcommands|!cc|add(trigger)(message)/enable(trigger)/disable(trigger)/senderenable(trigger)/senderdisable(trigger)|Edits a CustomCommand| -|!woot|!w|[-s/-d]|Let's the bot woot. Use -s to save the vote| -|!meh|!m|[-s/-d]|Let's the bot meh. Use -s to save the vote| -|!lottery| |[time]|Starts a lottery| -|!roulette| |(moves)[time]|Starts a roulette| -|!everyone| |[msg]|Mentions everyone| -|!toggleafk| | |Toggles AFKRemoval| -|!channelblacklist|!cbl|add (cid)/rem (cid)/toggle|Adds/Removes a whole youtube channel from the blacklist/toggles the channelblacklist| +|Command|Alias|Arguments|Flags|Description| +|---|---|---|---|---| +|!add|!addwl|(@user)| |Adds the given user to the waitlist| +|!move|!mv|(@user)(position)| |Moves the given user to the given position| +|!swap| |(@user)(@user)|-nl|Swap the waitlist-positions of the specified users. -nl will prevent waitlsit-locking| +|!unblacklist|!unbl/!rmbl|(format:cid / media-url)| |Removes the given song from the blacklist| +|!unmute| |(@user)| |Unmutes the given user| +|!wlunban| |(@user)| |Unbans the given user from the waitlist| +|!cleanwl| | | |Clears and rebuilds the waitlist to remove ghost users| +|!lock| | | |Locks the waitlist| +|!unlock| | | |Unlocks the waitlist| +|!cycle| | | |Toggles the DJ cycle| +|!clear|!clearwl| | |Locks and clears the waitlist| +|!historyskip| | | |Toggles historyskip| +|!voteskip| | | |Toggles voteskip| +|!timeguard| | | |Toggles timeguard| +|!cleverbot| | | |Toggles cleverbot| +|!eventmode| | |[-c/-l/-u][-dc/-ec]|Toggles eventmode| +|!lockdown| | | |Toggles lockdown| +|!dcmoveback| | | |Toggles DCMoveback| +|!chatfilter| | | |Toggles chatfilter| +|!filterreset| |(@user)| |Resets all chatfilterscores for the given user| +|!clearhistory| | | |Clears the songhistory| +|!removehistory|!rmh|(format:cid / media-url)| |Removes the given media from the history| +|!reloadblacklist|!reloadbl| | |Reloads the blacklist from the database| +|!reloadroles| | | |Reloads all roles from the database| +|!reloadcustomcommands|!reloadcc| | |Reloads all CustomCommands from the database| +|!lockskippos|!lspos|(position)| |Sets the position for lockskip| +|!chatlevel|!chatlvl/!clvl|(level)| |Sets the room chat level to the given level| +|!youtubeguard|!ytguard| | |Toggles YouTubeGuard| +|!soundcloudguard|!scguard| | |Toggles SoundCloudGuard| +|!titleguard| | | |Toggles TitleGuard| +|!togglecustomcommands|!togglecc| | |Toggles CustomCommands| +|!customcommands|!cc|add(trigger)(message)/ enable(trigger)/ disable(trigger)/ senderenable(trigger)/ senderdisable(trigger)| |Edits a CustomCommand| +|!woot|!w| |[-s/-d]|Let's the bot woot. Use -s to save the vote| +|!meh|!m| |[-s/-d]|Let's the bot meh. Use -s to save the vote| +|!lottery| |[time]| |Starts a lottery| +|!roulette| |(moves)[time]| |Starts a roulette| +|!everyone| |[msg]| |Mentions everyone| +|!toggleafk| | | |Toggles AFKRemoval| +|!channelblacklist|!cbl|add (cid)/rem (cid)/toggle| |Adds/Removes a whole youtube channel from the blacklist/toggles the channelblacklist| ## Manager Commands Manager commands include bouncer and bouncer+ commands -|Command|Alias|Arguments|Description| -|---|---|---|---| -|!setstaff| |(role)(@user)|Sets the given user to the given role| -|!bouncer+| | |Toggles bouncer+| -|!welcomemsg| | |Sets the room welcome message| -|!roomname| | |Sets the roomname| -|!superuser|!su|(@user)|Sets the given user as superuser| -|!restart| | |Restarts the bot| -|!clearghosts| | |Clears ghost-users from the community. Use with care, may result in a ban for the bot| +|Command|Alias|Arguments|Flags|Description| +|---|---|---|---|---| +|!setstaff| |(role)(@user)| |Sets the given user to the given role| +|!bouncer+| | | |Toggles bouncer+| +|!welcomemsg| | | |Sets the room welcome message| +|!roomname| | | |Sets the roomname| +|!superuser|!su|(@user)| |Sets the given user as superuser| +|!restart| | |-n|Restarts the bot| +|!clearghosts| | | |Clears ghost-users from the community. Use with care, may result in a ratelimit-ban for the bot| () = required argument diff --git a/docs/config.md b/docs/config.md index d26b65a..3e7d64b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -56,6 +56,8 @@ |titleguard|object|settings for titleguard| |titleguard.enabled|boolean|Sets the default value for titleguard| |titleguard.not_contain|array[string]|Words titles are forbidden to contain| +|titleguard.regex_match|RegEx|Regular expression to test against. Set to null to disable this| +|titleguard.lockskip|boolean|Enables lockskip if titleguard is triggerd| |playlists.play|number|A playlist-id for the bot to play when in the waitlist| |playlists.none|number|A playlist-id for the bot to activate when not in waitlist to avoid being acidentially added| |afk|object|Settings for the afk-function| @@ -80,4 +82,8 @@ |web.useUWS|boolean|Enable this to use a more performant websocket-library which requires a c++-compiler on you machine. Disable it, if your bot throws an error at startup concerning uWebsocket| |web.path|string|the path the api runs under| |defaultCC|object|Contains multiple objects with default customcommands, see config.example.js for their properties| +|userfilter|object|Settings for the userfilter| +|userfilter.enabled|boolean|Enables the userfilter| +|userfilter.username_disallowed|array[string]|array of disallowed usernames| +|userfilter.regex|RegEx|RegEx to test usernames. Triggers the filter when a match is found. Set to null to disable| diff --git a/docs/database.md b/docs/database.md new file mode 100644 index 0000000..b0131a2 --- /dev/null +++ b/docs/database.md @@ -0,0 +1,3 @@ +## Database + +Unfortunately, the used ORM has a little bug which prevents it from creating the database correctly. To initialize it, run install.sql if you are using mysql/mariadb on the created database and you should be good. \ No newline at end of file diff --git a/docs/install.sql b/docs/install.sql new file mode 100644 index 0000000..fd68871 --- /dev/null +++ b/docs/install.sql @@ -0,0 +1,112 @@ +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET NAMES utf8 */; +/*!50503 SET NAMES utf8mb4 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; + +CREATE TABLE IF NOT EXISTS `channels` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) DEFAULT NULL, + `cid` varchar(161) NOT NULL DEFAULT '', + `is_banned` tinyint(1) DEFAULT '0', + `ban_reason` text, + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + PRIMARY KEY (`cid`), + UNIQUE KEY `id` (`id`), + UNIQUE KEY `channels_id_unique` (`id`), + UNIQUE KEY `cid` (`cid`), + UNIQUE KEY `channels_cid_unique` (`cid`) +) ENGINE=InnoDB AUTO_INCREMENT=1037 DEFAULT CHARSET=utf8mb4; + +CREATE TABLE IF NOT EXISTS `customcommands` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `trigger` varchar(191) NOT NULL, + `message` varchar(255) NOT NULL, + `status` tinyint(1) NOT NULL DEFAULT '1', + `senderinfo` tinyint(1) NOT NULL DEFAULT '1', + `allowMention` tinyint(1) NOT NULL DEFAULT '1', + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `id` (`id`), + UNIQUE KEY `trigger` (`trigger`), + UNIQUE KEY `customcommands_id_unique` (`id`), + UNIQUE KEY `customcommands_trigger_unique` (`trigger`) +) ENGINE=InnoDB AUTO_INCREMENT=74 DEFAULT CHARSET=utf8mb4; + +CREATE TABLE IF NOT EXISTS `plays` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `woots` int(10) unsigned DEFAULT '0', + `grabs` int(10) unsigned DEFAULT '0', + `mehs` int(10) unsigned DEFAULT '0', + `listeners` int(10) unsigned DEFAULT '0', + `time` datetime DEFAULT NULL, + `skipped` tinyint(1) DEFAULT '0', + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + `song_plug_id` int(10) unsigned DEFAULT NULL, + `user_id` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `id` (`id`), + UNIQUE KEY `plays_id_unique` (`id`), + KEY `song_plug_id` (`song_plug_id`), + KEY `user_id` (`user_id`), + CONSTRAINT `plays_ibfk_1` FOREIGN KEY (`song_plug_id`) REFERENCES `songs` (`plug_id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `plays_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=3999 DEFAULT CHARSET=utf8mb4; + +CREATE TABLE IF NOT EXISTS `songs` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `author` varchar(255) DEFAULT NULL, + `title` varchar(255) DEFAULT NULL, + `slug` varchar(255) DEFAULT NULL, + `format` int(10) unsigned NOT NULL, + `cid` varchar(20) NOT NULL, + `plug_id` int(10) unsigned NOT NULL, + `duration` int(10) unsigned DEFAULT NULL, + `image` varchar(255) DEFAULT NULL, + `is_banned` tinyint(1) DEFAULT '0', + `ban_reason` text, + `tskip` int(10) unsigned DEFAULT NULL, + `autovote` enum('n','w','m') NOT NULL DEFAULT 'n', + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + PRIMARY KEY (`plug_id`), + UNIQUE KEY `id` (`id`), + UNIQUE KEY `cid` (`cid`), + UNIQUE KEY `plug_id` (`plug_id`), + UNIQUE KEY `songs_id_unique` (`id`), + UNIQUE KEY `songs_cid_unique` (`cid`), + UNIQUE KEY `songs_plug_id_unique` (`plug_id`) +) ENGINE=InnoDB AUTO_INCREMENT=442 DEFAULT CHARSET=utf8mb4; + +CREATE TABLE IF NOT EXISTS `users` ( + `id` int(10) unsigned NOT NULL DEFAULT '0', + `username` varchar(255) NOT NULL, + `language` varchar(255) DEFAULT 'en', + `avatar_id` varchar(255) DEFAULT NULL, + `badge` varchar(255) DEFAULT NULL, + `blurb` text, + `global_role` int(10) unsigned DEFAULT '0', + `role` int(10) unsigned DEFAULT '0', + `super_user` tinyint(1) DEFAULT '0', + `s_role` int(10) unsigned DEFAULT '0', + `level` int(10) unsigned DEFAULT '0', + `custom_points` int(10) unsigned DEFAULT '0', + `joined` datetime DEFAULT NULL, + `birthday` datetime DEFAULT NULL, + `status` tinyint(1) DEFAULT '1', + `afk_msg` text, + `last_seen` datetime DEFAULT NULL, + `last_active` datetime DEFAULT NULL, + `afk_level` enum('active','afk','warned','warned2') NOT NULL DEFAULT 'active', + `wl_removes` int(10) unsigned DEFAULT NULL, + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; +/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; diff --git a/langfile.js b/langfile.js index 5d00326..904b32b 100644 --- a/langfile.js +++ b/langfile.js @@ -91,9 +91,14 @@ module.exports = { error: '[&{mod}: Kick] You can\'t kick that user.' }, ban: { - default: '[&{mod}: Banned &{username}]', + default: '[&{mod}: Banned &{username}&{duration}]', no_staff_ban: '@&{username}, please let our staff decide, who should be permanently banned. (Duration changed to 1 day)', - staff_ban: '@&{username}, you are not allowed to ban staff memebers. Remove them from the staff list before baning.' + staff_ban: '@&{username}, you are not allowed to ban staff memebers. Remove them from the staff list before baning.', + duration: { + h: ' for one hour', + d: ' for one day', + f: ' permanently' + } }, setstaff: { default: '[&{mod}: Set &{username} as &{role}]', @@ -136,7 +141,7 @@ module.exports = { language: { warn: '@&{username}, please have look at our rules. You are speaking the wrong language!' }, - link:{ + link: { warn: '@&{username}, please stop sending these links.', mute: '@&{username} didn\'t stop to send links, now he can\'t...' } @@ -190,9 +195,9 @@ module.exports = { youtubeGuard: { skip: '/me [YouTubeGuard]', api_unreachable: '@staff, I couldn\'t reach YouTube to check the avability of the current song. Please check.', - block:'@&{username}, YouTube is currently blocked in this room.', - block_enabled:'[&{username}: YouTubeBlock enabled]', - block_disabled:'[&{username}: YouTubeBlock disabled]', + block: '@&{username}, YouTube is currently blocked in this room.', + block_enabled: '[&{username}: YouTubeBlock enabled]', + block_disabled: '[&{username}: YouTubeBlock disabled]', blocked: { default: '@&{username}, your song "&{song}" was automatically added to the blacklist because it\'s blocked in the following countries: "&{countries}"', bl_reason: 'Blocked in the following countries: &{countries}' @@ -224,8 +229,8 @@ module.exports = { default: '@&{username}, your song "&{song}" was automatically added to the blacklist because it\'s set as not embeddable on plug.dj.', bl_reason: 'Video not embeddable' }, - ytUnavailable:{ - default:'@&{username}, YouTube seems to be unavailable. Your song "&{song}" has therefore be skipped.' + ytUnavailable: { + default: '@&{username}, YouTube seems to be unavailable. Your song "&{song}" has therefore be skipped.' }, enabled: '[&{username}: YouTubeGuard enabled]', disabled: '[&{username}: YouTubeGuard disabled]' @@ -233,9 +238,9 @@ module.exports = { soundcloudGuard: { skip: '/me [SoundCloudGuard]', api_unreachable: '@staff, I couldn\'t reach SoundCloud to check the avability of the current song. Please check.', - block:'@&{username}, SoundCloud is currently blocked in this room.', - block_enabled:'[&{username}: SoundCloudBlock enabled]', - block_disabled:'[&{username}: SoundCloudBlock disabled]', + block: '@&{username}, SoundCloud is currently blocked in this room.', + block_enabled: '[&{username}: SoundCloudBlock enabled]', + block_disabled: '[&{username}: SoundCloudBlock disabled]', deleted: { default: '@&{username}, your song "&{song}" was automatically added to the blacklist because it has been deleted.', bl_reason: 'Song was deleted.' @@ -402,12 +407,15 @@ module.exports = { clearghosts: { default: '[&{username}: ClearGhosts] We will now be kicking all possible ghost-users out of the room to increase performance for the others. Be sure to have at least used the chat within the 50 hours @everyone' }, - userfilter:{ + userfilter: { enabled: '[&{username}: UserFilter enabled]', disabled: '[&{username}: UserFilter disabled]', username: { warn: '@&{username}, you name doesn\'t fit the room rules. Please change it or you will be banned within 60 seconds.', ban: '@&{username} was banned for using a name against the room rules.' } + }, + staff:{ + default:'[&{username}: @staff ]' } }; \ No newline at end of file diff --git a/lib/addqueue.js b/lib/addqueue.js index f891d6d..d7371d8 100644 --- a/lib/addqueue.js +++ b/lib/addqueue.js @@ -6,36 +6,34 @@ var langfile = require('../langfile'); var utils = require('./utils'); module.exports = { - add: function (uid, pos) { + add: (uid, pos)=> { if (typeof uid === 'object') uid = uid.id; //noinspection JSUnresolvedFunction - return redis.zadd('meta:addqueue', pos - 1, uid).then(function () { - return redis.get('meta:isAddQueueLock').then(function (isLock) { - if ((isLock === '0' || isLock === null) && plugged.isWaitlistLocked() === false) { - plugged.setLock(true, false); - return redis.set('meta:isAddQueueLock', 1); - } else return Promise.resolve(); - }); - }); + return redis.zadd('meta:addqueue', pos - 1, uid).then(() => redis.get('meta:isAddQueueLock').then(isLock => { + if ((isLock === '0' || isLock === null) && plugged.isWaitlistLocked() === false) { + plugged.setLock(true, false); + return redis.set('meta:isAddQueueLock', 1); + } else return Promise.resolve(); + })); }, - wlUpdate: function (waitlist) { + wlUpdate: (waitlist)=> { if (waitlist.length < 50) { - redis.exists('meta:addqueue').then(function (ex) { + redis.exists('meta:addqueue').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.zrange('meta:addqueue', 0, 0, 'WITHSCORES').then(function (result) { + redis.zrange('meta:addqueue', 0, 0, 'WITHSCORES').then(result => { var pos = parseInt(result[1]); var uid = parseInt(result[0]); if (plugged.getUserByID(uid) !== undefined) { plugged.sendChat(utils.replace(langfile.addqueue.default, {username: plugged.getUserByID(uid).username})); - plugged.addToWaitlist(uid, function (err) { + plugged.addToWaitlist(uid, err => { if (!err && pos < 50) { plugged.moveDJ(uid, pos); //noinspection JSUnresolvedFunction - redis.zrem('meta:addqueue', uid).then(function () { - redis.exists('meta:addqueue').then(function (ex) { + redis.zrem('meta:addqueue', uid).then(() => { + redis.exists('meta:addqueue').then(ex => { if (ex === 0) { - redis.get('meta:isAddQueueLock').then(function (isLock) { + redis.get('meta:isAddQueueLock').then(isLock => { if (isLock === '1' && plugged.isWaitlistLocked() === true) { plugged.setLock(false, false); redis.set('meta:isAddQueueLock', 0); diff --git a/lib/afk.js b/lib/afk.js index 0f85d8c..12be780 100644 --- a/lib/afk.js +++ b/lib/afk.js @@ -12,88 +12,72 @@ var redis = require('./db/redis_db'); module.exports = { crons: { - afk: new CronJob('0 */10 * * * *', function () { + afk: new CronJob('0 */10 * * * *', () => { var promise; if (config.afk.enabled) { //noinspection JSUnresolvedFunction - promise = db.models.User.findAll({where: {afk_level: 'warned2', status: true}}).then(function (users) { - users = users.filter(function (user) { - return utils.wlPosition(user.id) !== -1; - }); + promise = db.models.User.findAll({where: {afk_level: 'warned2', status: true}}).then(users => { + users = users.filter(user => utils.wlPosition(user.id) !== -1); var kicks = []; var removes = []; - users.forEach(function (user) { + users.forEach(user => { if (user.wl_removes >= config.afk.kick)kicks.push(user); else removes.push(user); }); - kicks.forEach(function (user) { + kicks.forEach(user => { if (user.s_role > 1) { plugged.sendChat(utils.replace(langfile.afk.kick, {username: user.username})); - plugged.banUser(user.id, plugged.BANDURATION.HOUR, plugged.BANREASON.VIOLATING_COMMUNITY_RULES, function () { - setTimeout(function () { + plugged.banUser(user.id, plugged.BANDURATION.HOUR, plugged.BANREASON.VIOLATING_COMMUNITY_RULES, () => { + setTimeout(() => { plugged.unbanUser(user.id); }, 10000); }); } else removes.push(user); }); plugged.sendChat(utils.replace(langfile.afk.remove, { - usernames: removes.map(function (user) { - return utils.replace(langfile.afk.usernames, {username: user.username}); - }).join('').trim() + usernames: removes.map(user => utils.replace(langfile.afk.usernames, {username: user.username})).join('').trim() })); - removes.forEach(function (user) { + removes.forEach(user => { plugged.removeDJ(user.id); }); //noinspection JSUnresolvedFunction return db.models.User.findAll({where: {afk_level: 'warned', status: true}}); - }).then(function (users) { - users = users.filter(function (user) { - return utils.wlPosition(user.id) !== -1; - }); + }).then(users => { + users = users.filter(user => utils.wlPosition(user.id) !== -1); plugged.sendChat(utils.replace(langfile.afk.warn_2, { - username: users.map(function (user) { - return utils.replace(langfile.afk.usernames, {username: user.username}); - }).join('').trim() + username: users.map(user => utils.replace(langfile.afk.usernames, {username: user.username})).join('').trim() })); - return Promise.all(users.map(function (user) { + return Promise.all(users.map(user => { user.update({afk_level: 'warned2'}); - })).then(function () { - //noinspection JSUnresolvedFunction - return db.models.User.findAll({where: {afk_level: 'afk', status: true}}); - }); - }).then(function (users) { - users = users.filter(function (user) { - return utils.wlPosition(user.id) !== -1; - }); + })).then(() => //noinspection JSUnresolvedFunction + db.models.User.findAll({where: {afk_level: 'afk', status: true}})); + }).then(users => { + users = users.filter(user => utils.wlPosition(user.id) !== -1); plugged.sendChat(utils.replace(langfile.afk.warn_1, { - username: users.map(function (user) { - return utils.replace(langfile.afk.usernames, {username: user.username}); - }).join('').trim() + username: users.map(user => utils.replace(langfile.afk.usernames, {username: user.username})).join('').trim() })); - return Promise.all(users.map(function (user) { + return Promise.all(users.map(user => { user.update({afk_level: 'warned'}); })); }); } else promise = Promise.resolve(); - promise.then(function () { - //noinspection JSUnresolvedFunction - return db.models.User.update({afk_level: 'afk'}, { - where: { - status: true, - last_active: {$lt: moment().subtract(config.afk.time, 'seconds').toDate()} - } - }); - }).catch(function (err) { + promise.then(() => //noinspection JSUnresolvedFunction + db.models.User.update({afk_level: 'afk'}, { + where: { + status: true, + last_active: {$lt: moment().subtract(config.afk.time, 'seconds').toDate()} + } + })).catch(err => { story.error('AFK-Removal', {attach: err}); }); }, null, true), - activestaff: new CronJob('0 */20 * * * *', function () { + activestaff: new CronJob('0 */20 * * * *', () => { var active = 0; var stafflist = plugged.getStaffOnline(); function checkstaff(index) { if (stafflist[index].role > 1) { - redis.get('user:afk:' + stafflist[index].id).then(function (ex) { + redis.get(`user:afk:${stafflist[index].id}`).then(ex => { if (ex === 1) { active = active + 1 } @@ -109,16 +93,16 @@ module.exports = { } }, null, true) }, - isAfk: function (user) { + isAfk: (user)=> { if (typeof user === 'object') user = user.id; - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { //noinspection JSUnresolvedFunction db.models.User.find({ where: { id: user, last_active: {$lt: moment().subtract(config.afk.time, 'seconds').toDate()} } - }).then(function (user) { + }).then(user => { resolve((user !== null && user !== undefined)); }).catch(reject); }); diff --git a/lib/apiConnectors/soundCloud.js b/lib/apiConnectors/soundCloud.js index f442364..b89fa93 100644 --- a/lib/apiConnectors/soundCloud.js +++ b/lib/apiConnectors/soundCloud.js @@ -7,9 +7,9 @@ var langfile = require('../../langfile'); var utils = require('../utils'); module.exports = { - check: function (media) { - return new Promise(function (resolve, reject) { - request.get('https://api.soundcloud.com/tracks/' + media.cid + '?client_id=' + config.apiKeys.soundcloud, function (err, resp) { + check: (media)=> { + return new Promise((resolve, reject) => { + request.get(`https://api.soundcloud.com/tracks/${media.cid}?client_id=${config.apiKeys.soundcloud}`, (err, resp) => { if (!err) { if (resp.statusCode === 404) { resolve([true, { diff --git a/lib/apiConnectors/youTube.js b/lib/apiConnectors/youTube.js index bb987c6..66dd14c 100644 --- a/lib/apiConnectors/youTube.js +++ b/lib/apiConnectors/youTube.js @@ -31,22 +31,21 @@ function checkRegionRestriction(body) { } module.exports = { - getSong: function (media) { - return new Promise(function (resolve, reject) { - request.get('https://www.googleapis.com/youtube/v3/videos?part=contentDetails,status,snippet&id=' + media.cid + '&key=' + config.apiKeys.youtube, function (err, resp, body) { - if (!err) { - if (resp.statusCode === 200) { - body = JSON.parse(body); - if (body.items.length > 0) resolve(body.items[0]); - else reject(new Error('not found')); - } else reject(new Error('Invalid status code')) - } else reject(err) + getSong: (media)=> { + return new Promise((resolve, reject) => { + request.get(`https://www.googleapis.com/youtube/v3/videos?part=contentDetails,status,snippet&id=${media.cid}&key=${config.apiKeys.youtube}`, (err, resp, body) => { + if (err)reject(err); + if (resp.statusCode !== 200)return reject(new Error('Invalid status code')); + + body = JSON.parse(body); + if (body.items.length > 0) resolve(body.items[0]); + else reject(new Error('not found')); }); }); }, - check: function (media) { - return new Promise(function (resolve, reject) { - request.get('https://www.googleapis.com/youtube/v3/videos?part=contentDetails,status&id=' + media.cid + '&key=' + config.apiKeys.youtube, function (error, resp, body) { + check: (media)=> { + return new Promise((resolve, reject) => { + request.get(`https://www.googleapis.com/youtube/v3/videos?part=contentDetails,status&id=${media.cid}&key=${config.apiKeys.youtube}`, (error, resp, body) => { if (!error) { if (resp.statusCode === 200) { body = JSON.parse(body); diff --git a/lib/chatfilters.js b/lib/chatfilters.js index 54545ca..33da83f 100644 --- a/lib/chatfilters.js +++ b/lib/chatfilters.js @@ -14,51 +14,45 @@ var strings = {}; loadChatfilters(); function loadChatfilters() { - fs.readdir(path.resolve(__dirname, 'chatfilters'), function (err, files) { + fs.readdir(path.resolve(__dirname, 'chatfilters'), (err, files) => { if (err) { story.fatal('ChatFilters', 'Cannot load chatfilters', {attach: err}); chatfilters.push(Promise.resolve()); } else { if (files.length === 0) chatfilters.push(Promise.resolve); else { - files.forEach(function (file) { + files.forEach(file => { try { var filter = require(path.resolve(__dirname, 'chatfilters', file)); if (filter.enabled) { chatfilters.push(filter.check); strings[filter.type] = filter.strings; - story.debug('ChatFilters', 'Loaded chatfilter ' + filter.name); - } else story.debug('ChatFilters', 'Skipping ' + filter.name + ' since it\'s disabled.'); + story.debug('ChatFilters', `Loaded chatfilter ${filter.name}`); + } else story.debug('ChatFilters', `Skipping ${filter.name} since it's disabled.`); } catch (e) { story.warn('ChatFilters', 'Failed to load chatfilter.', {attach: e}); } }); } - story.info('ChatFilters', 'Loaded ' + (chatfilters.length) + ' chatfilters.'); + story.info('ChatFilters', `Loaded ${chatfilters.length} chatfilters.`); } }); } module.exports = { filters: chatfilters, - resolveMsg: function (type) { - return strings[type]; - }, + resolveMsg: (type)=> strings[type], _: { - strings: strings + strings }, - cron: new CronJob('0 1 * * * *', function () { + cron: new CronJob('0 1 * * * *', () => { //noinspection JSUnresolvedFunction - redis.hkeys('spam:user:spampoints').then(function (keys) { - return Promise.all(keys.map(function (key) { - //noinspection JSUnresolvedFunction - return redis.hincrby('spam:user:spampoints', key, (0 - config.chatfilter.spam.points)).then(function (point) { - if (point < 0) { //noinspection JSUnresolvedFunction - return redis.hset('spam:user:spampoints', key, 0); - } - else return Promise.resolve(); - }); - })); - }); + redis.hkeys('spam:user:spampoints').then(keys => Promise.all(keys.map(key => //noinspection JSUnresolvedFunction + redis.hincrby('spam:user:spampoints', key, (0 - config.chatfilter.spam.points)).then(point => { + if (point < 0) { //noinspection JSUnresolvedFunction + return redis.hset('spam:user:spampoints', key, 0); + } + else return Promise.resolve(); + })))); }, null, true) }; \ No newline at end of file diff --git a/lib/chatfilters/banned_words.js b/lib/chatfilters/banned_words.js index f0a83b2..759ab68 100644 --- a/lib/chatfilters/banned_words.js +++ b/lib/chatfilters/banned_words.js @@ -12,8 +12,8 @@ module.exports = { warn: langfile.chatfilter.bannedword.warn, mute: langfile.chatfilter.bannedword.mute }, - check: function (data) { - return new Promise(function (resolve, reject) { + check: (data)=> { + return new Promise((resolve, reject) => { if (utils.contains(data.message, config.chatfilter.words.blacklist)) reject({ type: 'bannedword', points: 5 diff --git a/lib/chatfilters/language.js b/lib/chatfilters/language.js index 6a7a131..2c5032e 100644 --- a/lib/chatfilters/language.js +++ b/lib/chatfilters/language.js @@ -11,18 +11,15 @@ module.exports = { strings: { warn: langfile.chatfilter.language.warn }, - check: function (data) { - return new Promise(function (resolve, reject) { + check: (data)=> { + return new Promise((resolve, reject) => { if (config.chatfilter.language.enabled) { - detector.detect(data.messae, function (err, msg) { - if (err) { - resolve(); - } else { - if (msg.reliable) { - if (config.chatfilter.language.allowed.indexOf(msg.languages[0].code) !== -1) resolve(); - else reject({type: 'language', points: 0}); - } else resolve(); - } + detector.detect(data.messae, (err, msg) => { + if (err)return resolve(); + if (!msg.reliable)return resolve(); + if (config.chatfilter.language.allowed.includes(msg.languages[0].code))return resolve(); + + reject({type: 'language', points: 0}); }); } else resolve(); }); diff --git a/lib/chatfilters/links.js b/lib/chatfilters/links.js index c60ba7a..d4c4f92 100644 --- a/lib/chatfilters/links.js +++ b/lib/chatfilters/links.js @@ -13,34 +13,30 @@ module.exports = { warn: langfile.chatfilter.link.warn, mute: langfile.chatfilter.link.mute }, - check: function (data) { - return new Promise(function (resolve, reject) { + check: (data)=> { + return new Promise((resolve, reject) => { if (config.chatfilter.enabled) { var matches = data.message.match(config.chatfilter.links.regex); if (matches.length === 0) resolve(); else { - matches = matches.map(function (match) { - return URL.parse(match); - }); - Promise.all(matches.map(function (match) { - return new Promise(function (resolve, reject) { - if (config.chatfilter.links.plugdj.hosts.indexOf(match.hostname) !== -1 && config.chatfilter.links.plugdj.enabled) { - //noinspection JSUnresolvedFunction - match.pathname = S(match.pathname).chompRight('/').s; - if (config.chatfilter.links.plugdj.allowed_paths.indexOf(match.pathname) === -1) reject({ - type: 'link', - points: 10 - }); - } else if (config.chatfilter.links.mode === 'blacklist' && config.chatfilter.links.filter.indexOf(match.hostname) !== -1) reject({ - type: 'link', - points: 10 - }); - else if (config.chatfilter.links.mode === 'whitelist' && config.chatfilter.links.filter.indexOf(match.hostname) === -1) reject({ + matches = matches.map(match => URL.parse(match)); + Promise.all(matches.map(match => new Promise((resolve, reject) => { + if (config.chatfilter.links.plugdj.hosts.includes(match.hostname) && config.chatfilter.links.plugdj.enabled) { + //noinspection JSUnresolvedFunction + match.pathname = S(match.pathname).chompRight('/').s; + if (!config.chatfilter.links.plugdj.allowed_paths.includes(match.pathname)) reject({ type: 'link', points: 10 }); + } else if (config.chatfilter.links.mode === 'blacklist' && config.chatfilter.links.filter.includes(match.hostname)) reject({ + type: 'link', + points: 10 + }); + else if (config.chatfilter.links.mode === 'whitelist' && !config.chatfilter.links.filter.includes(match.hostname)) reject({ + type: 'link', + points: 10 }); - })).then(resolve).catch(reject); + }))).then(resolve).catch(reject); } } else resolve(); }); diff --git a/lib/chatfilters/repeat.js b/lib/chatfilters/repeat.js index a383f66..00475a9 100644 --- a/lib/chatfilters/repeat.js +++ b/lib/chatfilters/repeat.js @@ -11,15 +11,15 @@ module.exports = { warn: langfile.chatfilter.repeat.warn, mute: langfile.chatfilter.repeat.mute }, - check: function (data) { - return new Promise(function (resolve, reject) { - redis.get('user:lastmessage:' + data.id).then(function (lmsg) { + check: (data)=> { + return new Promise((resolve, reject) => { + redis.get(`user:lastmessage:${data.id}`).then(lmsg => { if (lmsg === data.message) reject({type: 'repeat', points: 10}); else { resolve(); - redis.set('user:lastmessage:' + data.id, data.message).then(function () { + redis.set(`user:lastmessage:${data.id}`, data.message).then(() => { //noinspection JSUnresolvedFunction - redis.expire('user:lastmessage:' + data.id, 600); + return redis.expire(`user:lastmessage:${data.id}`, 600); }); } }) diff --git a/lib/chatfilters/spam.js b/lib/chatfilters/spam.js index 55b2481..bb8bea3 100644 --- a/lib/chatfilters/spam.js +++ b/lib/chatfilters/spam.js @@ -12,27 +12,25 @@ module.exports = { mute: langfile.chatfilter.spam.mute, warn: langfile.chatfilter.spam.warn }, - check: function (data) { - return new Promise(function (resolve, reject) { + check: (data)=> { + return new Promise((resolve, reject) => { //noinspection JSUnresolvedFunction - redis.hincrby('user:spampoints', data.id, 1).then(function (points) { + redis.hincrby('user:spampoints', data.id, 1).then(points => { if (points > 60) reject({type: 'spam', points: 10}); else resolve(); }); }); }, - cron: new CronJob('0 0 * * * *', function () { + cron: new CronJob('0 0 * * * *', () => { //noinspection JSUnresolvedFunction - redis.hkeys('user:spampoints').then(function (keys) { - Promise.all(keys.map(function (key) { - //noinspection JSUnresolvedFunction - return redis.hincrby('user:spampoints', key, -60).then(function (p) { + redis.hkeys('user:spampoints').then(keys => { + Promise.all(keys.map(key => //noinspection JSUnresolvedFunction + redis.hincrby('user:spampoints', key, -60).then(p => { if (p < 0) { //noinspection JSUnresolvedFunction - return redis.hset('user:spampoints',key, 0); + return redis.hset('user:spampoints', key, 0); } else return Promise.resolve(); - }); - })); + }))); }); }, null, true) }; \ No newline at end of file diff --git a/lib/cleverbot.js b/lib/cleverbot.js index 914f2f3..0be107a 100644 --- a/lib/cleverbot.js +++ b/lib/cleverbot.js @@ -10,7 +10,7 @@ var cleverbot = null; try { var Cleverbot = require('cleverbot-node'); cleverbot = new Cleverbot; - Cleverbot.prepare(function () { + Cleverbot.prepare(() => { story.info('cleverbot', 'Cleverbot loaded and ready.'); }); } catch (e) { @@ -19,9 +19,9 @@ try { story.debug('cleverbot', 'Unable to load cleverbot-integration.', {attach: e}); } -module.exports = function (data) { +module.exports = (data)=> { if (cleverbot !== null && cleverbot !== undefined && config.cleverbot.enabled) { - cleverbot.write(data.message.replace('@' + plugged.getSelf().username, '').trim(), function (resp) { + cleverbot.write(data.message.replace(`@${plugged.getSelf().username}`, '').trim(), (resp)=> { story.debug('cleverbot', resp.message); plugged.sendChat(utils.replace(langfile.cleverbot.format, { username: data.username, diff --git a/lib/client.js b/lib/client.js index afcf35b..23ef9b4 100644 --- a/lib/client.js +++ b/lib/client.js @@ -5,8 +5,8 @@ var story = require('storyboard').mainStory; var config = require('./load_config'); var plugged = new Plugged({ - log: function (msg, verbosity, type) { - switch(type) { + log: (msg, verbosity, type)=> { + switch (type) { case "magenta": type = "debug"; break; @@ -26,7 +26,7 @@ var plugged = new Plugged({ } }); -Promise.promisifyAll(plugged,{suffix:'Promise'}); +Promise.promisifyAll(plugged, {suffix: 'Promise'}); plugged.login(config.login); diff --git a/lib/commands.js b/lib/commands.js index 63594de..2b5577e 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -13,26 +13,26 @@ var filelist = []; loadCommands(); function loadCommands() { - fs.readdir(path.resolve(__dirname, 'commands'), function (err, files) { + fs.readdir(path.resolve(__dirname, 'commands'), (err, files) => { if (err) { story.fatal('Commands', 'Cannot load commands', {attach: err}); process.exit(1); } else { - files.forEach(function (file) { + files.forEach(file => { try { var command = require(path.resolve(__dirname, 'commands', file)); if (command.enabled) { - command.names.forEach(function (name) { + command.names.forEach(name => { commands[name] = command; }); - filelist.push(path.resolve(__dirname, 'commands/' + file)); - story.debug('Commands', 'Loaded command ' + command.names[0]); - } else story.debug('Commands', 'Skipping ' + command.names[0] + '(' + file + ') since it\'s disabled.'); + filelist.push(path.resolve(__dirname, `commands/${file}`)); + story.debug('Commands', `Loaded command ${command.names[0]}`); + } else story.debug('Commands', `Skipping ${command.names[0]}(${file}) since it's disabled.`); } catch (e) { - story.warn('Commands', 'Failed to load command ' + file, {attach: e}); + story.warn('Commands', `Failed to load command ${file}`, {attach: e}); } }); - story.info('Commands', 'Loaded ' + (filelist.length) + ' commands.'); + story.info('Commands', `Loaded ${filelist.length} commands.`); } }); } diff --git a/lib/commands/add.js b/lib/commands/add.js index 8bc2219..8d3fabb 100644 --- a/lib/commands/add.js +++ b/lib/commands/add.js @@ -14,27 +14,27 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.split(' '); //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction var user = plugged.getUserByName(S(_.rest(split, 1).join(' ')).chompLeft('@').chompRight(' ').s); if (user !== undefined) { - utils.isWlBanned(user).then(function (isBanned) { + utils.isWlBanned(user).then(isBanned => { if (!isBanned) { - if (function () { + if ((() => { var waitlist = plugged.getWaitlist() || []; var dj = plugged.getDJ() || {id: -1}; if (dj === user.id) return false; - else return waitlist.indexOf(user.id) === -1; - }()) { + else return !waitlist.includes(user.id); + })()) { plugged.sendChat(utils.replace(langfile.bp_actions.add, {username: data.username}), 45); if (plugged.getWaitlist() === undefined || plugged.getWaitlist().length < 50) { - plugged.addToWaitlist(user.id, function (err) { + plugged.addToWaitlist(user.id, err => { if (err)story.error('add', 'Error adding user to the waitlist.', {attach: err}); }); - } else addqueue.add(user.id, 100).then(function () { + } else addqueue.add(user.id, 100).then(() => { plugged.sendChat(utils.replace(langfile.bp_actions.add_queue, { username: user.username, mod: data.username @@ -52,7 +52,7 @@ module.exports = { value: S(_.rest(split, 1).join(' ')).chompLeft('@').s }), 20); } - story.info('add', utils.userLogString(data.username, data.id) + ': ' + utils.userLogString(user)); + story.info('add', `${utils.userLogString(data.username, data.id)}: ${utils.userLogString(user)}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/ban.js b/lib/commands/ban.js index 07e21fb..b8e7bed 100644 --- a/lib/commands/ban.js +++ b/lib/commands/ban.js @@ -1,4 +1,6 @@ var story = require('storyboard').mainStory; +var S = require('string'); +var _ = require('underscore'); var plugged = require('../client'); var redis = require('../db/redis_db'); @@ -8,12 +10,45 @@ var langfile = require('../../langfile'); module.exports = { names: ['ban'], - enabled: false, + enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); - //todo + if (perm > 1) { + var split = data.message.split(' '); + if (split.length > 2) { + var duration; + if (split[1] === 'h')duration = plugged.BANDURATION.HOUR; + else if (split[1] === 'd')duration = plugged.BANDURATION.DAY; + else if (split[1] === 'p' || split[1] === 'f') { + if (config.options.bouncer_plus) { + duration = plugged.BANDURATION.PERMA; + } else return; + } else return plugged.sendChat(utils.replace(langfile.error.argument, { + username: data.username, + cmd: 'Ban' + }), 20); + //noinspection JSUnresolvedFunction + var user = plugged.getUserByName(S(_.rest(split, 2).join(' ')).chompLeft('@').chompRight(' ').s) || plugged.getUserByID(split[2]); + if (user) { + plugged.sendChat(utils.replace(langfile.ban.default, { + mod: data.username, + username: user.username, + duration: langfile.ban.duration[duration] + })); + plugged.banUser(user.id, duration, plugged.BANREASON.VIOLATING_COMMUNITY_RULES); + } else { //noinspection JSUnresolvedFunction + plugged.sendChat(utils.replace(langfile.error.user_not_found, { + username: plugged.getUserByID(data.id), + value: S(_.rest(split, 1).join(' ')).chompLeft('@').s + }), 20); + } + } else plugged.sendChat(utils.replace(langfile.error.argument, { + username: data.username, + cmd: 'Ban' + }), 20); + } }); plugged.removeChatMessage(data.cid); } diff --git a/lib/commands/blacklist.js b/lib/commands/blacklist.js index decb80d..a64a625 100644 --- a/lib/commands/blacklist.js +++ b/lib/commands/blacklist.js @@ -14,46 +14,40 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { - redis.exists('meta:state:skipable').then(function (ex) { + redis.hget('user:roles', data.id).then(perm => { + redis.exists('meta:state:skipable').then(ex => { perm = parseInt(perm, 10); if (perm > 1 && ex === 0) { var booth = utils.clone(plugged.getBooth()); var media = utils.clone(plugged.getMedia()); - //todo locksip option plugged.sendChat(utils.replace(langfile.blacklist.default, {username: data.username}), 60); if (config.blacklist.lockskip) { //noinspection JSUnresolvedFunction - plugged.setCyclePromise(true).then(function () { - //noinspection JSUnresolvedFunction - return plugged.skipDJPromise(booth.dj); - }).then(function () { + plugged.setCyclePromise(true).then(() => //noinspection JSUnresolvedFunction + plugged.skipDJPromise(booth.dj)).then(() => { if (config.lockskip.move_pos !== undefined) plugged.moveDJ(booth.dj, config.lockskip.move_pos); return Promise.resolve(); - }).then(function () { + }).then(() => { if (booth.shouldCycle !== plugged.doesWaitlistCycle()) { //noinspection JSUnresolvedFunction return plugged.setCyclePromise(booth.shouldCycle); } else Promise.resolve(); - }).catch(function (err) { + }).catch(err => { story.error('Error while lockskipping.', {attach: err}); }); } else plugged.skipDJ(booth.dj); - redis.set('meta:state:skipable', 1).then(function () { - //noinspection JSUnresolvedFunction - redis.expire('meta:state:skipable', 2); - }); + redis.set('meta:state:skipable', 1, 'EX', 2); var split = data.message.trim().split(' '); //noinspection JSCheckFunctionSignatures var reason = utils.blacklistReason(_.rest(split, 1).join(' ').trim()); - db.blacklist.add(media.format, media.cid, reason).then(function () { - setTimeout(function () { + db.blacklist.add(media.format, media.cid, reason).then(() => { + setTimeout(() => { if (split.length > 1) { plugged.sendChat(utils.replace(langfile.blacklist.with_reason, { username: plugged.getUserByID(booth.dj).username, mod: data.username, song: utils.songtitle(media.author, media.title), - reason: reason + reason }), 60); db.models.Song.update({ is_banned: true, @@ -69,7 +63,7 @@ module.exports = { } }, 4 * 1000); }); - story.info('blacklist', utils.userLogString(data.username, data.id) + ': ' + utils.mediatitlelog(media) + ' played by ' + utils.userLogString(plugged.getUserByID(booth.dj))); + story.info('blacklist', `${utils.userLogString(data.username, data.id)}: ${utils.mediatitlelog(media)} played by ${utils.userLogString(plugged.getUserByID(booth.dj))}`); } }); }); diff --git a/lib/commands/bouncer+.js b/lib/commands/bouncer+.js index 375700b..a8c46b1 100644 --- a/lib/commands/bouncer+.js +++ b/lib/commands/bouncer+.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 2) { config.options.bouncer_plus = !config.options.bouncer_plus; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.bouncer_plus.disabled, {username: data.username}), 45); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'options:bouncer_plus', (config.options.bouncer_plus ? 1 : 0)); - story.info('bouncer+', utils.userLogString(data.username, data.id) + ': --> ' + config.options.bouncer_plus.toString()); + story.info('bouncer+', `${utils.userLogString(data.username, data.id)}: --> ${config.options.bouncer_plus.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/catfact.js b/lib/commands/catfact.js index 9fb4641..9c29210 100644 --- a/lib/commands/catfact.js +++ b/lib/commands/catfact.js @@ -9,7 +9,7 @@ module.exports = { names:['catfact', 'catfacts'], enabled: true, handler: function (data) { - request('http://catfacts-api.appspot.com/api/facts', function (error, response, body) { + request('http://catfacts-api.appspot.com/api/facts', (error, response, body) => { if (!error && body != null) { //noinspection JSUnresolvedVariable plugged.sendChat(utils.replace(langfile.catfact.default, { diff --git a/lib/commands/channelblacklist.js b/lib/commands/channelblacklist.js index 4494374..3eb867c 100644 --- a/lib/commands/channelblacklist.js +++ b/lib/commands/channelblacklist.js @@ -13,7 +13,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.split(' '); @@ -33,7 +33,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.blacklist.channelblacklist.disabled, {username: data.username}), 30); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'channelblacklist:enabled', (config.blacklist.channelblacklist ? 1 : 0)); - story.info('ChannelBlacklist', utils.userLogString(data.username, data.id) + ': --> ' + config.blacklist.channelblacklist.toString()); + story.info('ChannelBlacklist', `${utils.userLogString(data.username, data.id)}: --> ${config.blacklist.channelblacklist.toString()}`); } else plugged.sendChat(utils.replace(langfile.error.eventmode, { username: data.username, cmd: 'ChannelBlacklist' @@ -43,20 +43,20 @@ module.exports = { var r = _.rest(split, 3).join(' ').trim(); //noinspection JSDuplicatedDeclaration var cid = split[2]; - db.channelblacklist.add(cid, (r.length > 0 ? r : null)).then(function () { + db.channelblacklist.add(cid, (r.length > 0 ? r : null)).then(() => { plugged.sendChat(utils.replace(langfile.blacklist.channelblacklist.add, { username: data.username, - cid: cid + cid })); }); break; case 'rem': //noinspection JSDuplicatedDeclaration var cid = split[2]; - db.channelblacklist.remove(cid).then(function () { + db.channelblacklist.remove(cid).then(() => { plugged.sendChat(utils.replace(langfile.blacklist.channelblacklist.remove, { username: data.username, - cid: cid + cid })); }); break; diff --git a/lib/commands/chatfilter.js b/lib/commands/chatfilter.js index 6d4c239..48f8e09 100644 --- a/lib/commands/chatfilter.js +++ b/lib/commands/chatfilter.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.chatfilter.enabled = !config.chatfilter.enabled; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.chatfilter.disabled, {username: data.username}), 30); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'chatfilter:enabled', (config.chatfilter.enabled ? 1 : 0)); - story.info('chatfilter', utils.userLogString(data.username, data.id) + ': --> ' + config.chatfilter.enabled.toString()); + story.info('chatfilter', `${utils.userLogString(data.username, data.id)}: --> ${config.chatfilter.enabled.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/chatlevel.js b/lib/commands/chatlevel.js index a7fb3f2..2df91fb 100644 --- a/lib/commands/chatlevel.js +++ b/lib/commands/chatlevel.js @@ -9,13 +9,13 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.trim().split(' '); if (split.length === 2) { var lvl = parseInt(split[1]); - if (!isNaN(lvl) && [1, 2, 3].indexOf(lvl) !== -1) { + if (!isNaN(lvl) && [1, 2, 3].includes(lvl)) { plugged.sendChat(utils.replace(langfile.chatlevel.default, {username: data.username})); //noinspection JSUnresolvedFunction plugged.setMinChatLevel(lvl); diff --git a/lib/commands/cleanwl.js b/lib/commands/cleanwl.js index 5412733..ced169e 100644 --- a/lib/commands/cleanwl.js +++ b/lib/commands/cleanwl.js @@ -9,7 +9,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var wl = utils.clone(plugged.getWaitlist()); diff --git a/lib/commands/clear.js b/lib/commands/clear.js index 5a68520..bfa3fc0 100644 --- a/lib/commands/clear.js +++ b/lib/commands/clear.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if ((config.options.bouncer_plus ? (perm > 1) : (perm > 2))) { plugged.sendChat(utils.replace(langfile.bp_actions.clear, {username: data.username}), 70); diff --git a/lib/commands/clearghosts.js b/lib/commands/clearghosts.js index edd0873..f6f74af 100644 --- a/lib/commands/clearghosts.js +++ b/lib/commands/clearghosts.js @@ -12,32 +12,26 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 2) { plugged.sendChat(utils.replace(langfile.clearghosts.default, {username: data.username})); - setTimeout(function () { + setTimeout(() => { db.models.User.findAll({ where: { status: true, last_active: {$lt: moment().subtract(50, 'hours').toDate()} } - }).then(function (users) { - return Promise.all(users.map(function (user) { - return new Promise(function (resolve) { - plugged.banUser(user.id, plugged.BANDURATION.HOUR, plugged.BANREASON.VIOLATING_COMMUNITY_RULES, function (err) { - if (err) resolve(-1); - resolve(user.id); - }) - }); - })); - }).then(function (uids) { - Promise.all(uids.map(function (uid) { - return new Promise(function (resolve) { - if (uid !== -1) plugged.unbanUser(uid); - resolve(); - }); - })) + }).then(users => Promise.all(users.map(user => new Promise(resolve => { + plugged.banUser(user.id, plugged.BANDURATION.HOUR, plugged.BANREASON.VIOLATING_COMMUNITY_RULES, err => { + if (err) resolve(-1); + resolve(user.id); + }) + })))).then(uids => { + Promise.all(uids.map(uid => new Promise(resolve => { + if (uid !== -1) plugged.unbanUser(uid); + resolve(); + }))) }); }, 15 * 1000); } diff --git a/lib/commands/clearhistory.js b/lib/commands/clearhistory.js index 7619168..76ef364 100644 --- a/lib/commands/clearhistory.js +++ b/lib/commands/clearhistory.js @@ -11,14 +11,14 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { plugged.sendChat(utils.replace(langfile.skip.history.clear, {username: data.username}), 60); //noinspection JSCheckFunctionSignatures - redis.keys('media:history:*').then(function (keys) { + redis.keys('media:history:*').then(keys => { //noinspection JSUnresolvedFunction - keys.forEach(function (key) { + keys.forEach(key => { //noinspection JSUnresolvedFunction redis.del(key); }); diff --git a/lib/commands/cleverbot.js b/lib/commands/cleverbot.js index fec730a..94a80c2 100644 --- a/lib/commands/cleverbot.js +++ b/lib/commands/cleverbot.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.cleverbot.enabled = !config.cleverbot.enabled; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.cleverbot.disabled, {username: data.username}), 30); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'cleverbot:enabled', (config.cleverbot.enabled ? 1 : 0)); - story.info('cleverbot', utils.userLogString(data.username, data.id) + ': --> ' + config.cleverbot.enabled.toString()); + story.info('cleverbot', `${utils.userLogString(data.username, data.id)}: --> ${config.cleverbot.enabled.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/customcommands.js b/lib/commands/customcommands.js index f03dffc..556191f 100644 --- a/lib/commands/customcommands.js +++ b/lib/commands/customcommands.js @@ -13,7 +13,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.trim().split(' '); @@ -27,7 +27,7 @@ module.exports = { message: _.rest(split, 3).join(' ').trim(), status: true } - }).spread(function (cc) { + }).spread(cc => { //noinspection JSCheckFunctionSignatures cc.updateAttributes({message: _.rest(split, 3).join(' ').trim()}); }); diff --git a/lib/commands/cycle.js b/lib/commands/cycle.js index 4235997..5bb6924 100644 --- a/lib/commands/cycle.js +++ b/lib/commands/cycle.js @@ -11,13 +11,13 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { plugged.sendChat(utils.replace(langfile.bp_actions.cycle, {username: data.username}), 70); var cycle = plugged.doesWaitlistCycle(); plugged.setCycle(!cycle); - story.info('cycle', utils.userLogString(data.username, data.id) + ': --> ' + (!cycle).toString()); + story.info('cycle', `${utils.userLogString(data.username, data.id)}: --> ${(!cycle).toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/cycleskip.js b/lib/commands/cycleskip.js index 3dbf4f8..ec79d61 100644 --- a/lib/commands/cycleskip.js +++ b/lib/commands/cycleskip.js @@ -11,8 +11,8 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { - redis.exists('meta:state:skipable').then(function (ex) { + redis.hget('user:roles', data.id).then(perm => { + redis.exists('meta:state:skipable').then(ex => { perm = parseInt(perm, 10); if (perm > 1 && ex === 0) { var booth = utils.clone(plugged.getBooth()); @@ -20,12 +20,9 @@ module.exports = { plugged.sendChat(utils.replace(langfile.skip.cycleskip, {username: data.username}), 70); plugged.setCycle(false); plugged.skipDJ(booth.dj); - redis.set('meta:state:skipable', 1).then(function () { - //noinspection JSUnresolvedFunction - redis.expire('meta:state:skipable', 2); - }); + redis.set('meta:state:skipable', 1, 'EX', 2); if (booth.shouldCycle !== plugged.doesWaitlistCycle) plugged.setCycle(booth.shouldCycle); - setTimeout(function () { + setTimeout(() => { var split = data.message.trim().split(' '); if (langfile.skip.reasons[split[1]] !== undefined) { plugged.sendChat(utils.replace(langfile.skip.reasons[split[1]], { @@ -34,7 +31,7 @@ module.exports = { }), 60); } }, 4 * 1000); - story.info('cycleskip', utils.userLogString(data.username, data.id) + ': ' + utils.mediatitlelog(media) + ' played by ' + utils.userLogString(plugged.getUserByID(booth.dj))); + story.info('cycleskip', `${utils.userLogString(data.username, data.id)}: ${utils.mediatitlelog(media)} played by ${utils.userLogString(plugged.getUserByID(booth.dj))}`); } }); }); diff --git a/lib/commands/dc.js b/lib/commands/dc.js index 77b7734..66d7e90 100644 --- a/lib/commands/dc.js +++ b/lib/commands/dc.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { if (config.dcmoveback.enabled) { - redis.get('user:disconnect:' + data.id).then(function (pos) { + redis.get(`user:disconnect:${data.id}`).then(pos => { if (pos !== null) { pos = parseInt(pos); if (pos !== -1 && pos > utils.wlPosition(data.id)) { @@ -23,20 +23,20 @@ module.exports = { if (utils.wlPosition(data.id) === -1) plugged.addToWaitlist(data.id); plugged.moveDJ(data.id, pos); //noinspection JSUnresolvedFunction - redis.del('user:disconnect:' + data.id); + redis.del(`user:disconnect:${data.id}`); } else { - addqueue.add(data.id, pos).then(function () { + addqueue.add(data.id, pos).then(() => { plugged.sendChat(utils.replace(langfile.dcmoveback.command.addqueue, { username: data.username, pos: (pos + 1).toString() })); //noinspection JSUnresolvedFunction - redis.del('user:disconnect:' + data.id); + redis.del(`user:disconnect:${data.id}`); }); } } else { //noinspection JSUnresolvedFunction - redis.del('user:disconnect:' + data.id); + redis.del(`user:disconnect:${data.id}`); plugged.sendChat(utils.replace(langfile.dcmoveback.command.on_wl, {username: data.username})); } } else { diff --git a/lib/commands/dcmoveback.js b/lib/commands/dcmoveback.js index 224512b..a5d7fc9 100644 --- a/lib/commands/dcmoveback.js +++ b/lib/commands/dcmoveback.js @@ -11,14 +11,14 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.dcmoveback.enabled = !config.dcmoveback.enabled; if (config.dcmoveback.enabled) plugged.sendChat(utils.replace(langfile.dcmoveback.enabled, {username: data.username})); else plugged.sendChat(utils.replace(langfile.dcmoveback.disabled, {username: data.username})); redis.set('meta:config', 'options:dcmoveback', (config.dcmoveback.enabled ? 1 : 0)); - story.info('dcmoveback', utils.userLogString(data.username, data.id) + ': --> ' + config.dcmoveback.enabled.toString()); + story.info('dcmoveback', `${utils.userLogString(data.username, data.id)}: --> ${config.dcmoveback.enabled.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/define.js b/lib/commands/define.js index ba5c97a..182ae66 100644 --- a/lib/commands/define.js +++ b/lib/commands/define.js @@ -14,8 +14,8 @@ module.exports = { //noinspection JSCheckFunctionSignatures var msg = _.rest(data.message.split(' '), 1).join(' ').trim(); if (msg.length > 0) { - var uri = 'http://api.wordnik.com/v4/word.json/' + msg + '/definitions?limit=200&includeRelated=true&useCanonical=true&includeTags=false&api_key=' + config.apiKeys.wordnik; - request.get(uri, function (error, response, body) { + var uri = `http://api.wordnik.com/v4/word.json/${msg}/definitions?limit=200&includeRelated=true&useCanonical=true&includeTags=false&api_key=${config.apiKeys.wordnik}`; + request.get(uri, (error, response, body) => { if (!error && response.statusCode === 200) { var definition = JSON.parse(body); if (definition.length === 0) plugged.sendChat(utils.replace(langfile.define.no_definition_found, { diff --git a/lib/commands/delchat.js b/lib/commands/delchat.js index 5f74044..3646d18 100644 --- a/lib/commands/delchat.js +++ b/lib/commands/delchat.js @@ -13,13 +13,13 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { var split = data.message.split(' '); if (split.length === 1) { var chats = plugged.getChat(); - chats.forEach(function (chat) { + chats.forEach(chat => { plugged.removeChatMessage(chat.cid); }); plugged.sendChat(utils.replace(langfile.delchat.clear, { @@ -28,13 +28,13 @@ module.exports = { }), 60); } else { //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction - db.models.User.find({where: {$or: [{username: {$like: '%' + S(_.rest(split, 1).join(' ')).chompLeft('@').chompRight(' ').s + '%'}}, {id: _.rest(split, 1)}]}}).then(function (user) { + db.models.User.find({where: {$or: [{username: {$like: `%${S(_.rest(split, 1).join(' ')).chompLeft('@').chompRight(' ').s}%`}}, {id: _.rest(split, 1)}]}}).then(user => { if (user !== null && user !== undefined) { plugged.sendChat(utils.replace(langfile.delchat.user, { mod: data.username, username: user.username }), 45); - plugged.getChatByUser(user.username).forEach(function (msg) { + plugged.getChatByUser(user.username).forEach(msg => { plugged.removeChatMessage(msg.cid); }); } else { //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction diff --git a/lib/commands/demote.js b/lib/commands/demote.js index f47e8ed..96404f9 100644 --- a/lib/commands/demote.js +++ b/lib/commands/demote.js @@ -9,7 +9,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 0) plugged.removeStaff(data.id); }); diff --git a/lib/commands/disable.js b/lib/commands/disable.js index 6978756..9d3edc9 100644 --- a/lib/commands/disable.js +++ b/lib/commands/disable.js @@ -6,7 +6,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { var split = data.message.split(' '); diff --git a/lib/commands/eventmode.js b/lib/commands/eventmode.js index f681625..99caaa9 100644 --- a/lib/commands/eventmode.js +++ b/lib/commands/eventmode.js @@ -12,7 +12,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var str = S(data.message); @@ -47,7 +47,7 @@ module.exports = { } //noinspection JSUnresolvedFunction redis.hset('meta:config', 'state:eventmode', (config.state.eventmode ? 1 : 0)); - story.info('eventmode', utils.userLogString(data.username, data.id) + ': --> ' + config.state.eventmode.toString()); + story.info('eventmode', `${utils.userLogString(data.username, data.id)}: --> ${config.state.eventmode.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/everyone.js b/lib/commands/everyone.js index 5a1c9ec..4817397 100644 --- a/lib/commands/everyone.js +++ b/lib/commands/everyone.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.trim().split(' '); diff --git a/lib/commands/filterreset.js b/lib/commands/filterreset.js index 8f68466..e903f42 100644 --- a/lib/commands/filterreset.js +++ b/lib/commands/filterreset.js @@ -12,7 +12,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.split(' '); @@ -21,17 +21,13 @@ module.exports = { var user = plugged.getUserByName(S(_.initial(_.rest(split, 1)).join(' ')).chompLeft('@').chompRight(' ').s); if (user !== undefined) { //noinspection JSUnresolvedFunction - redis.hset('spam:user:spampoints', user.id, 0).then(function () { - //noinspection JSUnresolvedFunction - return redis.del('user:lastmessage:' + user.id); - }).then(function () { - //noinspection JSUnresolvedFunction - return redis.hset('user:spampoints', user.id, 0); - }).then(function () { + redis.hset('spam:user:spampoints', user.id, 0).then(() => //noinspection JSUnresolvedFunction + redis.del(`user:lastmessage:${user.id}`)).then(() => //noinspection JSUnresolvedFunction + redis.hset('user:spampoints', user.id, 0)).then(() => { }); - redis.set('user:chat:spam:' + user.id + ':warns', 0).then(function () { + redis.set(`user:chat:spam:${user.id}:warns`, 0).then(() => { plugged.sendChat(utils.replace(langfile.filterreset.default, { username: user.username, mod: data.username diff --git a/lib/commands/historyskip.js b/lib/commands/historyskip.js index 4e4736f..39f57ba 100644 --- a/lib/commands/historyskip.js +++ b/lib/commands/historyskip.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { if (!config.state.eventmode) { @@ -20,7 +20,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.skip.history.disabled, {username: data.username}), 30); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'history:skipenabled', (config.history.skipenabled ? 1 : 0)); - story.info('historyskip', utils.userLogString(data.username, data.id) + ': --> ' + config.history.skipenabled.toString()); + story.info('historyskip', `${utils.userLogString(data.username, data.id)}: --> ${config.history.skipenabled.toString()}`); } else plugged.sendChat(utils.replace(langfile.error.eventmode, { username: data.username, cmd: 'Historyskip' diff --git a/lib/commands/idblacklist.js b/lib/commands/idblacklist.js index 14cc970..8704d90 100644 --- a/lib/commands/idblacklist.js +++ b/lib/commands/idblacklist.js @@ -18,7 +18,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { var split = data.message.trim().split(' '); @@ -30,16 +30,16 @@ module.exports = { var url = URL.parse(split[1], true); if (url.hostname === 'youtu.be') { //noinspection JSUnresolvedFunction - blackl('1:' + S(url.pathname).replaceAll('/', '').s); + blackl(`1:${S(url.pathname).replaceAll('/', '').s}`); } else { //noinspection JSUnresolvedVariable if (url.hostname === 'www.youtbe.com' && url.query.v !== undefined) { //noinspection JSUnresolvedVariable - blackl('1:' + url.query.v) + blackl(`1:${url.query.v}`) } else if (url.hostname === 'soundcloud.com') { - request.get('https://api.soundcloud.com/resolve?client_id=' + config.apiKeys.soundcloud + '&url=' + split[1], function (err, resp, body) { + request.get(`https://api.soundcloud.com/resolve?client_id=${config.apiKeys.soundcloud}&url=${split[1]}`, (err, resp, body) => { if (!err && resp.statusCode === 200) { body = JSON.parse(body); - blackl('2:' + body.id); + blackl(`2:${body.id}`); } }); } else plugged.sendChat(utils.replace(langfile.error.argument, { @@ -61,19 +61,19 @@ module.exports = { is_banned: true, ban_reason: (split.length === 2 ? undefined : _.rest(split, 2).join(' ').trim()) } - }).spread(function (song) { + }).spread(song => { //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction song.updateAttributes({ is_banned: true, ban_reason: (split.length === 2 ? undefined : utils.blacklistReason(_.rest(split, 2).join(' ').trim())) }); //noinspection JSCheckFunctionSignatures - redis.set('media:blacklist:' + song.format + ':' + song.cid, (split.length === 2 ? 1 : _.rest(split, 2).join(' ').trim())); + redis.set(`media:blacklist:${song.format}:${song.cid}`, (split.length === 2 ? 1 : _.rest(split, 2).join(' ').trim())); plugged.sendChat(utils.replace(langfile.blacklist.idbl.default, { username: data.username, song: utils.songtitle(song.author, song.title) }), 30); - story.info('blacklist', utils.userLogString(data.username, data.id) + ' added ' + utils.songtitle(song.author, song.title) + '[' + song.format + ':' + song.cid + '] to the blacklist'); + story.info('blacklist', `${utils.userLogString(data.username, data.id)} added ${utils.songtitle(song.author, song.title)}[${song.format}:${song.cid}] to the blacklist`); }); } else plugged.sendChat(utils.replace(langfile.error.argument, { username: data.username, diff --git a/lib/commands/join.js b/lib/commands/join.js index c2ec100..61c3c2b 100644 --- a/lib/commands/join.js +++ b/lib/commands/join.js @@ -8,12 +8,12 @@ module.exports = { names: ['join'], enabled: true, handler: function (data) { - redis.exists('meta:roulette:active').then(function (ex) { + redis.exists('meta:roulette:active').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.sismember('meta:roulette:users', data.id).then(function (mem) { + redis.sismember('meta:roulette:users', data.id).then(mem => { if (mem === 0) { //noinspection JSUnresolvedFunction - redis.sadd('meta:roulette:users', data.id).then(function () { + redis.sadd('meta:roulette:users', data.id).then(() => { plugged.sendChat(utils.replace(langfile.roulette.join, {username: data.username})); }); } diff --git a/lib/commands/joinmode.js b/lib/commands/joinmode.js index cd91a51..e7a4c8e 100644 --- a/lib/commands/joinmode.js +++ b/lib/commands/joinmode.js @@ -11,7 +11,7 @@ module.exports = { enabled:true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { if (!config.state.eventmode) { @@ -20,7 +20,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.joinmode.disabled, {username: data.username}), 30); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'joinmode:enabled', (config.options.joinmode? 1 : 0)); - story.info('joinmode', utils.userLogString(data.username, data.id) + ': --> ' + config.options.joinmode.toString()); + story.info('joinmode', `${utils.userLogString(data.username, data.id)}: --> ${config.options.joinmode.toString()}`); } else plugged.sendChat(utils.replace(langfile.error.eventmode, { username: data.username, cmd: 'Joinmode' diff --git a/lib/commands/joinwl.js b/lib/commands/joinwl.js index 5f0e4c8..9f01ebd 100644 --- a/lib/commands/joinwl.js +++ b/lib/commands/joinwl.js @@ -9,10 +9,10 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { - plugged.activatePlaylist(config.playlists.play, function () { + plugged.activatePlaylist(config.playlists.play, () => { plugged.joinWaitlist(); }); } diff --git a/lib/commands/kick.js b/lib/commands/kick.js index 989ae94..d4c65b7 100644 --- a/lib/commands/kick.js +++ b/lib/commands/kick.js @@ -13,14 +13,14 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { var split = data.message.split(' '); //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction var user = plugged.getUserByName(S(_.rest(split, 1).join(' ')).chompLeft('@').chompRight(' ').s); if (user !== undefined) { - redis.get('user:role:save:' + user.id).then(function (role) { + redis.get(`user:role:save:${user.id}`).then(role => { if (role >= perm) plugged.sendChat(utils.replace(langfile.kick.error, { mod: data.username, username: user.username @@ -30,12 +30,12 @@ module.exports = { mod: data.username, username: user.username }), 60); - plugged.banUser(user.id, plugged.BANDURATION.HOUR, plugged.BANREASON.VIOLATING_COMMUNITY_RULES, function () { - setTimeout(function () { + plugged.banUser(user.id, plugged.BANDURATION.HOUR, plugged.BANREASON.VIOLATING_COMMUNITY_RULES, () => { + setTimeout(() => { plugged.unbanUser(user.id); }, 15 * 1000); }); - story.info('lockskip', utils.userLogString(data.username, data.id) + ': ' + utils.userLogString(plugged.getUserByID(user))); + story.info('lockskip', `${utils.userLogString(data.username, data.id)}: ${utils.userLogString(plugged.getUserByID(user))}`); } }); } else { //noinspection JSUnresolvedFunction diff --git a/lib/commands/leave.js b/lib/commands/leave.js index f3be577..f6a199f 100644 --- a/lib/commands/leave.js +++ b/lib/commands/leave.js @@ -8,12 +8,12 @@ module.exports = { names: ['leave'], enabled: true, handler: function (data) { - redis.exists('meta:roulette:active').then(function (ex) { + redis.exists('meta:roulette:active').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.sismember('meta:roulette:users', data.id).then(function (mem) { + redis.sismember('meta:roulette:users', data.id).then(mem => { if (mem === 1) { //noinspection JSUnresolvedFunction - redis.srem('meta:roulette:users', data.id).then(function () { + redis.srem('meta:roulette:users', data.id).then(() => { plugged.sendChat(utils.replace(langfile.roulette.leave, {username: data.username})); }); } diff --git a/lib/commands/leavewl.js b/lib/commands/leavewl.js index f0b0e57..ac316ed 100644 --- a/lib/commands/leavewl.js +++ b/lib/commands/leavewl.js @@ -8,10 +8,10 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { - plugged.leaveWaitlist(function () { + plugged.leaveWaitlist(() => { plugged.activatePlaylist(config.playlists.none); }); } diff --git a/lib/commands/link.js b/lib/commands/link.js index 6be8e3e..0d1c254 100644 --- a/lib/commands/link.js +++ b/lib/commands/link.js @@ -13,10 +13,10 @@ module.exports = { var m = utils.clone(plugged.getMedia()); if (m.format === 1) plugged.sendChat(utils.replace(langfile.link.default, { username: data.username, - link: 'https://youtu.be/' + m.cid + link: `https://youtu.be/${m.cid}` })); else { - request.get('https://api.soundcloud.com/tracks/' + m.cid + '?client_id=' + config.apiKeys.soundcloud, function (err, resp, body) { + request.get(`https://api.soundcloud.com/tracks/${m.cid}?client_id=${config.apiKeys.soundcloud}`, (err, resp, body) => { if (!err && resp.statusCode === 200) { var json = JSON.parse(body); //noinspection JSUnresolvedVariable diff --git a/lib/commands/lock.js b/lib/commands/lock.js index 5fd2fbf..56b9153 100644 --- a/lib/commands/lock.js +++ b/lib/commands/lock.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { plugged.sendChat(utils.replace(langfile.bp_actions.lock, {username: data.username}), 70); diff --git a/lib/commands/lockdown.js b/lib/commands/lockdown.js index bd402e3..4fcbddb 100644 --- a/lib/commands/lockdown.js +++ b/lib/commands/lockdown.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.state.lockdown = !config.state.lockdown; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.lockdown.disabled, {username: data.username}), 60); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'state:lockdown', (config.state.lockdown ? 1 : 0)); - story.info('lockdown', utils.userLogString(data.username, data.id) + ': --> ' + config.state.lockdown); + story.info('lockdown', `${utils.userLogString(data.username, data.id)}: --> ${config.state.lockdown}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/lockskip.js b/lib/commands/lockskip.js index b095dc9..31b625b 100644 --- a/lib/commands/lockskip.js +++ b/lib/commands/lockskip.js @@ -12,26 +12,25 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { - redis.exists('meta:state:skipable').then(function (ex) { + redis.hget('user:roles', data.id).then(perm => { + redis.exists('meta:state:skipable').then(ex => { perm = parseInt(perm, 10); if (perm > 1 && ex === 0) { plugged.sendChat(utils.replace(langfile.skip.lockskip, {username: data.username}), 70); var booth = utils.clone(plugged.getBooth()); var media = utils.clone(plugged.getMedia()); //noinspection JSUnresolvedFunction - plugged.setCyclePromise(true).then(function () { - //noinspection JSUnresolvedFunction - return plugged.skipDJPromise(booth.dj); - }).then(function () { + plugged.setCyclePromise(true).then(() => //noinspection JSUnresolvedFunction + plugged.skipDJPromise(booth.dj)).then(() => { + redis.set('meta:state:skipable', 1, 'EX', 2); if (config.lockskip.move_pos !== undefined) plugged.moveDJ(booth.dj, config.lockskip.move_pos); return Promise.resolve(); - }).then(function () { + }).then(() => { if (booth.shouldCycle !== plugged.doesWaitlistCycle()) { //noinspection JSUnresolvedFunction return plugged.setCyclePromise(booth.shouldCycle); } else Promise.resolve(); - }).then(function () { + }).then(() => { var split = data.message.trim().split(' '); if (langfile.skip.reasons[split[1]] !== undefined) { plugged.sendChat(utils.replace(langfile.skip.reasons[split[1]], { @@ -39,10 +38,10 @@ module.exports = { song: utils.songtitle(media.author, media.title) }), 60); } - }).catch(function (err) { + }).catch(err => { story.error('Error while lockskipping.', {attach: err}); }); - story.info('lockskip', utils.userLogString(data.username, data.id) + ': ' + utils.mediatitlelog(media) + ' played by ' + utils.userLogString(plugged.getUserByID(booth.dj))); + story.info('lockskip', `${utils.userLogString(data.username, data.id)}: ${utils.mediatitlelog(media)} played by ${utils.userLogString(plugged.getUserByID(booth.dj))}`); } }); }); diff --git a/lib/commands/lockskippos.js b/lib/commands/lockskippos.js index 28bc2a2..7edcc1b 100644 --- a/lib/commands/lockskippos.js +++ b/lib/commands/lockskippos.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.trim().split(' '); @@ -21,9 +21,9 @@ module.exports = { config.lockskip.move_pos = pos; plugged.sendChat(utils.replace(langfile.skip.lockskippos, { username: data.username, - pos: pos + pos }), 30); - story.info('locksippos', utils.userLogString(data.username, data.id) + ' set Lockskippos to ' + pos); + story.info('locksippos', `${utils.userLogString(data.username, data.id)} set Lockskippos to ${pos}`); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'lockskip:move_pos', pos); } else plugged.sendChat(utils.replace(langfile.error.argument, { diff --git a/lib/commands/lottery.js b/lib/commands/lottery.js index 2d492bc..af9610c 100644 --- a/lib/commands/lottery.js +++ b/lib/commands/lottery.js @@ -11,22 +11,22 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.trim().split(' '); var t = (split.length < 2) ? 2 : parseInt(split[1]); if (!isNaN(t)) { plugged.sendChat(utils.replace(langfile.lottery.default, {username: data.username, time: t})); - if (t > 1) setTimeout(function () { + if (t > 1) setTimeout(() => { plugged.sendChat(utils.replace(langfile.lottery.one_minute, {username: data.username})); }, (t - 1) * 60 * 1000); - setTimeout(function () { + setTimeout(() => { var wl = utils.clone(plugged.getWaitlist()); choose(); function choose() { var usr = wl[_.random(0, wl.length - 1)]; - redis.exists('user:afk:' + usr).then(function (ex) { + redis.exists(`user:afk:${usr}`).then(ex => { if (ex === 1) { plugged.sendChat(utils.replace(langfile.lottery.winner, { username: plugged.getUserByID(usr).username, diff --git a/lib/commands/meh.js b/lib/commands/meh.js index 86a9935..13b96d0 100644 --- a/lib/commands/meh.js +++ b/lib/commands/meh.js @@ -12,7 +12,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { plugged.meh(); diff --git a/lib/commands/move.js b/lib/commands/move.js index 3e90449..a72d2de 100644 --- a/lib/commands/move.js +++ b/lib/commands/move.js @@ -14,7 +14,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.split(' '); @@ -28,24 +28,24 @@ module.exports = { //noinspection JSUnresolvedFunction var user = plugged.getUserByName(S(_.initial(_.rest(split, 1)).join(' ')).chompLeft('@').chompRight(' ').s); if (user !== undefined && !isNaN(pos)) { - utils.isWlBanned(user).then(function (isB) { + utils.isWlBanned(user).then(isB => { if (!isB) { plugged.sendChat(utils.replace(langfile.move.default, {username: data.username})); - if (plugged.getWaitlist().indexOf(user.id) === -1) { + if (!plugged.getWaitlist().includes(user.id)) { if (plugged.getWaitlist().length < 50) { plugged.addToWaitlist(user.id); plugged.moveDJ(user.id, pos - 1); } else { - addqueue.add(user.id, pos).then(function () { + addqueue.add(user.id, pos).then(() => { plugged.sendChat(utils.replace(langfile.move.addqueue, { username: user.username, mod: data.username, - pos: pos + pos })); }); } } else plugged.moveDJ(user.id, pos - 1); - story.info('move', utils.userLogString(data.username, data.id) + ' moved ' + utils.userLogString(user) + ' to ' + pos); + story.info('move', `${utils.userLogString(data.username, data.id)} moved ${utils.userLogString(user)} to ${pos}`); } else plugged.sendChat(utils.replace(langfile.error.wl_banned, { username: data.username, cmd: 'Move' diff --git a/lib/commands/mute.js b/lib/commands/mute.js index 7d65688..2f29b1f 100644 --- a/lib/commands/mute.js +++ b/lib/commands/mute.js @@ -13,30 +13,30 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { var split = data.message.split(' '); //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction var user = plugged.getUserByName(S(_.rest(split, 1).join(' ')).chompLeft('@').chompRight(' ').s); if (user !== undefined) { - redis.exists('user:mute:' + user.id).then(function (exm) { + redis.exists(`user:mute:${user.id}`).then(exm => { if (exm === 1) { plugged.sendChat(utils.replace(langfile.mute.already_muted, { username: user.username, mod: data.username }), 30); } else { - redis.set('user:mute:' + user.id, 1).then(function () { - redis.set('user:mute:' + user.id + ':violation', 0); + redis.set(`user:mute:${user.id}`, 1).then(() => { + redis.set(`user:mute:${user.id}:violation`, 0); //noinspection JSUnresolvedFunction - redis.expire('user:mute:' + user.id, config.chatfilter.spam.mute_duration); + redis.expire(`user:mute:${user.id}`, config.chatfilter.spam.mute_duration); }); plugged.sendChat(utils.replace(langfile.mute.default, { username: user.username, mod: data.username }), 60); - story.info('mute', utils.userLogString(data.username, data.id) + ': ' + utils.userLogString(user)); + story.info('mute', `${utils.userLogString(data.username, data.id)}: ${utils.userLogString(user)}`); } }); } else { //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction diff --git a/lib/commands/next.js b/lib/commands/next.js index 571b55a..6e9753b 100644 --- a/lib/commands/next.js +++ b/lib/commands/next.js @@ -9,10 +9,10 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 0) { - plugged.getPlaylist(config.playlists.play, function (err, list) { + plugged.getPlaylist(config.playlists.play, (err, list) => { if (!err) { if ((plugged.getCurrentDJ() !== undefined ? plugged.getCurrentDJ().id === plugged.getSelf().id : false)) { plugged.sendChat(utils.replace(langfile.next.default, { diff --git a/lib/commands/ping.js b/lib/commands/ping.js index 85343c7..77b4b83 100644 --- a/lib/commands/ping.js +++ b/lib/commands/ping.js @@ -9,7 +9,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 0) plugged.sendChat(utils.replace(langfile.ping.default, {username: data.username}), 30); }); diff --git a/lib/commands/play.js b/lib/commands/play.js index 91955f3..d07e6bd 100644 --- a/lib/commands/play.js +++ b/lib/commands/play.js @@ -10,18 +10,18 @@ module.exports = { handler: function (data) { if (config.options.joinmode) { if (!config.state.eventmode) { - utils.isWlBanned(data.id).then(function (isBanned) { + utils.isWlBanned(data.id).then(isBanned => { if (!isBanned) { - if ((function () { + if (((() => { var waitlist = plugged.getWaitlist() || []; var dj = plugged.getDJ() || {id: -1}; if (dj === data.id) return false; - else return waitlist.indexOf(data.id) === -1; - }())) { + else return !waitlist.includes(data.id); + })())) { if (plugged.getWaitlist() === undefined || plugged.getWaitlist().length < 50) { plugged.addToWaitlist(data.id); } else { - addqueue.add(data.id, 150).then(function () { + addqueue.add(data.id, 150).then(() => { plugged.sendChat(utils.replace(langfile.joinmode.add_queue, { username: data.username })); diff --git a/lib/commands/pong.js b/lib/commands/pong.js index 3656ab8..faf938f 100644 --- a/lib/commands/pong.js +++ b/lib/commands/pong.js @@ -9,7 +9,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 0) plugged.sendChat(utils.replace(langfile.ping.pong, {username: data.username}), 30); }); diff --git a/lib/commands/promote.js b/lib/commands/promote.js index 9e97491..46b9010 100644 --- a/lib/commands/promote.js +++ b/lib/commands/promote.js @@ -9,7 +9,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); var split = data.message.trim().split(' '); if (perm > 0) { diff --git a/lib/commands/reloadblacklist.js b/lib/commands/reloadblacklist.js index 7c37401..c76086c 100644 --- a/lib/commands/reloadblacklist.js +++ b/lib/commands/reloadblacklist.js @@ -10,16 +10,16 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { //noinspection JSUnresolvedFunction - redis.del('media:blacklist').then(function () { + redis.del('media:blacklist').then(() => { //noinspection JSUnresolvedFunction - db.models.Song.findAll({where: {is_banned: true}}).then(function (songs) { - songs.forEach(function (song) { + db.models.Song.findAll({where: {is_banned: true}}).then(songs => { + songs.forEach(song => { //noinspection JSUnresolvedFunction - redis.hset('media:blacklist', song.format + ':' + song.cid, ((song.ban_reason !== undefined && song.ban_reason !== null) ? song.ban_reason : 1)); + redis.hset('media:blacklist', `${song.format}:${song.cid}`, ((song.ban_reason !== undefined && song.ban_reason !== null) ? song.ban_reason : 1)); }); plugged.sendChat(utils.replace(langfile.blacklist.reload, { username: data.username, diff --git a/lib/commands/reloadcustomcommands.js b/lib/commands/reloadcustomcommands.js index a41e7d9..c6186bf 100644 --- a/lib/commands/reloadcustomcommands.js +++ b/lib/commands/reloadcustomcommands.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { customcommands._reload(); diff --git a/lib/commands/reloadroles.js b/lib/commands/reloadroles.js index 3286dd3..068bb30 100644 --- a/lib/commands/reloadroles.js +++ b/lib/commands/reloadroles.js @@ -10,17 +10,11 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { - Promise.all(plugged.getChatByUser().map(function (user) { - return db.models.find({where: {id: user.id}}); - })).then(function (users) { - return Promise.all(users.map(function (user) { - //noinspection JSUnresolvedFunction - return redis.hset('user:roles', user.id, user.s_role); - })); - }).then(function () { + Promise.all(plugged.getChatByUser().map(user => db.models.find({where: {id: user.id}}))).then(users => Promise.all(users.map(user => //noinspection JSUnresolvedFunction + redis.hset('user:roles', user.id, user.s_role)))).then(() => { plugged.sendChat(utils.replace(langfile.reloadroles.default, {username: data.username}), 30); }); } diff --git a/lib/commands/remove.js b/lib/commands/remove.js index c812a6b..aed206f 100644 --- a/lib/commands/remove.js +++ b/lib/commands/remove.js @@ -13,14 +13,14 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { var split = data.message.split(' '); //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction var user = plugged.getUserByName(S(_.rest(split, 1).join(' ')).chompLeft('@').chompRight(' ').s); if (user !== undefined) { - if (plugged.getWaitlist().indexOf(user.id) !== -1 || plugged.getCurrentDJ().id === user.id) { + if (plugged.getWaitlist().includes(user.id) || plugged.getCurrentDJ().id === user.id) { plugged.sendChat(utils.replace(langfile.bp_actions.remove, {username: data.username}), 45); plugged.removeDJ(user.id); } @@ -30,7 +30,7 @@ module.exports = { value: S(_.rest(split, 1).join(' ')).chompLeft('@').s }), 20); } - story.info('remove', utils.userLogString(data.username, data.id) + ': ' + utils.userLogString(user)); + story.info('remove', `${utils.userLogString(data.username, data.id)}: ${utils.userLogString(user)}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/removehistory.js b/lib/commands/removehistory.js index 9489dae..a69756b 100644 --- a/lib/commands/removehistory.js +++ b/lib/commands/removehistory.js @@ -15,7 +15,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.trim().split(' '); @@ -27,16 +27,16 @@ module.exports = { var url = URL.parse(split[1], true); if (url.hostname === 'youtu.be') { //noinspection JSUnresolvedFunction - remove('1:' + S(url.pathname).replaceAll('/', '').s); + remove(`1:${S(url.pathname).replaceAll('/', '').s}`); } else { //noinspection JSUnresolvedVariable if (url.hostname === 'www.youtbe.com' && url.query.v !== undefined) { //noinspection JSUnresolvedVariable - remove('1:' + url.query.v) + remove(`1:${url.query.v}`) } else if (url.hostname === 'soundcloud.com') { - request.get('https://api.soundcloud.com/resolve?client_id=' + config.apiKeys.soundcloud + '&url=' + split[1], function (err, resp, body) { + request.get(`https://api.soundcloud.com/resolve?client_id=${config.apiKeys.soundcloud}&url=${split[1]}`, (err, resp, body) => { if (!err && resp.statusCode === 200) { body = JSON.parse(body); - remove('2:' + body.id); + remove(`2:${body.id}`); } }); } else plugged.sendChat(utils.replace(langfile.error.argument, { @@ -52,10 +52,10 @@ module.exports = { function remove(mid) { //noinspection JSUnresolvedFunction - redis.del('media:history:' + mid).then(function (r) { + redis.del(`media:history:${mid}`).then(r => { if (r === 1) { plugged.sendChat(utils.replace(langfile.skip.history.remove, {username: data.username})); - story.info('History', utils.userLogString(data.username, data.id) + ' removed ' + mid + ' from the history.'); + story.info('History', `${utils.userLogString(data.username, data.id)} removed ${mid} from the history.`); } else plugged.sendChat(utils.replace(langfile.error.argument, { cmd: 'RemoveHistory', diff --git a/lib/commands/restart.js b/lib/commands/restart.js index a5e6c9f..291f443 100644 --- a/lib/commands/restart.js +++ b/lib/commands/restart.js @@ -9,28 +9,29 @@ var langfile = require('../../langfile'); //todo use env variables module.exports = { - names:['restart'], + names: ['restart'], enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 2) { + var now = data.message.includes('-n') || data.message.includes('--now'); try { var pm2 = require('pm2'); - pm2.connect(function () { + pm2.connect(() => { plugged.sendChat(utils.replace(langfile.restart.default, {username: data.username})); - setTimeout(function () { + setTimeout(() => { //noinspection JSUnresolvedFunction - redis.hset('meta:options', 'isRestart', 1).then(function () { - pm2.restart(config.pm2.pid, function (err) { + redis.hset('meta:options', 'isRestart', 1).then(() => { + pm2.restart(config.pm2.pid, err => { plugged.sendChat(utils.replace(langfile.restart.error, {username: data.username})); story.warn('restart', 'Error while restarting.', {attach: err}); //noinspection JSUnresolvedFunction redis.hdel('meta:options', 'isRestart'); }); }); - }, 3 * 1000); + }, now ? 0 : 3 * 1000); }); } catch (e) { plugged.sendChat(utils.replace(langfile.restart.error, {username: data.username})); diff --git a/lib/commands/roomname.js b/lib/commands/roomname.js index 09a60df..c4b7160 100644 --- a/lib/commands/roomname.js +++ b/lib/commands/roomname.js @@ -12,7 +12,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 2) { var split = data.message.trim().split(' '); @@ -22,7 +22,7 @@ module.exports = { plugged.updateRoomInfo(_.rest(split, 1).join(' ').trim(), meta.description, meta.welcome); plugged.sendChat(utils.replace(langfile.roomedit.roomname, {username: data.username}), 30); //noinspection JSCheckFunctionSignatures - story.info('roomname', utils.userLogString(data.username, data.id) + ': --> ' + _.rest(split, 1).join(' ').trim()); + story.info('roomname', `${utils.userLogString(data.username, data.id)}: --> ${_.rest(split, 1).join(' ').trim()}`); } else plugged.sendChat(utils.replace(langfile.error.argument, { username: data.username, cmd: 'Welcome' diff --git a/lib/commands/roulette.js b/lib/commands/roulette.js index 6526896..894b4a4 100644 --- a/lib/commands/roulette.js +++ b/lib/commands/roulette.js @@ -11,10 +11,10 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { - redis.exists('meta:roulette:active').then(function (exa) { + redis.exists('meta:roulette:active').then(exa => { if (exa === 0) { var split = data.message.trim().split(' '); var m = (split.length < 2) ? NaN : parseInt(split[1]); @@ -26,11 +26,11 @@ module.exports = { time: t, moves: m })); - setTimeout(function () { + setTimeout(() => { //noinspection JSUnresolvedFunction redis.del('meta:roulette:active'); //noinspection JSUnresolvedFunction - redis.scard('meta:roulette:users').then(function (memcount) { + redis.scard('meta:roulette:users').then(memcount => { if (memcount === 0) { plugged.sendChat(utils.replace(langfile.roulette.no_joins, {username: data.username})); } else { @@ -43,15 +43,15 @@ module.exports = { getusers(m); function getusers(count) { //noinspection JSUnresolvedFunction - redis.spop('meta:roulette:users').then(function (usr) { + redis.spop('meta:roulette:users').then(usr => { users.push(plugged.getUserByID(usr)); if (count - 1 > 0) getusers(count - 1); else { plugged.sendChat(langfile.roulette.lucky_winners); - users.forEach(function (user) { + users.forEach(user => { plugged.sendChat(utils.replace(langfile.roulette.winner, {username: user.username})); }); - users.forEach(function (user) { + users.forEach(user => { plugged.moveDJ(user.id, _.random(0, plugged.getWaitlist().length - 1)); }); //noinspection JSUnresolvedFunction diff --git a/lib/commands/setstaff.js b/lib/commands/setstaff.js index 22becee..2ceb68e 100644 --- a/lib/commands/setstaff.js +++ b/lib/commands/setstaff.js @@ -14,7 +14,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 2) { var split = data.message.split(' '); @@ -30,8 +30,8 @@ module.exports = { if (role === plugged.USERROLE.NONE) plugged.removeStaff(user.id); else plugged.addStaff(user.id, role); db.models.User.update({s_role: utils.permlevel(role)}, {where: {id: user.id}}); - redis.set('user:role:save:' + user.id, utils.permlevel(role)); - story.info('promote', utils.userLogString(data.username, data.id) + ': ' + utils.userLogString(user) + ' --> ' + utils.rolename(role)); + redis.set(`user:role:save:${user.id}`, utils.permlevel(role)); + story.info('promote', `${utils.userLogString(data.username, data.id)}: ${utils.userLogString(user)} --> ${utils.rolename(role)}`); } else { //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction plugged.sendChat(utils.replace(langfile.error.user_not_found, { username: plugged.getUserByID(data.id), diff --git a/lib/commands/shuffleplaylist.js b/lib/commands/shuffleplaylist.js index 3e9f89a..fd34425 100644 --- a/lib/commands/shuffleplaylist.js +++ b/lib/commands/shuffleplaylist.js @@ -9,7 +9,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { plugged.shufflePlaylist(config.playlists.play); diff --git a/lib/commands/skip.js b/lib/commands/skip.js index 7fa43cc..9aa8bec 100644 --- a/lib/commands/skip.js +++ b/lib/commands/skip.js @@ -11,19 +11,16 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { - redis.exists('meta:state:skipable').then(function (ex) { + redis.hget('user:roles', data.id).then(perm => { + redis.exists('meta:state:skipable').then(ex => { perm = parseInt(perm, 10); var booth = utils.clone(plugged.getBooth()); var media = utils.clone(plugged.getMedia()); if (perm > 1 && ex === 0) { plugged.sendChat(utils.replace(langfile.skip.default, {username: data.username}), 70); plugged.skipDJ(booth.dj); - redis.set('meta:state:skipable', 1).then(function () { - //noinspection JSUnresolvedFunction - redis.expire('meta:state:skipable', 2); - }); - setTimeout(function () { + redis.set('meta:state:skipable', 1, 'EX', 2); + setTimeout(() => { var split = data.message.trim().split(' '); if (langfile.skip.reasons[split[1]] !== undefined) { plugged.sendChat(utils.replace(langfile.skip.reasons[split[1]], { @@ -32,22 +29,22 @@ module.exports = { }), 60); } }, 4 * 1000); - story.info('skip', utils.userLogString(data.username, data.id) + ': ' + utils.mediatitlelog(media) + ' played by ' + utils.userLogString(plugged.getUserByID(booth.dj))); + story.info('skip', `${utils.userLogString(data.username, data.id)}: ${utils.mediatitlelog(media)} played by ${utils.userLogString(plugged.getUserByID(booth.dj))}`); } else if (perm === 1 && ex === 0 && config.rdjskip.enabled) { //noinspection JSUnresolvedFunction - redis.sismember('meta:data:rdjskip:votes', data.id).then(function (is) { + redis.sismember('meta:data:rdjskip:votes', data.id).then(is => { if (is === 0) { - redis.get('meta:data:staff:active').then(function (active) { + redis.get('meta:data:staff:active').then(active => { active = parseInt(active, 10); if (active <= config.rdjskip.max_staff_active) { //noinspection JSUnresolvedFunction - redis.scard('meta:data:rdjskip:votes').then(function (card) { + redis.scard('meta:data:rdjskip:votes').then(card => { if (card + 1 >= config.rdjskip.votes) { plugged.sendChat(utils.replace(langfile.rdjskip.skip, {username: data.username})); - story.info('skip', utils.userLogString(data.username, data.id) + ': ' + utils.mediatitlelog(media) + ' played by ' + utils.userLogString(plugged.getUserByID(booth.dj))); + story.info('skip', `${utils.userLogString(data.username, data.id)}: ${utils.mediatitlelog(media)} played by ${utils.userLogString(plugged.getUserByID(booth.dj))}`); } else { //noinspection JSUnresolvedFunction - redis.sadd('meta:data:rdjskip:votes', data.id).then(function () { + redis.sadd('meta:data:rdjskip:votes', data.id).then(() => { plugged.sendChat(utils.replace(langfile.rdjskip.default, {username: data.username})); }); } diff --git a/lib/commands/songinfo.js b/lib/commands/songinfo.js index 014eeb2..7ad52ea 100644 --- a/lib/commands/songinfo.js +++ b/lib/commands/songinfo.js @@ -23,16 +23,16 @@ module.exports = { var url = URL.parse(split[1], true); if (url.hostname === 'youtu.be') { //noinspection JSUnresolvedFunction - lookup('1:' + S(url.pathname).replaceAll('/', '').s); + lookup(`1:${S(url.pathname).replaceAll('/', '').s}`); } else { //noinspection JSUnresolvedVariable if (url.hostname === 'www.youtbe.com' && url.query.v !== undefined) { //noinspection JSUnresolvedVariable - lookup('1:' + url.query.v) + lookup(`1:${url.query.v}`) } else if (url.hostname === 'soundcloud.com') { - request.get('https://api.soundcloud.com/resolve?client_id=' + config.apiKeys.soundcloud + '&url=' + split[1], function (err, resp, body) { + request.get(`https://api.soundcloud.com/resolve?client_id=${config.apiKeys.soundcloud}&url=${split[1]}`, (err, resp, body) => { if (!err && resp.statusCode === 200) { body = JSON.parse(body); - lookup('2:' + body.id); + lookup(`2:${body.id}`); } }); } else plugged.sendChat(utils.replace(langfile.error.argument, { @@ -41,23 +41,23 @@ module.exports = { })); } } else lookup(split[1]); - } else lookup(plugged.getMedia().format + ':' + plugged.getMedia().cid); + } else lookup(`${plugged.getMedia().format}:${plugged.getMedia().cid}`); function lookup(sid) { //noinspection JSUnresolvedFunction if (sid.length > 8 && S(sid).contains(':')) { var sp = sid.split(':'); - db.models.Song.find({where: {cid: sp[1], format: sp[0]}}).then(function (song) { + db.models.Song.find({where: {cid: sp[1], format: sp[0]}}).then(song => { if (song !== null && song !== undefined) { - redis.exists('media:blacklist:' + song.format + ':' + song.cid).then(function (bl) { - redis.exists('media:history:' + song.format + ':' + song.cid).then(function (his) { + redis.exists(`media:blacklist:${song.format}:${song.cid}`).then(bl => { + redis.exists(`media:history:${song.format}:${song.cid}`).then(his => { plugged.sendChat(utils.replace(langfile.songinfo.default, { username: data.username, title: utils.songtitle(song.author, song.title), - bl: (bl === 1) ? ((song.ban_reason !== undefined && song.ban_reason !== null) ? true.toString() + ' ' + utils.replace(langfile.songinfo.bl_reason, {reason: song.ban_reason}) : true.toString()) : false.toString(), + bl: (bl === 1) ? ((song.ban_reason !== undefined && song.ban_reason !== null) ? `${true.toString()} ${utils.replace(langfile.songinfo.bl_reason, {reason: song.ban_reason})}` : true.toString()) : false.toString(), his: (his === 1).toString(), - sid: sid + sid })); }); }); diff --git a/lib/commands/soundcloudblock.js b/lib/commands/soundcloudblock.js index 8e2d57a..f1f08d5 100644 --- a/lib/commands/soundcloudblock.js +++ b/lib/commands/soundcloudblock.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.soundcloudGuard.block = !config.soundcloudGuard.block; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.soundcloudGuard.block_disabled, {username: data.username}), 60); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'soundcloudguard:block:enabled', (config.soundcloudGuard.block ? 1 : 0)); - story.info('soundcloudblock', utils.userLogString(data.username, data.id) + ': --> ' + config.soundcloudGuard.block.toString()); + story.info('soundcloudblock', `${utils.userLogString(data.username, data.id)}: --> ${config.soundcloudGuard.block.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/soundcloudguard.js b/lib/commands/soundcloudguard.js index d7ee95f..9ce8e23 100644 --- a/lib/commands/soundcloudguard.js +++ b/lib/commands/soundcloudguard.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.soundcloudGuard.enabled = !config.soundcloudGuard.enabled; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.soundcloudGuard.disabled, {username: data.username}), 60); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'soundcloudguard:enabled', (config.soundcloudGuard.enabled ? 1 : 0)); - story.info('soundcloudguard', utils.userLogString(data.username, data.id) + ': --> ' + config.soundcloudGuard.enabled.toString()); + story.info('soundcloudguard', `${utils.userLogString(data.username, data.id)}: --> ${config.soundcloudGuard.enabled.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/staff.js b/lib/commands/staff.js new file mode 100644 index 0000000..4c5a0fa --- /dev/null +++ b/lib/commands/staff.js @@ -0,0 +1,17 @@ +var S = require('string'); + +var plugged = require('../client'); +var redis = require('../db/redis_db'); +var config = require('../../config'); +var utils = require('../utils'); +var langfile = require('../../langfile'); +var db = require('../db/sql_db'); + +module.exports = { + names: ['staff'], + enabled: true, + handler: function (data) { + plugged.sendChat(utils.replace(langfile.staff.default, {username: data.username})); + plugged.removeChatMessage(data.cid); + } +}; \ No newline at end of file diff --git a/lib/commands/state.js b/lib/commands/state.js index 91e8848..34cdd03 100644 --- a/lib/commands/state.js +++ b/lib/commands/state.js @@ -9,7 +9,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { var strings = [ @@ -63,7 +63,7 @@ module.exports = { val: config.options.joinmode.toString() }) ]; - strings.forEach(function (str) { + strings.forEach(str => { plugged.sendChat(str); }); } diff --git a/lib/commands/superuser.js b/lib/commands/superuser.js index 9313887..e0f1d6d 100644 --- a/lib/commands/superuser.js +++ b/lib/commands/superuser.js @@ -13,7 +13,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 2) { var split = data.message.split(' '); @@ -21,7 +21,7 @@ module.exports = { //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction var user = plugged.getUserByName(S(_.rest(split, 1).join(' ')).chompLeft('@').chompRight(' ').s); if (user !== undefined) { - db.models.User.find({where: {id: user.id}}).then(function (usr) { + db.models.User.find({where: {id: user.id}}).then(usr => { usr.updateAttributes({super_user: !usr.super_user}); if (usr.super_user) plugged.sendChat(utils.replace(langfile.superuser.add, { mod: data.username, diff --git a/lib/commands/swap.js b/lib/commands/swap.js index 54d3e97..2215884 100644 --- a/lib/commands/swap.js +++ b/lib/commands/swap.js @@ -10,9 +10,10 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { + if(data.message.includes(' -nl')) {var noLock = true;data.message=data.message.replace(' -nl','')} var split = data.message.split('@'); if (split.length === 3) { //noinspection JSUnresolvedFunction @@ -34,7 +35,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.swap.no_wl, {username: data.username})); function swapOutWaitlist(inWl, outWL) { - utils.isWlBanned([inWl, outWL]).then(function (isB) { + utils.isWlBanned([inWl, outWL]).then(isB => { if (!isB) { var pos = utils.wlPosition(inWl); var lock = plugged.isWaitlistLocked(); @@ -43,14 +44,18 @@ module.exports = { u1: u1.username, u2: u2.username })); - plugged.setLock(true, false, function () { - plugged.removeDJ(inWl, function () { - plugged.addToWaitlist(outWL, function () { + + if(noLock)doIt(); + else plugged.setLock(true,false,doIt); + + function doIt(){ + plugged.removeDJ(inWl, () => { + plugged.addToWaitlist(outWL, () => { plugged.moveDJ(outWL, pos); - plugged.setLock(lock, false); + if(!noLock)plugged.setLock(lock, false); }); }); - }); + } } else plugged.sendChat(utils.replace(langfile.error.wl_banned, { username: data.username, cmd: 'Swap' diff --git a/lib/commands/timeguard.js b/lib/commands/timeguard.js index c4e9a36..dc9d9a3 100644 --- a/lib/commands/timeguard.js +++ b/lib/commands/timeguard.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { if (!config.state.eventmode) { @@ -20,7 +20,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.skip.timeguard.disabled, {username: data.username}), 60); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'timeguard:enabled', (config.timeguard.enabled ? 1 : 0)); - story.info('timeguard', utils.userLogString(data.username, data.id) + ': --> ' + config.timeguard.enabled.toString()); + story.info('timeguard', `${utils.userLogString(data.username, data.id)}: --> ${config.timeguard.enabled.toString()}`); } else plugged.sendChat(utils.replace(langfile.error.eventmode, { username: data.username, cmd: 'Timeguard' diff --git a/lib/commands/titleguard.js b/lib/commands/titleguard.js index 83eb2f5..a5eb490 100644 --- a/lib/commands/titleguard.js +++ b/lib/commands/titleguard.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.titleguard.enabled = !config.titleguard.enabled; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.titleguard.disabled, {username: data.username}), 60); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'titleguard:enabled', (config.youtubeGuard.enabled ? 1 : 0)); - story.info('titleguard', utils.userLogString(data.username, data.id) + ': --> ' + config.titleguard.enabled.toString()); + story.info('titleguard', `${utils.userLogString(data.username, data.id)}: --> ${config.titleguard.enabled.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/toggleafk.js b/lib/commands/toggleafk.js index d92bfad..20ee222 100644 --- a/lib/commands/toggleafk.js +++ b/lib/commands/toggleafk.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.afk.enabled = !config.afk.enabled; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.afk.disabled, {username: data.username}), 30); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'afk:enabled', (config.afk.enabled ? 1 : 0)); - story.info('afk', utils.userLogString(data.username, data.id) + ': --> ' + config.afk.enabled.toString()); + story.info('afk', `${utils.userLogString(data.username, data.id)}: --> ${config.afk.enabled.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/togglecustomcommands.js b/lib/commands/togglecustomcommands.js index 9ef8303..c0afa2f 100644 --- a/lib/commands/togglecustomcommands.js +++ b/lib/commands/togglecustomcommands.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.customcommands.enabled = !config.customcommands.enabled; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.customcommands.disabled, {username: data.username}), 30); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'customcommands:enabled', (config.state.eventmode ? 1 : 0)); - story.info('customcommands', utils.userLogString(data.username, data.id) + ': --> ' + config.customcommands.enabled.toString()); + story.info('customcommands', `${utils.userLogString(data.username, data.id)}: --> ${config.customcommands.enabled.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/tskip.js b/lib/commands/tskip.js new file mode 100644 index 0000000..d5f76d1 --- /dev/null +++ b/lib/commands/tskip.js @@ -0,0 +1,7 @@ +module.exports = { + names: ['tskip', 'timedskip'], + enabled: false, + handler: function (data) { + //todo implement + } +}; \ No newline at end of file diff --git a/lib/commands/unban.js b/lib/commands/unban.js index 05fc693..fc0ed0a 100644 --- a/lib/commands/unban.js +++ b/lib/commands/unban.js @@ -1,3 +1,6 @@ +var S = require('string'); +var _ = require('underscore'); + var plugged = require('../client'); var redis = require('../db/redis_db'); var config = require('../../config'); @@ -5,14 +8,30 @@ var utils = require('../utils'); var langfile = require('../../langfile'); module.exports = { - names:['unban'], - enabled: false, + names: ['unban'], + enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { - //todo + var username = S(_.rest(data.message.split(' '))).chompRight(' ').chompLeft('@').s; + plugged.getBans((err, bans)=> { + if (err) { + //todo + } else { + var ban = bans.filter(ban=>ban.username === username); + if (ban) { + plugged.unbanUser(ban.id, (err)=> { + if (!err) { + //todo + } + }) + } else { + //todo + } + } + }) } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/unblacklist.js b/lib/commands/unblacklist.js index 490de42..cf62caf 100644 --- a/lib/commands/unblacklist.js +++ b/lib/commands/unblacklist.js @@ -16,7 +16,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.trim().split(' '); @@ -29,14 +29,14 @@ module.exports = { if (url.hostname === 'youtu.be') { //noinspection JSUnresolvedFunction var cid = S(url.pathname).replaceAll('/', '').s; - db.blacklist.remove(1, cid).then(function (song) { + db.blacklist.remove(1, cid).then(song => { if (song !== null && song !== undefined) { db.blacklist.remove(song.format, song.cid); plugged.sendChat(utils.replace(langfile.blacklist.unbl.default, { username: data.username, song: utils.songtitle(song.author, song.title) }), 30); - story.info('unbl', utils.userLogString(data.username, data.id) + ' removed ' + utils.songtitle(song.author, song.title) + '[' + song.format + ':' + song.cid + '] from the blacklist.'); + story.info('unbl', `${utils.userLogString(data.username, data.id)} removed ${utils.songtitle(song.author, song.title)}[${song.format}:${song.cid}] from the blacklist.`); } else plugged.sendChat(utils.replace(langfile.error.argument, { username: data.username, cmd: 'UnBl' @@ -45,31 +45,31 @@ module.exports = { } else { //noinspection JSUnresolvedVariable if (url.hostname === 'www.youtube.com' && url.query.v !== undefined) { //noinspection JSUnresolvedVariable - db.models.Song.find({where: {format: 1, cid: url.query.v}}).then(function (song) { + db.models.Song.find({where: {format: 1, cid: url.query.v}}).then(song => { if (song !== undefined && song !== null) { db.blacklist.remove(song.format, song.cid); plugged.sendChat(utils.replace(langfile.blacklist.unbl.default, { username: data.username, song: utils.songtitle(song.author, song.title) }), 30); - story.info('unbl', utils.userLogString(data.username, data.id) + ' removed ' + utils.songtitle(song.author, song.title) + '[' + song.format + ':' + song.cid + '] from the blacklist.'); + story.info('unbl', `${utils.userLogString(data.username, data.id)} removed ${utils.songtitle(song.author, song.title)}[${song.format}:${song.cid}] from the blacklist.`); } else plugged.sendChat(utils.replace(langfile.error.argument, { username: data.username, cmd: 'UnBl' }), 20); }); } else if (url.hostname === 'soundcloud.com') { - request.get('http://api.soundcloud.com/resolve?url=' + split[1] + '&client_id=' + config.apiKeys.soundcloud, function (err, resp, body) { + request.get(`http://api.soundcloud.com/resolve?url=${split[1]}&client_id=${config.apiKeys.soundcloud}`, (err, resp, body) => { if (!err && resp.statusCode === 200) { body = JSON.parse(body); - db.models.Song.find({where: {format: 2, cid: body.id}}).then(function (song) { + db.models.Song.find({where: {format: 2, cid: body.id}}).then(song => { if (song !== undefined && song !== null) { db.blacklist.remove(song.format, song.cid); plugged.sendChat(utils.replace(langfile.blacklist.unbl.default, { username: data.username, song: utils.songtitle(song.author, song.title) }), 30); - story.info('unbl', utils.userLogString(data.username, data.id) + ' removed ' + utils.songtitle(song.author, song.title) + '[' + song.format + ':' + song.cid + '] from the blacklist.'); + story.info('unbl', `${utils.userLogString(data.username, data.id)} removed ${utils.songtitle(song.author, song.title)}[${song.format}:${song.cid}] from the blacklist.`); } else plugged.sendChat(utils.replace(langfile.error.argument, { username: data.username, cmd: 'UnBl' @@ -84,21 +84,21 @@ module.exports = { } } else { var args = split[1].split(':'); - if (args.length === 2 && ['1', '2'].indexOf(args[0]) !== -1) { + if (args.length === 2 && ['1', '2'].includes(args[0])) { db.models.Song.find({ where: { is_banned: true, format: args[0], cid: args[1] } - }).then(function (song) { + }).then(song => { if (song !== null && song !== undefined) { db.blacklist.remove(args[0], args[1]); plugged.sendChat(utils.replace(langfile.blacklist.unbl.default, { username: data.username, song: utils.songtitle(song.author, song.title) }), 30); - story.info('unbl', utils.userLogString(data.username, data.id) + ' removed ' + utils.songtitle(song.author, song.title) + '[' + song.format + ':' + song.cid + '] from the blacklist.'); + story.info('unbl', `${utils.userLogString(data.username, data.id)} removed ${utils.songtitle(song.author, song.title)}[${song.format}:${song.cid}] from the blacklist.`); } else plugged.sendChat(utils.replace(langfile.error.argument, { username: data.username, cmd: 'UnBl' diff --git a/lib/commands/unlock.js b/lib/commands/unlock.js index d499461..00de0db 100644 --- a/lib/commands/unlock.js +++ b/lib/commands/unlock.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if ((config.options.bouncer_plus ? (perm > 1) : (perm > 2))) { plugged.sendChat(utils.replace(langfile.bp_actions.unlock, {username: data.username}), 70); diff --git a/lib/commands/unmute.js b/lib/commands/unmute.js index 020b98e..df71bc4 100644 --- a/lib/commands/unmute.js +++ b/lib/commands/unmute.js @@ -13,26 +13,26 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.split(' '); //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction var user = plugged.getUserByName(S(_.rest(split, 1).join(' ')).chompLeft('@').chompRight(' ').s); if (user !== undefined) { - redis.exists('user:mute:' + user.id).then(function (exm) { + redis.exists(`user:mute:${user.id}`).then(exm => { if (exm === 1) { //noinspection JSUnresolvedFunction - redis.del('user:mute:' + user.id).then(function () { + redis.del(`user:mute:${user.id}`).then(() => { //noinspection JSUnresolvedFunction - redis.del('user:mute:' + user.id + ':violation'); + redis.del(`user:mute:${user.id}:violation`); plugged.unmuteUser(user.id); }); plugged.sendChat(utils.replace(langfile.unmute.default, { username: user.username, mod: data.username }), 60); - story.info('unmute', utils.userLogString(data.username, data.id) + ': ' + utils.userLogString(user)); + story.info('unmute', `${utils.userLogString(data.username, data.id)}: ${utils.userLogString(user)}`); } else plugged.sendChat(utils.replace(langfile.unmute.not_muted, { mod: data.username, username: user.username diff --git a/lib/commands/uptime.js b/lib/commands/uptime.js index cee857b..3f585ea 100644 --- a/lib/commands/uptime.js +++ b/lib/commands/uptime.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 0) { //noinspection JSUnresolvedFunction diff --git a/lib/commands/voteskip.js b/lib/commands/voteskip.js index 7b8c228..37ea3f1 100644 --- a/lib/commands/voteskip.js +++ b/lib/commands/voteskip.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { if (!config.state.eventmode) { @@ -20,7 +20,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.skip.vote.disabled, {username: data.username}), 30); //noinspection JSUnresolvedFunction redis.hset('meta:config','voteskip:enabled', (config.voteskip.enabled ? 1 : 0)); - story.info('voteskip', utils.userLogString(data.username, data.id) + ': --> ' + config.voteskip.enabled.toString()); + story.info('voteskip', `${utils.userLogString(data.username, data.id)}: --> ${config.voteskip.enabled.toString()}`); } else plugged.sendChat(utils.replace(langfile.error.eventmode, { username: data.username, cmd: 'Voteskip' diff --git a/lib/commands/welcomemsg.js b/lib/commands/welcomemsg.js index 533631c..c7bf911 100644 --- a/lib/commands/welcomemsg.js +++ b/lib/commands/welcomemsg.js @@ -12,7 +12,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 2) { var split = data.message.trim().split(' '); @@ -26,7 +26,7 @@ module.exports = { } plugged.sendChat(utils.replace(langfile.roomedit.welcomemsg, {username: data.username}), 30); //noinspection JSCheckFunctionSignatures - story.info('welcomemsg', utils.userLogString(data.username, data.id) + ': --> ' + _.rest(split, 1).join(' ').trim()); + story.info('welcomemsg', `${utils.userLogString(data.username, data.id)}: --> ${_.rest(split, 1).join(' ').trim()}`); } else plugged.sendChat(utils.replace(langfile.error.argument, { username: data.username, cmd: 'Welcome' diff --git a/lib/commands/wlban.js b/lib/commands/wlban.js index 01be2d6..c7336a2 100644 --- a/lib/commands/wlban.js +++ b/lib/commands/wlban.js @@ -12,7 +12,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (perm > 1) { var split = data.message.split(' '); @@ -24,7 +24,7 @@ module.exports = { username: user.username, mod: data.username })); - redis.set('user:waitlist:ban:' + user.id, 1); + redis.set(`user:waitlist:ban:${user.id}`, 1); if (utils.wlPosition(user.id) !== -1) plugged.removeDJ(user.id); } } diff --git a/lib/commands/wlunban.js b/lib/commands/wlunban.js index da3f276..f7b6fad 100644 --- a/lib/commands/wlunban.js +++ b/lib/commands/wlunban.js @@ -12,7 +12,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles',data.id).then(function (perm) { + redis.hget('user:roles',data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { var split = data.message.split(' '); @@ -25,7 +25,7 @@ module.exports = { mod: data.username })); //noinspection JSUnresolvedFunction - redis.del('user:waitlist:ban:' + user.id); + redis.del(`user:waitlist:ban:${user.id}`); } } } diff --git a/lib/commands/woot.js b/lib/commands/woot.js index c28d362..1ecd76b 100644 --- a/lib/commands/woot.js +++ b/lib/commands/woot.js @@ -12,7 +12,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { plugged.woot(); diff --git a/lib/commands/youtubeblock.js b/lib/commands/youtubeblock.js index ef33bc3..1df9595 100644 --- a/lib/commands/youtubeblock.js +++ b/lib/commands/youtubeblock.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.youtubeGuard.block = !config.youtubeGuard.block; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.youtubeGuard.block_disabled, {username: data.username}), 60); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'youtubeguard:block:enabled', (config.youtubeGuard.block ? 1 : 0)); - story.info('youtubeblock', utils.userLogString(data.username, data.id) + ': --> ' + config.youtubeGuard.block.toString()); + story.info('youtubeblock', `${utils.userLogString(data.username, data.id)}: --> ${config.youtubeGuard.block.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/commands/youtubeguard.js b/lib/commands/youtubeguard.js index 3df78e1..caf00d8 100644 --- a/lib/commands/youtubeguard.js +++ b/lib/commands/youtubeguard.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, handler: function (data) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (config.options.bouncer_plus ? (perm > 1) : (perm > 2)) { config.youtubeGuard.enabled = !config.youtubeGuard.enabled; @@ -19,7 +19,7 @@ module.exports = { else plugged.sendChat(utils.replace(langfile.youtubeGuard.disabled, {username: data.username}), 60); //noinspection JSUnresolvedFunction redis.hset('meta:config', 'youtubeguard:enabled', (config.youtubeGuard.enabled ? 1 : 0)); - story.info('youtubeguard', utils.userLogString(data.username, data.id) + ': --> ' + config.youtubeGuard.enabled.toString()); + story.info('youtubeguard', `${utils.userLogString(data.username, data.id)}: --> ${config.youtubeGuard.enabled.toString()}`); } }); plugged.removeChatMessage(data.cid); diff --git a/lib/customcommands.js b/lib/customcommands.js index 615e4bd..353e30f 100644 --- a/lib/customcommands.js +++ b/lib/customcommands.js @@ -14,22 +14,18 @@ var cckeys = Object.keys(config.defaultCC); load(); function load() { - Promise.all(cckeys.map(function (key) { - return db.models.CustomCommand.upsert({ - trigger: key, - message: config.defaultCC[key].msg, - senderinfo: config.defaultCC[key].sender - }); - })).then(function () { - //noinspection JSUnresolvedFunction - return db.models.CustomCommand.findAll({where: {status: true}}); - }).each(function (cc) { + Promise.all(cckeys.map(key => db.models.CustomCommand.upsert({ + trigger: key, + message: config.defaultCC[key].msg, + senderinfo: config.defaultCC[key].sender + }))).then(() => //noinspection JSUnresolvedFunction + db.models.CustomCommand.findAll({where: {status: true}})).each(cc => { customcommands[cc.trigger] = { trigger: cc.trigger, message: cc.message, senderinfo: cc.senderinfo, allowMention: cc.allowMention, - handler: function (data) { + handler: (data)=> { if (cc.allowMention === false) { plugged.sendChat(utils.replace(langfile.customcommand[(cc.senderinfo ? 'default' : 'nosenderinfo')], { username: data.username, diff --git a/lib/db/models/Channel.js b/lib/db/models/Channel.js index 604e17e..81bc833 100644 --- a/lib/db/models/Channel.js +++ b/lib/db/models/Channel.js @@ -1,12 +1,10 @@ -module.exports = function (sequelize, Sequelize) { - return sequelize.define('Song', { - id: {type: Sequelize.INTEGER.UNSIGNED, autoIncrement: true, unique: true}, - name: {type: Sequelize.STRING, allowNull: true}, - cid: {type: Sequelize.STRING(161), allowNull: true, primaryKey: true, unique: true}, - is_banned: {type: Sequelize.BOOLEAN, defaultValue: false}, - ban_reason: {type: Sequelize.TEXT} - }, { - underscored: true, - tableName: 'channels' - }); -}; \ No newline at end of file +module.exports = (sequelize, Sequelize) => sequelize.define('Song', { + id: {type: Sequelize.INTEGER.UNSIGNED, autoIncrement: true, unique: true}, + name: {type: Sequelize.STRING, allowNull: true}, + cid: {type: Sequelize.STRING(161), allowNull: true, primaryKey: true, unique: true}, + is_banned: {type: Sequelize.BOOLEAN, defaultValue: false}, + ban_reason: {type: Sequelize.TEXT} +}, { + underscored: true, + tableName: 'channels' +}); \ No newline at end of file diff --git a/lib/db/models/CustomCommand.js b/lib/db/models/CustomCommand.js index 155063b..446eb0d 100644 --- a/lib/db/models/CustomCommand.js +++ b/lib/db/models/CustomCommand.js @@ -1,13 +1,11 @@ -module.exports = function (sequelize, Sequelize) { - return sequelize.define("CustomCommand", { - id: {type: Sequelize.INTEGER.UNSIGNED, primaryKey: true, unique: true, autoIncrement: true}, - trigger: {type: Sequelize.STRING(191), allowNull: false, unique: true}, - message: {type: Sequelize.STRING, allowNull: false}, - status: {type: Sequelize.BOOLEAN, defaultValue: true}, - senderinfo: {type: Sequelize.BOOLEAN, defaultValue: true, allowNull: false}, - allowMention: {type: Sequelize.BOOLEAN, defaultValue: true, allowNull: false} - }, { - underscored: true, - tableName: 'customcommands' - }) -}; \ No newline at end of file +module.exports = (sequelize, Sequelize) => sequelize.define("CustomCommand", { + id: {type: Sequelize.INTEGER.UNSIGNED, primaryKey: true, unique: true, autoIncrement: true}, + trigger: {type: Sequelize.STRING(191), allowNull: false, unique: true}, + message: {type: Sequelize.STRING, allowNull: false}, + status: {type: Sequelize.BOOLEAN, defaultValue: true}, + senderinfo: {type: Sequelize.BOOLEAN, defaultValue: true, allowNull: false}, + allowMention: {type: Sequelize.BOOLEAN, defaultValue: true, allowNull: false} +}, { + underscored: true, + tableName: 'customcommands' +}); \ No newline at end of file diff --git a/lib/db/models/Play.js b/lib/db/models/Play.js index 1404cc7..03da16a 100644 --- a/lib/db/models/Play.js +++ b/lib/db/models/Play.js @@ -1,14 +1,12 @@ -module.exports = function(sequelize, Sequelize) { - return sequelize.define('Play', { - id: {type: Sequelize.INTEGER.UNSIGNED, primaryKey: true, autoIncrement: true, unique: true}, - woots: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, - grabs: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, - mehs: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, - listeners: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, - time: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}, - skipped: {type: Sequelize.BOOLEAN, defaultValue: false} - }, { - underscored: true, - tableName: 'plays' - }) -}; \ No newline at end of file +module.exports = (sequelize, Sequelize) => sequelize.define('Play', { + id: {type: Sequelize.INTEGER.UNSIGNED, primaryKey: true, autoIncrement: true, unique: true}, + woots: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, + grabs: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, + mehs: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, + listeners: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, + time: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}, + skipped: {type: Sequelize.BOOLEAN, defaultValue: false} +}, { + underscored: true, + tableName: 'plays' +}); \ No newline at end of file diff --git a/lib/db/models/Song.js b/lib/db/models/Song.js index 9cd32aa..05d7faa 100644 --- a/lib/db/models/Song.js +++ b/lib/db/models/Song.js @@ -1,34 +1,19 @@ var S = require('string'); -module.exports = function (sequelize, Sequelize) { - return sequelize.define('Song', { - id: {type: Sequelize.INTEGER.UNSIGNED, autoIncrement: true, unique: true}, - author: {type: Sequelize.STRING, allowNull: true}, - title: {type: Sequelize.STRING, allowNull: true}, - slug: {type: Sequelize.STRING, allowNull: true}, - format: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false}, - cid: {type: Sequelize.STRING(20), allowNull: false, unique: true}, - plug_id: {type: Sequelize.INTEGER.UNSIGNED, unique: true, allowNull: false, primaryKey: true}, - duration: {type: Sequelize.INTEGER.UNSIGNED}, - image: {type: Sequelize.STRING}, - is_banned: {type: Sequelize.BOOLEAN, defaultValue: false}, - ban_reason: {type: Sequelize.TEXT}, - tskip: {type: Sequelize.INTEGER.UNSIGNED, allowNull: true, defaultValue: null}, - autovote: {type: Sequelize.ENUM('n', 'w', 'm'), allowNull: false, defaultValue: 'n'} - }, { - underscored: true, - tableName: 'songs', - setterMethods: { - title: function (v) { - //noinspection JSUnresolvedFunction - var formattedSlug = S(this.getDataValue('author') + '-' + v).slugify().s; - this.setDataValue('slug', formattedSlug); - return this.setDataValue('title', v); - }, - slug: function (v) { - //noinspection JSUnresolvedFunction - return this.setDataValue('slug', S(v).slugify().s); - } - } - }); -}; \ No newline at end of file +module.exports = (sequelize, Sequelize) => sequelize.define('Song', { + id: {type: Sequelize.INTEGER.UNSIGNED, autoIncrement: true, unique: true}, + author: {type: Sequelize.STRING, allowNull: true}, + title: {type: Sequelize.STRING, allowNull: true}, + format: {type: Sequelize.INTEGER.UNSIGNED, allowNull: false}, + cid: {type: Sequelize.STRING(20), allowNull: false, unique: true}, + plug_id: {type: Sequelize.INTEGER.UNSIGNED, unique: true, allowNull: false, primaryKey: true}, + duration: {type: Sequelize.INTEGER.UNSIGNED}, + image: {type: Sequelize.STRING}, + is_banned: {type: Sequelize.BOOLEAN, defaultValue: false}, + ban_reason: {type: Sequelize.TEXT}, + tskip: {type: Sequelize.INTEGER.UNSIGNED, allowNull: true, defaultValue: null}, + autovote: {type: Sequelize.ENUM('n', 'w', 'm'), allowNull: false, defaultValue: 'n'} +}, { + underscored: true, + tableName: 'songs' +}); \ No newline at end of file diff --git a/lib/db/models/User.js b/lib/db/models/User.js index 03ddc6b..463cb4c 100644 --- a/lib/db/models/User.js +++ b/lib/db/models/User.js @@ -1,28 +1,25 @@ -module.exports = function (sequelize, Sequelize) { - return sequelize.define("User", { - id: {type: Sequelize.INTEGER.UNSIGNED, primaryKey: true, unique: true}, - username: {type: Sequelize.STRING, allowNull: false}, - slug: {type: Sequelize.STRING, allowNull: false}, - language: {type: Sequelize.STRING, defaultValue: 'en'}, - avatar_id: {type: Sequelize.STRING}, - badge: {type: Sequelize.STRING}, - blurb: {type: Sequelize.TEXT}, - global_role: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, - role: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, - super_user: {type: Sequelize.BOOLEAN, defaultValue: false}, - s_role: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, - level: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, - custom_points: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, - joined: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}, - birthday: {type: Sequelize.DATE}, - status: {type: Sequelize.BOOLEAN, defaultValue: true}, - afk_msg: {type: Sequelize.TEXT, allowNull: true}, - last_seen: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}, - last_active: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}, - afk_level: {type: Sequelize.ENUM('active', 'afk', 'warned', 'warned2'), defaultValue: 'active'}, - wl_removes: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0} - }, { - underscored: true, - tableName: 'users' - }) -}; \ No newline at end of file +module.exports = (sequelize, Sequelize) => sequelize.define("User", { + id: {type: Sequelize.INTEGER.UNSIGNED, primaryKey: true, unique: true}, + username: {type: Sequelize.STRING, allowNull: false}, + language: {type: Sequelize.STRING, defaultValue: 'en'}, + avatar_id: {type: Sequelize.STRING}, + badge: {type: Sequelize.STRING}, + blurb: {type: Sequelize.TEXT}, + global_role: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, + role: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, + super_user: {type: Sequelize.BOOLEAN, defaultValue: false}, + s_role: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, + level: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, + custom_points: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0}, + joined: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}, + birthday: {type: Sequelize.DATE}, + status: {type: Sequelize.BOOLEAN, defaultValue: true}, + afk_msg: {type: Sequelize.TEXT, allowNull: true}, + last_seen: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}, + last_active: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}, + afk_level: {type: Sequelize.ENUM('active', 'afk', 'warned', 'warned2'), defaultValue: 'active'}, + wl_removes: {type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0} +}, { + underscored: true, + tableName: 'users' +}); \ No newline at end of file diff --git a/lib/db/sql_db.js b/lib/db/sql_db.js index b8e5b49..1e4f721 100644 --- a/lib/db/sql_db.js +++ b/lib/db/sql_db.js @@ -2,95 +2,120 @@ var Sequelize = require('sequelize'); var path = require('path'); var story = require('storyboard').mainStory; var Promise = require('bluebird'); +var EventEmitter = require('events'); var config = require('../load_config'); var redis = require('./redis_db'); -config.sequelize.options.logging = function (toLog) { - if (config.options.sql_debug)story.debug('sql', toLog); -}; +class Database { + constructor() { + this.ready = false; + this.emitter = new EventEmitter(); + var that = this; + config.sequelize.options.logging = toLog => { + if (config.options.sql_debug)story.debug('sql', toLog); + }; + this.sequelize = new Sequelize(config.sequelize.database, config.sequelize.username, config.sequelize.password, config.sequelize.options); -var sequelize = new Sequelize(config.sequelize.database, config.sequelize.username, config.sequelize.password, config.sequelize.options); -var models = { - User: sequelize.import(path.join(__dirname, 'models', 'User')), - Play: sequelize.import(path.join(__dirname, 'models', 'Play')), - Song: sequelize.import(path.join(__dirname, 'models', 'Song')), - CustomCommand: sequelize.import(path.join(__dirname, 'models', 'CustomCommand')), - Channel: sequelize.import(path.join(__dirname, 'models', 'Channel')) -}; + this.models = { + User: that.sequelize.import(path.join(__dirname, 'models', 'User')), + Play: that.sequelize.import(path.join(__dirname, 'models', 'Play')), + Song: that.sequelize.import(path.join(__dirname, 'models', 'Song')), + CustomCommand: that.sequelize.import(path.join(__dirname, 'models', 'CustomCommand')), + Channel: that.sequelize.import(path.join(__dirname, 'models', 'Channel')) + }; -models.Play.belongsTo(models.Song); -models.Song.hasMany(models.Play); -models.Play.belongsTo(models.User); -models.User.hasMany(models.Play); + this.models.Play.belongsTo(this.models.Song); + this.models.Play.belongsTo(this.models.User); + this.models.Song.hasMany(this.models.Play); + this.models.User.hasMany(this.models.Play); -sequelize.sync(); - -module.exports = { - models: models, - sequelize: sequelize, - channelblacklist: { - add: function (cid, reason) { - return models.Channel.upsert({ - cid: cid, - is_banned: true, - ban_reason: (reason !== null && reason !== undefined ? reason : null) - }).then(function () { - //noinspection JSUnresolvedFunction - return redis.hset('media:blacklist', cid, (reason !== null && reason !== undefined ? reason : '1')) - }) - }, - remove: function (cid) { - return models.Channel.update({ - is_banned: false, - ban_reason: null - }, {where: {cid: cid}}).then(function () { - //noinspection JSUnresolvedFunction - return redis.hdel('media:channelblacklist', cid); - }); - } - }, - blacklist: { - add: function (format, cid, reason) { - if (typeof format === 'object') { - reason = cid; - cid = format.cid; - format = format.format + this.channelblacklist = { + add: function (cid, reason) { + return that.models.Channel.upsert({ + cid, + is_banned: true, + ban_reason: (reason !== null && reason !== undefined ? reason : null) + }).then(() => //noinspection JSUnresolvedFunction + redis.hset( + 'media:blacklist', + cid, + reason !== null && reason !== undefined ? reason : '1' + )) + }, + remove: function (cid) { + return that.models.Channel.update({ + is_banned: false, + ban_reason: null + }, {where: {cid}}).then(() => //noinspection JSUnresolvedFunction + redis.hdel('media:channelblacklist', cid)); } - if (reason === undefined || reason === null) reason = 1; - return new Promise(function (resolve, reject) { - //noinspection JSUnresolvedFunction - redis.hset('media:blacklist', format + ':' + cid, reason).then(function () { - return models.Song.findOrCreate({ + }; + this.blacklist = { + add: function (format, cid, reason) { + if (typeof format === 'object') { + reason = cid; + cid = format.cid; + format = format.format + } + if (reason === undefined || reason === null) reason = 1; + return new Promise((resolve, reject) => { + //noinspection JSUnresolvedFunction + redis.hset('media:blacklist', `${format}:${cid}`, reason).then(() => that.models.Song.findOrCreate({ where: { - format: format, - cid: cid + format, + cid }, defaults: { - format: format, - cid: cid, + format, + cid, idBanned: true, ban_reason: (reason === 1) ? null : reason } - }); - }).spread(function (track) { - return track.updateAttributes({ + })).spread(track => track.updateAttributes({ is_banned: true, ban_reason: (reason === 1) ? null : reason - }); - }).then(resolve).catch(reject); - }); - }, - remove: function (format, cid) { - return new Promise(function (resolve, reject) { - models.Song.find({where: {format: format, cid: cid}}).then(function (song) { - if (song !== null && song !== undefined) { - return song.update({ban_reason: null, is_banned: false}) - } else reject('not_found'); - }).then(function () { - //noinspection JSUnresolvedFunction - return redis.hdel('media:blacklist', format + ':' + cid); - }).then(resolve).catch(reject); - }); - } + })).then(resolve).catch(reject); + }); + }, + remove: function (format, cid) { + return new Promise((resolve, reject) => { + that.models.Song.find({where: {format, cid}}).then(song => { + if (song !== null && song !== undefined) { + return song.update({ban_reason: null, is_banned: false}) + } else reject('not_found'); + }).then(() => //noinspection JSUnresolvedFunction + redis.hdel('media:blacklist', `${format}:${cid}`)).then(resolve).catch(reject); + }); + } + }; + + this.sequelize.validate().then(() => { + story.debug('Database-Connection active.'); + return that.sequelize.sync(); + }).then(() => //noinspection JSUnresolvedFunction + redis.del('media:blacklist').then(() => //noinspection JSUnresolvedFunction + that.models.Song.findAll({where: {is_banned: true}})).then(songs => Promise.all(songs.map(song => //noinspection JSUnresolvedFunction + redis.hset( + 'media:blacklist', + `${song.format}:${song.cid}`, + (song.ban_reason !== undefined && song.ban_reason !== null) ? song.ban_reason : 1 + )))).then(songs => { + story.info(`Loaded blacklist with ${songs.length} entries.`); + //noinspection JSUnresolvedFunction + return that.models.Channel.findAll({where: {is_banned: true}}); + }).then(channels => Promise.all(channels.map(channel => { + //noinspection JSUnresolvedFunction + redis.hset('media:channelblacklist', channel.cid, (channel.reason !== null ? channel.reason : 1)); + }))).then(()=> { + that.ready = true; + that.emitter.emit('ready'); + }).catch(err => { + story.error('Failed to load blacklist: ', {attach: err}); + })).catch(err => { + story.error('Could not connect to database', {attach: err}); + process.exit(1); + }); } -}; \ No newline at end of file +} + +module.exports = new Database(); \ No newline at end of file diff --git a/lib/eventhandlers/advance.js b/lib/eventhandlers/advance.js index 1d001bf..3e92cb2 100644 --- a/lib/eventhandlers/advance.js +++ b/lib/eventhandlers/advance.js @@ -25,34 +25,29 @@ module.exports = { now = utils.clone(now); prev = utils.clone(prev); if (booth.dj !== undefined) { - Promise.all(songfilters.map(function (e) { - return e(booth, now); - })).catch(function (error) { - story.debug('SongFilters', '', {attach: error}); + Promise.all(songfilters.map(e => e(booth, now))).catch(error => { if (plugged.getMedia().id === now.media.id) { plugged.sendChat(error.preskip); if (error.do_lockskip) { //noinspection JSUnresolvedFunction - plugged.setCyclePromise(true).then(function () { - //noinspection JSUnresolvedFunction - return plugged.skipDJPromise(booth.dj); - }).then(function () { + plugged.setCyclePromise(true).then(() => //noinspection JSUnresolvedFunction + plugged.skipDJPromise(booth.dj)).then(() => { if (config.lockskip.move_pos !== undefined) plugged.moveDJ(booth.dj, config.lockskip.move_pos); return Promise.resolve(); - }).then(function () { + }).then(() => { if (booth.shouldCycle !== plugged.doesWaitlistCycle()) { //noinspection JSUnresolvedFunction return plugged.setCyclePromise(booth.shouldCycle); } else Promise.resolve(); - }).then(function () { + }).then(() => { plugged.sendChat(error.afterskip); if (error.blacklist) db.blacklist.add(now.media.format, now.media.cid, error.bl_reason || undefined); - }).catch(function (err) { + }).catch(err => { story.error('Error while lockskipping.', {attach: err}); }); } else { plugged.skipDJ(booth.dj); - setTimeout(function () { + setTimeout(() => { plugged.sendChat(error.afterskip); if (error.blacklist) db.blacklist.add(now.media.format, now.media.cid, error.bl_reason || undefined); }, 4 * 1000); @@ -69,7 +64,7 @@ module.exports = { plug_id: now.media.id, cid: now.media.cid } - }).spread(function (song) { + }).spread(song => { song.updateAttributes({ image: now.media.image, title: now.media.title, @@ -82,7 +77,7 @@ module.exports = { } if (song.tskip !== null && song.tskip !== undefined && !config.state.eventmode) { plugged.sendChat(utils.replace(langfile.tskip.default, {time: song.tskip}), song.tskip * 1000); - setTimeout(function () { + setTimeout(() => { if (plugged.getMedia().id === now.media.id) { plugged.sendChat(langfile.tskip.skip, 60 * 1000); plugged.skipDJ(booth.dj); @@ -90,12 +85,12 @@ module.exports = { }, song.tskip * 1000); } }); - story.info('advance', utils.userLogString(plugged.getUserByID(booth.dj)) + ': ' + utils.mediatitlelog(now.media)); + story.info('advance', `${utils.userLogString(plugged.getUserByID(booth.dj))}: ${utils.mediatitlelog(now.media)}`); } else story.info('advance', 'Nobody is playing!'); clearTimeout(timeouts.stuck); clearTimeout(timeouts.tskip); if (booth.dj !== undefined) { - timeouts.stuck = setTimeout(function () { + timeouts.stuck = setTimeout(() => { if (plugged.getMedia().id === now.media.id) { plugged.sendChat(langfile.skip.stuck.default, 30); plugged.skipDJ(booth.dj, now.historyID); @@ -103,47 +98,41 @@ module.exports = { }, (now.media.duration + 5) * 1000); } if (prev.dj !== undefined) { - redis.set('media:history:' + prev.media.format + ':' + prev.media.cid, 1).then(function () { + redis.set(`media:history:${prev.media.format}:${prev.media.cid}`, 1).then(() => { //noinspection JSUnresolvedFunction - redis.expire('media:history:' + prev.media.format + ':' + prev.media.cid, config.history.time * 60); + redis.expire(`media:history:${prev.media.format}:${prev.media.cid}`, config.history.time * 60); }); - db.sequelize.transaction(function (t) { - return db.models.Play.create({ - time: new Date, - woots: prev.score.positive, - mehs: prev.score.negative, - grabs: prev.score.grabs - }, {transaction: t}).then(function (play) { - //noinspection JSUnresolvedFunction - return play.setSong(prev.media.id, {transaction: t}).then(function () { - //noinspection JSUnresolvedFunction - return play.setUser(prev.dj.id, {transaction: t}); - }); - }); - }).catch(function () { - story.debug('SQL','Transaction errored while creating play. You skipped to fast...'); + db.sequelize.transaction(t => db.models.Play.create({ + time: new Date, + woots: prev.score.positive, + mehs: prev.score.negative, + grabs: prev.score.grabs + }, {transaction: t}).then(play => //noinspection JSUnresolvedFunction + play.setSong(prev.media.id, {transaction: t}).then(() => //noinspection JSUnresolvedFunction + play.setUser(prev.dj.id, {transaction: t})))).catch(() => { + story.debug('SQL','Transaction errored while creating play. You skipped too fast...'); }); - story.info('score', utils.mediatitlelog(prev.media) + ' woots: ' + prev.score.positive + ' | grabs: ' + prev.score.grabs + ' | mehs: ' + prev.score.negative); + story.info('score', `${utils.mediatitlelog(prev.media)} woots: ${prev.score.positive} | grabs: ${prev.score.grabs} | mehs: ${prev.score.negative}`); } //noinspection JSUnresolvedFunction redis.del('meta:data:rdjskip:votes'); websocketUpdate({ - m: function () { + m: (() => { if (now.media.id !== -1) { return { - cid: now.media.format + ':' + now.media.cid, + cid: `${now.media.format}:${now.media.cid}`, t: now.media.title, a: now.media.author }; } else return null; - }(), - dj: function () { + })(), + dj: (() => { if (booth.dj !== -1 && booth.dj !== undefined) { var u = plugged.getUserByID(booth.dj); return {id: u.id, n: u.username}; } else return null; - }() + })() }); } }; \ No newline at end of file diff --git a/lib/eventhandlers/chat.js b/lib/eventhandlers/chat.js index 6502053..ef05c7b 100644 --- a/lib/eventhandlers/chat.js +++ b/lib/eventhandlers/chat.js @@ -23,23 +23,23 @@ module.exports = { if (data.id !== plugged.getSelf().id) { if (config.state.lockdown) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (perm < 1) plugged.removeChatMessage(data.cid); else handleAsCommand(); }); } else { //noinspection JSUnresolvedFunction - redis.exists('user:mute:' + data.id).then(function (exm) { + redis.exists(`user:mute:${data.id}`).then(exm => { if (exm === 1) { plugged.removeChatMessage(data.cid); //noinspection JSUnresolvedFunction if (!S(data.message).startsWith(config.options.command_prefix)) { //noinspection JSUnresolvedFunction - redis.incr('user:mute:' + data.id + ':violation').then(function () { - redis.get('user:mute:' + data.id + ':violation').then(function (val) { + redis.incr(`user:mute:${data.id}:violation`).then(() => { + redis.get(`user:mute:${data.id}:violation`).then(val => { if (parseInt(val, 10) > config.chatfilter.spam.mute_violation) { - plugged.muteUser(data.id, plugged.MUTEDURATION.LONG, plugged.BANREASON.SPAMMING, function (err) { + plugged.muteUser(data.id, plugged.MUTEDURATION.LONG, plugged.BANREASON.SPAMMING, err => { if (!err)plugged.sendChat(utils.replace(langfile.chatfilter.spam.hard_mute, {username: data.username}), 60); }); } @@ -48,26 +48,24 @@ module.exports = { } } else if (config.chatfilter.enabled) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (role) { + redis.hget('user:roles', data.id).then(role => { role = parseInt(role); if (role < config.chatfilter.ignorerole) { - return Promise.all(chatfilter.filters.map(function (e) { - return e(data); - })); + return Promise.all(chatfilter.filters.map(e => e(data))); } else return Promise.resolve(); - }).then(function () { + }).then(() => { handleAsCommand(); - }).catch(function (filter) { + }).catch(filter => { story.debug('Chatfilters', '', {attach: filter}); plugged.deleteMessage(data.cid); if (filter.points > 0) { //noinspection JSUnresolvedFunction - redis.hincrby('spam:user:spampoints', data.id, filter.points).then(function (points) { + redis.hincrby('spam:user:spampoints', data.id, filter.points).then(points => { if (points > config.chatfilter.spam.points) { - redis.set('user:mute:' + data.id, 1).then(function () { - redis.set('user:mute:' + data.id + ':violation', 0); + redis.set(`user:mute:${data.id}`, 1).then(() => { + redis.set(`user:mute:${data.id}:violation`, 0); //noinspection JSUnresolvedFunction - redis.expire('user:mute:' + data.id, config.chatfilter.spam.mute_duration); + redis.expire(`user:mute:${data.id}`, config.chatfilter.spam.mute_duration); }); plugged.sendChat(utils.replace(chatfilter.resolveMsg(filter.type).mute, {username: data.username})); } else plugged.sendChat(utils.replace(chatfilter.resolveMsg(filter.type).warn, {username: data.username})); @@ -86,7 +84,7 @@ module.exports = { }, {where: {id: data.id}}); } } - story.info('chat', data.username + '[' + data.id + ']: ' + data.message); + story.info('chat', `${data.username}[${data.id}]: ${data.message}`); webSockUpdate({m: data.message, u: {id: data.id, n: plugged.getUserByID(data.id).username}, cid: data.cid}); function handleAsCommand() { @@ -96,7 +94,7 @@ module.exports = { var split = S(data.message).chompLeft(config.options.command_prefix).s.split(' '); if (commands[split[0].toLowerCase()] !== undefined) { commands[split[0].toLowerCase()].handler(data); - story.info('command', utils.userLogString(data.username, data.id) + ': ' + split[0] + ' [' + data.message + ']'); + story.info('command', `${utils.userLogString(data.username, data.id)}: ${split[0]} [${data.message}]`); } } else { //noinspection JSUnresolvedFunction @@ -105,7 +103,7 @@ module.exports = { var splt = S(data.message).chompLeft(config.customcommands.trigger).s.split(' '); if (customcommands[splt[0].toLowerCase()] !== undefined) { customcommands[splt[0].toLowerCase()].handler(data); - story.info('customcommand', utils.userLogString(data.username, data.id) + ': ' + splt[0] + ' [' + data.message + ']'); + story.info('customcommand', `${utils.userLogString(data.username, data.id)}: ${splt[0]} [${data.message}]`); } sendToCleverbot(); } @@ -115,7 +113,7 @@ module.exports = { function sendToCleverbot() { //noinspection JSUnresolvedFunction - if (config.cleverbot.enabled && S(data.message).contains('@' + plugged.getSelf().username)) { + if (config.cleverbot.enabled && S(data.message).contains(`@${plugged.getSelf().username}`)) { cleverbot(data); } } diff --git a/lib/eventhandlers/chat_command.js b/lib/eventhandlers/chat_command.js index 24cf35a..e4b9807 100644 --- a/lib/eventhandlers/chat_command.js +++ b/lib/eventhandlers/chat_command.js @@ -17,27 +17,27 @@ module.exports = { if (data.id !== plugged.getSelf().id) { if (config.state.lockdown) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (perm < 2) plugged.removeChatMessage(data.cid); }); } else if (config.options.disable_emote) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (perm) { + redis.hget('user:roles', data.id).then(perm => { perm = parseInt(perm, 10); if (perm < 1) { plugged.deleteMessage(data.cid); } }); } else { - redis.exists('user:mute:' + data.id).then(function (exm) { + redis.exists(`user:mute:${data.id}`).then(exm => { if (exm === 1) { plugged.removeChatMessage(data.cid); //noinspection JSUnresolvedFunction if (!S(data.message).startsWith(config.options.command_prefix)) { //noinspection JSUnresolvedFunction - redis.incr('user:mute:' + data.id + ':violation').then(function () { - redis.get('user:mute:' + data.id + ':violation').then(function (val) { + redis.incr(`user:mute:${data.id}:violation`).then(() => { + redis.get(`user:mute:${data.id}:violation`).then(val => { if (parseInt(val, 10) > config.chatfilter.spam.mute_violation) { plugged.sendChat(utils.replace(langfile.chatfilter.spam.hard_mute, {username: data.username}), 60); plugged.muteUser(data.id, plugged.MUTEDURATION.LONG, plugged.BANREASON.SPAMMING); @@ -48,26 +48,24 @@ module.exports = { } else if (config.chatfilter.enabled) { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (role) { + redis.hget('user:roles', data.id).then(role => { role = parseInt(role); if (role < config.chatfilter.ignorerole) { - return Promise.all(chatfilter.filters.map(function (e) { - return e(data); - })); + return Promise.all(chatfilter.filters.map(e => e(data))); } else return Promise.resolve(); - }).then(function () { + }).then(() => { - }).catch(function (filter) { + }).catch(filter => { story.debug('Chatfilters', '', {attach: filter}); plugged.deleteMessage(data.cid); if (filter.points > 0) { //noinspection JSUnresolvedFunction - redis.hincrby('spam:user:spampoints', data.id, filter.points).then(function (points) { + redis.hincrby('spam:user:spampoints', data.id, filter.points).then(points => { if (points > config.chatfilter.spam.points) { - redis.set('user:mute:' + data.id, 1).then(function () { - redis.set('user:mute:' + data.id + ':violation', 0); + redis.set(`user:mute:${data.id}`, 1).then(() => { + redis.set(`user:mute:${data.id}:violation`, 0); //noinspection JSUnresolvedFunction - redis.expire('user:mute:' + data.id, config.chatfilter.spam.mute_duration); + redis.expire(`user:mute:${data.id}`, config.chatfilter.spam.mute_duration); }); plugged.sendChat(utils.replace(chatfilter.resolveMsg(filter.type).mute, {username: data.username})); } else plugged.sendChat(utils.replace(chatfilter.resolveMsg(filter.type).warn, {username: data.username})); @@ -86,7 +84,7 @@ module.exports = { }, {where: {id: data.id}}); } } - story.info('chat', data.username + '[' + data.id + ']: ' + data.message); + story.info('chat', `${data.username}[${data.id}]: ${data.message}`); webSockUpdate({m: data.message, u: {id: data.id, n: plugged.getUserByID(data.id).username}, cid: data.cid}); } }; \ No newline at end of file diff --git a/lib/eventhandlers/conn_warning.js b/lib/eventhandlers/conn_warning.js index ca2978c..d72cdd2 100644 --- a/lib/eventhandlers/conn_warning.js +++ b/lib/eventhandlers/conn_warning.js @@ -5,6 +5,6 @@ var plugged = require('../client'); module.exports = { event: plugged.CONN_WARNING, handler: function (c) { - story.warn('Connection', 'Connection is about to drop. Count: ' + c); + story.warn('Connection', `Connection is about to drop. Count: ${c}`); } }; \ No newline at end of file diff --git a/lib/eventhandlers/joined_room.js b/lib/eventhandlers/joined_room.js index ef2a9d5..68919d3 100644 --- a/lib/eventhandlers/joined_room.js +++ b/lib/eventhandlers/joined_room.js @@ -9,16 +9,16 @@ var langfile = require('../../langfile'); module.exports = { event: plugged.JOINED_ROOM, handler: function () { - story.info('Joined room ' + config.options.room); + story.info(`Joined room ${config.options.room}`); //noinspection JSUnresolvedFunction - redis.hget('meta:options', 'isRestart').then(function (is) { + redis.hget('meta:options', 'isRestart').then(is => { if (is !== null && is === '1') { plugged.sendChat(langfile.restart.back_up, 45); //noinspection JSUnresolvedFunction redis.hdel('meta:options', 'isRestart'); } }); - plugged.getUsers().forEach(function (user) { + plugged.getUsers().forEach(user => { db.models.User.findOrCreate({ where: {id: user.id}, defaults: { @@ -28,7 +28,7 @@ module.exports = { avatar_id: user.avatarID, badge: user.badge } - }).spread(function (usr) { + }).spread(usr => { //noinspection JSUnresolvedFunction redis.hset('user:roles', user.id, usr.s_role); if (!usr.super_user && user.role !== usr.s_role) { @@ -43,7 +43,7 @@ module.exports = { }); }); - db.models.User.find({where: {id: plugged.getSelf().id}}).then(function (usr) { + db.models.User.find({where: {id: plugged.getSelf().id}}).then(usr => { if (usr !== null && usr !== undefined) { if (usr.s_role > 0) { //noinspection JSUnresolvedFunction redis.hset('user:roles', plugged.getSelf().id, usr.s_role); diff --git a/lib/eventhandlers/login_success.js b/lib/eventhandlers/login_success.js index 086fc27..8af761a 100644 --- a/lib/eventhandlers/login_success.js +++ b/lib/eventhandlers/login_success.js @@ -10,11 +10,10 @@ module.exports = { event: plugged.LOGIN_SUCCESS, handler: function () { plugged.cacheChat(true); - plugged.connect(config.options.room); - plugged.getAuthToken(function (err, token) { + plugged.getAuthToken((err, token) => { if (!err) { - redis.set('meta:auth:save:jar', JSON.stringify(plugged.getJar())).then(function () { - redis.set('meta:auth:save:token', token).then(function () { + redis.set('meta:auth:save:jar', JSON.stringify(plugged.getJar())).then(() => { + redis.set('meta:auth:save:token', token).then(() => { //noinspection JSUnresolvedFunction redis.expire('meta:auth:save:token', 604800); }); @@ -23,26 +22,9 @@ module.exports = { }); } }); - //noinspection JSUnresolvedFunction - redis.del('media:blacklist').then(function () { - //noinspection JSUnresolvedFunction - return db.models.Song.findAll({where: {is_banned: true}}); - }).then(function (songs) { - return Promise.all(songs.map(function (song) { - //noinspection JSUnresolvedFunction - return redis.hset('media:blacklist', song.format + ':' + song.cid, ((song.ban_reason !== undefined && song.ban_reason !== null) ? song.ban_reason : 1)); - })); - }).then(function (songs) { - story.info('Loaded blacklist with ' + songs.length + ' entries.'); - //noinspection JSUnresolvedFunction - return db.models.Channel.findAll({where: {is_banned: true}}); - }).then(function (channels) { - return Promise.all(channels.map(function (channel) { - //noinspection JSUnresolvedFunction - redis.hset('media:channelblacklist', channel.cid, (channel.reason !== null ? channel.reason : 1)); - })); - }).catch(function (err) { - story.error('Failed to load blacklist: ', {attach: err}); + if (db.ready) plugged.connect(config.options.room); + else db.emitter.on('ready', ()=> { + plugged.connect(config.options.room) }); story.info('Successfully authed to plug.dj'); diff --git a/lib/eventhandlers/mod_add_dj.js b/lib/eventhandlers/mod_add_dj.js index 47c9472..3fe6835 100644 --- a/lib/eventhandlers/mod_add_dj.js +++ b/lib/eventhandlers/mod_add_dj.js @@ -8,7 +8,7 @@ module.exports = { event: plugged.MOD_ADD_DJ, handler: function (data) { if (data.mi !== plugged.getSelf.id) { - story.info('add', utils.userLogString(data.m, data.mi) + ' added ' + utils.userLogString(data.username, data.id)); + story.info('add', `${utils.userLogString(data.m, data.mi)} added ${utils.userLogString(data.username, data.id)}`); } } }; \ No newline at end of file diff --git a/lib/eventhandlers/mod_ban.js b/lib/eventhandlers/mod_ban.js index e9996e3..10474c2 100644 --- a/lib/eventhandlers/mod_ban.js +++ b/lib/eventhandlers/mod_ban.js @@ -11,7 +11,7 @@ module.exports = { event: plugged.MOD_BAN, handler: function (data) { if (data.moderatorID !== plugged.getSelf().id) { - redis.get('user:role:save:' + data.moderatorID).then(function (perm) { + redis.get(`user:role:save:${data.moderatorID}`).then(perm => { perm = parseInt(perm, 10); if (perm < 2 && data.duration === plugged.BANDURATION.PERMA) { plugged.sendChat(utils.replace(langfile.ban.no_staff_ban, {username: data.moderator}), 60); @@ -20,7 +20,7 @@ module.exports = { plugged.removeStaff(data.moderatorID); } else { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (plvl) { + redis.hget('user:roles', data.id).then(plvl => { plvl = parseInt(plvl, 10); if (plvl > 1) { plugged.sendChat(utils.replace(langfile.ban.staff_ban, {username: data.moderator}), 60); @@ -30,14 +30,14 @@ module.exports = { }); } }); - story.info('ban', utils.userLogString(data.moderator, data.moderatorID) + ': ' + data.username + ' --> ' + data.duration); + story.info('ban', `${utils.userLogString(data.moderator, data.moderatorID)}: ${data.username} --> ${data.duration}`); //noinspection JSUnresolvedVariable wsBan({ m: {id: moderatorID, n: data.moderator}, - u: function () { + u: (() => { var u = plugged.getUserByName(data.username, true); return (u !== undefined ? {id: u.id, n: u.username} : {n: username}); - }(), + })(), d: data.duration }); } diff --git a/lib/eventhandlers/mod_skip.js b/lib/eventhandlers/mod_skip.js index 3cd0103..b66d47d 100644 --- a/lib/eventhandlers/mod_skip.js +++ b/lib/eventhandlers/mod_skip.js @@ -11,13 +11,10 @@ module.exports = { event: plugged.MOD_SKIP, handler: function (data) { if (data.moderatorID !== plugged.getSelf().id) { - redis.set('meta:state:skipable', 1).then(function () { - //noinspection JSUnresolvedFunction - redis.expire('meta:state:skipable', 2); - }); + redis.set('meta:state:skipable', 1, 'EX', 2); story.info('skip', utils.userLogString(data.moderator, data.moderatorID)); //noinspection JSUnresolvedVariable - redis.get('user:role:save:' + data.mi).then(function (perm) { + redis.get(`user:role:save:${data.mi}`).then(perm => { perm = parseInt(perm, 10); if (perm < 2) { plugged.sendChat(utils.replace(langfile.skip.no_mod_skip, {username: data.moderator})); diff --git a/lib/eventhandlers/mod_staff.js b/lib/eventhandlers/mod_staff.js index 792b3b0..5913652 100644 --- a/lib/eventhandlers/mod_staff.js +++ b/lib/eventhandlers/mod_staff.js @@ -11,14 +11,14 @@ module.exports = { handler: function (data) { data = data[0]; if (data.moderatorID !== plugged.getSelf().id) { - redis.get('user:role:save:' + data.moderatorID).then(function (perm) { + redis.hget('user:roles' , data.moderatorID).then(perm => { perm = parseInt(perm, 10); if (perm > 2) { - redis.set('user:role:save:' + data.id, data.role); + redis.hset('user:roles', data.id, data.role); db.models.User.update({s_role: data.role}, {where: {id: data.id}}); } else { //noinspection JSUnresolvedFunction - redis.hget('user:roles', data.id).then(function (permlvl) { + redis.hget('user:roles', data.id).then(permlvl => { permlvl = parseInt(permlvl, 10); var role = utils.role(permlvl); if (role === plugged.USERROLE.NONE) plugged.removeStaff(data.id); @@ -27,7 +27,7 @@ module.exports = { }); } }); - story.info('promote', utils.userLogString(data.moderator, data.moderatorID) + ': ' + utils.userLogString(data.username, data.id) + ' --> ' + utils.rolename(data.role)); + story.info('promote', `${utils.userLogString(data.moderator, data.moderatorID)}: ${utils.userLogString(data.username, data.id)} --> ${utils.rolename(data.role)}`); } } }; \ No newline at end of file diff --git a/lib/eventhandlers/user_join.js b/lib/eventhandlers/user_join.js index b5f908a..0517f21 100644 --- a/lib/eventhandlers/user_join.js +++ b/lib/eventhandlers/user_join.js @@ -18,102 +18,98 @@ module.exports = { var greetStr = '&{welcome} &{dcmoveback}'; var greet = false; var sendit = false; - var moveAction = function () { + var moveAction = () => { }; - redis.set('user:afk:' + user.id, 1).then(function () { + redis.set(`user:afk:${user.id}`, 1).then(() => { //noinspection JSUnresolvedFunction - redis.expire('user:afk:' + user.id, config.afk.time); + redis.expire(`user:afk:${user.id}`, config.afk.time); }); - Promise.resolve().then(function () { + Promise.resolve().then(() => { if (config.dcmoveback.enabled && config.dcmoveback.auto && !config.state.eventmode) { - return redis.get('user:disconnect:' + user.id).then(function (pos) { + return redis.get(`user:disconnect:${user.id}`).then(pos => { if (pos !== null) { pos = parseInt(pos); if (pos !== -1 && pos > utils.wlPosition(user)) { if ((plugged.getWaitlist() === undefined || plugged.getWaitlist().length < 50)) { - moveAction = function () { + moveAction = () => { if (utils.wlPosition(user) === -1) plugged.addToWaitlist(user.id); plugged.moveDJ(user.id, pos); //noinspection JSUnresolvedFunction - redis.del('user:disconnect:' + user.id); + redis.del(`user:disconnect:${user.id}`); }; greetStr = utils.replace(greetStr, {dcmoveback: utils.replace(langfile.dcmoveback.move, {pos: (pos + 1).toString()})}); sendit = true; return Promise.resolve(); } else { - return addqueue.add(user.id, pos).then(function () { + return addqueue.add(user.id, pos).then(() => { greetStr = utils.replace(greetStr, {dcmoveback: utils.replace(langfile.dcmoveback.addqueue, {pos: (pos + 1).toString()})}); sendit = true; //noinspection JSUnresolvedFunction - return redis.del('user:disconnect:' + user.id); + return redis.del(`user:disconnect:${user.id}`); }); } } else { greetStr = utils.replace(greetStr, {dcmoveback: ''}).trim(); //noinspection JSUnresolvedFunction - return redis.del('user:disconnect:' + user.id); + return redis.del(`user:disconnect:${user.id}`); } } else { greetStr = utils.replace(greetStr, {dcmoveback: ''}).trim(); //noinspection JSUnresolvedFunction - return redis.del('user:disconnect:' + user.id); + return redis.del(`user:disconnect:${user.id}`); } }); } else { greetStr = utils.replace(greetStr, {dcmoveback: ''}).trim(); return Promise.resolve(); } - }).then(function () { - return db.models.User.find({where: {id: user.id}}).then(function (usr) { - if (usr !== null && usr !== undefined) { - if (usr.s_role > 0) { //noinspection JSUnresolvedFunction - redis.hset('user:roles', user.id, usr.s_role); - } - if (!usr.super_user && user.role !== usr.s_role) { - if (usr.s_role > 0) plugged.addStaff(user.id, usr.s_role); - else plugged.removeStaff(user.id); - } - if (config.options.welcome.old) { - greet = true; - greetStr = utils.replace(greetStr, {welcome: utils.replace(langfile.welcome.old, {username: user.username})}); - sendit = true; - } else { - greetStr = utils.replace(greetStr, {welcome: ''}).trim(); - } - return usr.updateAttributes({status: true, slug: user.slug, username: user.username}); + }).then(() => db.models.User.find({where: {id: user.id}}).then(usr => { + if (usr !== null && usr !== undefined) { + if (usr.s_role > 0) { //noinspection JSUnresolvedFunction + redis.hset('user:roles', user.id, usr.s_role); + } + if (!usr.super_user && user.role !== usr.s_role) { + if (usr.s_role > 0) plugged.addStaff(user.id, usr.s_role); + else plugged.removeStaff(user.id); + } + if (config.options.welcome.old) { + greet = true; + greetStr = utils.replace(greetStr, {welcome: utils.replace(langfile.welcome.old, {username: user.username})}); + sendit = true; } else { - if (config.options.welcome.old) { - greet = true; - greetStr = utils.replace(greetStr, {welcome: utils.replace(langfile.welcome.new, {username: user.username})}); - sendit = true; - } else { - greetStr = utils.replace(greetStr, {welcome: ''}).trim(); - } - return db.models.User.create({ - id: user.id, - username: user.username, - slug: user.slug, - role: user.role, - global_role: user.gRole, - badge: user.badge, - language: user.language, - avatar_id: user.avatarID, - blurb: user.blurb - }); + greetStr = utils.replace(greetStr, {welcome: ''}).trim(); } - }); - }).then(function () { - Promise.all(userfilters.map(function (f) { - return f(user); - })).then(function () { - setTimeout(function () { + return usr.updateAttributes({status: true, slug: user.slug, username: user.username}); + } else { + if (config.options.welcome.old) { + greet = true; + greetStr = utils.replace(greetStr, {welcome: utils.replace(langfile.welcome.new, {username: user.username})}); + sendit = true; + } else { + greetStr = utils.replace(greetStr, {welcome: ''}).trim(); + } + return db.models.User.create({ + id: user.id, + username: user.username, + slug: user.slug, + role: user.role, + global_role: user.gRole, + badge: user.badge, + language: user.language, + avatar_id: user.avatarID, + blurb: user.blurb + }); + } + })).then(() => { + Promise.all(userfilters.map(f => f(user))).then(() => { + setTimeout(() => { if(sendit){ plugged.sendChat((greet ? '' : '@' + user.username + ' ') + greetStr.trim()); } moveAction(); }, 4 * 1000); - }).catch(function (filter) { + }).catch(filter => { }); }); diff --git a/lib/eventhandlers/user_leave.js b/lib/eventhandlers/user_leave.js index 41825d7..2a6d07c 100644 --- a/lib/eventhandlers/user_leave.js +++ b/lib/eventhandlers/user_leave.js @@ -14,17 +14,13 @@ module.exports = { handler: function (user) { if (user !== null && user !== undefined) { //noinspection JSUnresolvedFunction - redis.hget('user:waitlist:lastposition', user.id).then(function (pos) { + redis.hget('user:waitlist:lastposition', user.id).then(pos => { pos = parseInt(pos); if (pos !== -1) { - return redis.set('user:disconnect:' + user.id, pos).then(function () { - //noinspection JSUnresolvedFunction - return redis.expire('user:disconnect:' + user.id, config.dcmoveback.timeout); - }); + return redis.set(`user:disconnect:${user.id}`, pos).then(() => //noinspection JSUnresolvedFunction + redis.expire(`user:disconnect:${user.id}`, config.dcmoveback.timeout)); } else return Promise.resolve(); - }).then(function () { - return db.models.User.update({status: false}, {where: {id: user.id}}); - }); + }).then(() => db.models.User.update({status: false}, {where: {id: user.id}})); story.info('leave', utils.userLogString(user)); wsUpdate({id: user.id, n: user.username}); } diff --git a/lib/eventhandlers/userupdate.js b/lib/eventhandlers/userupdate.js index e86eba3..33b0d50 100644 --- a/lib/eventhandlers/userupdate.js +++ b/lib/eventhandlers/userupdate.js @@ -12,11 +12,9 @@ module.exports = { else if (data.username !== undefined) { var user = plugged.getUserByID(data.id); user.username = data.username; - Promise.all(userfilters.map(function (e) { - return e(user); - })).then(function () { + Promise.all(userfilters.map(e => e(user))).then(() => { if (userfilters.timeouts[data.id] !== undefined)clearTimeout(userfilters.timeouts[data.id]); - }).catch(function (filter) { + }).catch(filter => { plugged.sendChat(filter.chat); if (userfilters.timeouts[data.id] === undefined) filter.action(); }); diff --git a/lib/eventhandlers/vote.js b/lib/eventhandlers/vote.js index 00d3ff8..d2b1772 100644 --- a/lib/eventhandlers/vote.js +++ b/lib/eventhandlers/vote.js @@ -8,11 +8,11 @@ module.exports = { event: plugged.VOTE, handler: function (vote) { var score = {woots: 0, mehs: 0, userCount: plugged.getUsers().length}; - plugged.getVotes(false).forEach(function (vote) { + plugged.getVotes(false).forEach(vote => { if (vote.direction === 1) score.woots = score.woots + 1; else if (vote.direction === -1) score.mehs = score.mehs - 1; }); - if (function () { + if ((() => { switch (typeof config.voteskip.condition) { default: return false; @@ -29,10 +29,10 @@ module.exports = { else return false; break; } - }() && config.voteskip.enabled && !config.state.eventmode) { + })() && config.voteskip.enabled && !config.state.eventmode) { plugged.sendChat(langfile.skip.vote.skip); plugged.skipDJ(plugged.getCurrentDJ().id); - setTimeout(function () { + setTimeout(() => { plugged.sendChat(utils.replace(langfile.skip.vote.default, { username: plugged.getCurrentDJ(), song: utils.mediatitle(plugged.getMedia()) diff --git a/lib/eventhandlers/waitlist_update.js b/lib/eventhandlers/waitlist_update.js index bfed232..1714b4c 100644 --- a/lib/eventhandlers/waitlist_update.js +++ b/lib/eventhandlers/waitlist_update.js @@ -15,28 +15,23 @@ module.exports = { //todo examine who was removed //oldWaitlist = utils.clone(oldWaitlist); newWaitlist = utils.clone(newWaitlist); - setTimeout(function () { - Promise.all(plugged.getUsers().map(function (user) { - //noinspection JSUnresolvedFunction - return redis.hset('user:waitlist:lastposition', user.id, utils.wlPosition(user, newWaitlist)); - })).then(function () { - return Promise.all(newWaitlist.map(function (id) { - return redis.exists('user:waitlist:ban:' + id).then(function (ex) { - if (ex === 1) { - plugged.sendChat(utils.replace(langfile.wlban.remove, {username: plugged.getUserByID(id).username})); - plugged.removeDJ(id); - story.info('waitlist', utils.userLogString(plugged.getUserByID(id)) + ' joined the waitlist but is banned from the waitlist.'); - //noinspection JSUnresolvedFunction - return redis.hdel('user:waitlist:lastposition', id); - } else return Promise.resolve(); - }); - })); - }).then(function () { + setTimeout(() => { + Promise.all(plugged.getUsers().map(user => //noinspection JSUnresolvedFunction + redis.hset('user:waitlist:lastposition', user.id, utils.wlPosition(user, newWaitlist)))).then(() => Promise.all(newWaitlist.map(id => redis.exists(`user:waitlist:ban:${id}`).then(ex => { + if (ex === 1) { + plugged.sendChat(utils.replace(langfile.wlban.remove, {username: plugged.getUserByID(id).username})); + plugged.removeDJ(id); + story.info('waitlist', `${utils.userLogString(plugged.getUserByID(id))} joined the waitlist but is banned from the waitlist.`); + //noinspection JSUnresolvedFunction + return redis.hdel('user:waitlist:lastposition', id); + } else return Promise.resolve(); + })))).then(() => { addQueue.wlUpdate(plugged.getWaitlist()); }); }, 1000); - wsUpdate(newWaitlist.map(function (id) { - return {id: id, n: plugged.getUserByID(id).username} - })); + wsUpdate(newWaitlist.map(id => ({ + id, + n: plugged.getUserByID(id).username + }))); } }; \ No newline at end of file diff --git a/lib/load_config.js b/lib/load_config.js index e844a8b..54b1ee5 100644 --- a/lib/load_config.js +++ b/lib/load_config.js @@ -25,189 +25,187 @@ if (conf.apiKeys.youtube === '' || conf.apiKeys.soundcloud === '') { } else { module.exports = conf; - var redis = new require('ioredis')(conf.redis); + var redis = new require('./db/redis_db'); var loaded = 0; //noinspection JSUnresolvedFunction Promise.all([ - redis.hexists('meta:config', 'state:eventmode').then(function (ex) { + redis.hexists('meta:config', 'state:eventmode').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'state:eventmode').then(function (val) { + redis.hget('meta:config', 'state:eventmode').then(val => { conf.state.eventmode = val === '1'; load('eventmode', conf.state.eventmode); }); } else load('eventmode', 'not stored') }), - redis.hexists('meta:config', 'voteskip:enabled').then(function (ex) { + redis.hexists('meta:config', 'voteskip:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'voteskip:enabled').then(function (val) { + redis.hget('meta:config', 'voteskip:enabled').then(val => { conf.voteskip.enabled = val === '1'; load('voteskip', conf.voteskip.enabled) }); } else load('voteskip', 'not stored') }), - redis.hexists('meta:config', 'timeguard:enabled').then(function (ex) { + redis.hexists('meta:config', 'timeguard:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'timeguard:enabled').then(function (val) { + redis.hget('meta:config', 'timeguard:enabled').then(val => { conf.timeguard.enabled = val === '1'; load('timeguard', conf.timeguard.enabled); }); } else load('timeguard', 'not stored'); }), - redis.hexists('meta:config', 'history:skipenabled').then(function (ex) { + redis.hexists('meta:config', 'history:skipenabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'history:skipenabled').then(function (val) { + redis.hget('meta:config', 'history:skipenabled').then(val => { conf.history.skipenabled = val === '1'; load('historyskip', conf.history.skipenabled); }); } else load('historyskip', 'not stored'); }), - redis.hexists('meta:config', 'cleverbot:enabled').then(function (ex) { + redis.hexists('meta:config', 'cleverbot:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'cleverbot:enabled').then(function (val) { + redis.hget('meta:config', 'cleverbot:enabled').then(val => { conf.cleverbot.enabled = val === '1'; load('cleverbot', conf.cleverbot.enabled); }); } else load('cleverbot', 'not stored'); }), - redis.hexists('meta:config', 'lockskip:move_pos').then(function (ex) { + redis.hexists('meta:config', 'lockskip:move_pos').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'lockskip:move_pos').then(function (val) { + redis.hget('meta:config', 'lockskip:move_pos').then(val => { conf.lockskip.move_pos = parseInt(val); load('lockskippos', conf.lockskip.move_pos); }); } else load('lockskippos', 'not stored'); }), - redis.hexists('meta:config', 'options:bouncer_plus').then(function (ex) { + redis.hexists('meta:config', 'options:bouncer_plus').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'options:bouncer_plus').then(function (val) { + redis.hget('meta:config', 'options:bouncer_plus').then(val => { conf.options.bouncer_plus = val === '1'; load('bouncer+', conf.options.bouncer_plus); }); } else load('bouncer+', 'not stored'); }), - redis.hexists('meta:config', 'state:lockdown').then(function (ex) { + redis.hexists('meta:config', 'state:lockdown').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'state:lockdown').then(function (val) { + redis.hget('meta:config', 'state:lockdown').then(val => { conf.state.lockdown = val === '1'; load('lockdown', conf.state.lockdown); }); } else load('lockdown', 'not stored'); }), - redis.hexists('meta:config', 'chatfilter:enabled').then(function (ex) { + redis.hexists('meta:config', 'chatfilter:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'chatfilter:enabled').then(function (val) { + redis.hget('meta:config', 'chatfilter:enabled').then(val => { conf.chatfilter.enabled = val === '1'; load('chatfilter', conf.chatfilter.enabled); }); } else load('chatfilter', 'not stored'); }), - redis.hexists('meta:config', 'options:dcmoveback').then(function (ex) { + redis.hexists('meta:config', 'options:dcmoveback').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'options:dcmoveback').then(function (val) { + redis.hget('meta:config', 'options:dcmoveback').then(val => { conf.dcmoveback.enabled = val === '1'; load('dcmoveback', conf.dcmoveback.enabled); }); } else load('dcmoveback', 'not stored'); }), - redis.hexists('meta:config', 'soundcloudguard:enabled').then(function (ex) { + redis.hexists('meta:config', 'soundcloudguard:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'soundcloudguard:enabled').then(function (val) { + redis.hget('meta:config', 'soundcloudguard:enabled').then(val => { conf.soundcloudGuard.enabled = val === '1'; load('soundcloudguard', conf.soundcloudGuard.enabled); }); } else load('soundcloudguard', 'not stored'); }), - redis.hexists('meta:config', 'youtubeguard:enabled').then(function (ex) { + redis.hexists('meta:config', 'youtubeguard:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'youtubeguard:enabled').then(function (val) { + redis.hget('meta:config', 'youtubeguard:enabled').then(val => { conf.youtubeGuard.enabled = val === '1'; load('youtubeguard', conf.youtubeGuard.enabled); }); } else load('youtubeguard', 'not stored'); }), - redis.hexists('meta:config', 'customcommands:enabled').then(function (ex) { + redis.hexists('meta:config', 'customcommands:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'customcommands:enabled').then(function (val) { + redis.hget('meta:config', 'customcommands:enabled').then(val => { conf.customcommands.enabled = val === '1'; load('customcommands', conf.customcommands.enabled); }); } else load('customcommands', 'not stored'); }), - redis.hexists('meta:config', 'afk:enabled').then(function (ex) { + redis.hexists('meta:config', 'afk:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'afk:enabled').then(function (val) { + redis.hget('meta:config', 'afk:enabled').then(val => { conf.afk.enabled = val === '1'; load('afk', conf.afk.enabled); }); } else load('afk', 'not stored'); }), - redis.hexists('meta:config', 'joinmode:enabled').then(function (ex) { + redis.hexists('meta:config', 'joinmode:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'joinmode:enabled').then(function (val) { + redis.hget('meta:config', 'joinmode:enabled').then(val => { conf.options.joinmode = val === '1'; load('joinmode', conf.options.joinmode); }); } else load('joinmode', 'not stored'); }), - redis.hexists('meta:config', 'channelblacklist:enabled').then(function (ex) { + redis.hexists('meta:config', 'channelblacklist:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'channelblacklist:enabled').then(function (val) { + redis.hget('meta:config', 'channelblacklist:enabled').then(val => { conf.blacklist.channelblacklist = val === '1'; load('ChannelBlacklist', conf.blacklist.channelblacklist); }); } else load('ChannelBlacklist', 'not stored'); }), - redis.hexists('meta:config', 'youtube:block:enabled').then(function (ex) { + redis.hexists('meta:config', 'youtube:block:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'youtubeguard:block:enabled').then(function (val) { + redis.hget('meta:config', 'youtubeguard:block:enabled').then(val => { conf.youtubeGuard.block = val === '1'; load('YouTubeBlock', conf.youtubeGuard.block); }); } else load('YouTubeBlock', 'not stored'); }), - redis.hexists('meta:config', 'soundcloud:block:enabled').then(function (ex) { + redis.hexists('meta:config', 'soundcloud:block:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'soundcloudguard:block:enabled').then(function (val) { + redis.hget('meta:config', 'soundcloudguard:block:enabled').then(val => { conf.soundcloudGuard.block = val === '1'; load('SoundCloudBlock', conf.soundcloudGuard.block); }); } else load('SoundCloudBlock', 'not stored'); }), - redis.hexists('meta:config', 'titleguard:enabled').then(function (ex) { + redis.hexists('meta:config', 'titleguard:enabled').then(ex => { if (ex === 1) { //noinspection JSUnresolvedFunction - redis.hget('meta:config', 'titleguard:enabled').then(function (val) { + redis.hget('meta:config', 'titleguard:enabled').then(val => { conf.titleguard.enabled = val === '1'; load('titleguard', conf.titleguard.enabled); }); } else load('titleguard', 'not stored'); }) - ]).then(function () { - redis.quit(); - }).catch(function (err) { + ]).catch(err => { story.warn('Error while loading config from redis', {attach: err}) }); function load(name, val) { loaded = loaded + 1; - story.debug('config', 'Loaded ' + name + ' [' + val.toString() + '] from Redis. ' + loaded + '/9'); + story.debug('config', `Loaded ${name} [${val.toString()}] from Redis. ${loaded}/9`); } } \ No newline at end of file diff --git a/lib/songfilters.js b/lib/songfilters.js index 50cf3da..01d3b0b 100644 --- a/lib/songfilters.js +++ b/lib/songfilters.js @@ -9,26 +9,26 @@ var songfilters = []; loadsongfilters(); function loadsongfilters() { - fs.readdir(path.resolve(__dirname, 'songfilters'), function (err, files) { + fs.readdir(path.resolve(__dirname, 'songfilters'), (err, files) => { if (err) { story.fatal('SongFilters', 'Cannot load songfilters', {attach: err}); songfilters.push(Promise.resolve()); } else { if (files.length === 0) songfilters.push(Promise.resolve); else { - files.forEach(function (file) { + files.forEach(file => { try { var filter = require(path.resolve(__dirname, 'songfilters', file)); if (filter.enabled) { songfilters.push(filter.check); - story.debug('SongFilters', 'Loaded singfilter ' + filter.name); - } else story.debug('SongFilters', 'Skipping ' + filter.name + ' since it\'s disabled.'); + story.debug('SongFilters', `Loaded singfilter ${filter.name}`); + } else story.debug('SongFilters', `Skipping ${filter.name} since it's disabled.`); } catch (e) { story.warn('SongFilters', 'Failed to load songfilter.', {attach: e}); } }); } - story.info('SongFilters', 'Loaded ' + (songfilters.length) + ' songfilters.'); + story.info('SongFilters', `Loaded ${songfilters.length} songfilters.`); } }); } diff --git a/lib/songfilters/blacklist.js b/lib/songfilters/blacklist.js index 196b52c..c617665 100644 --- a/lib/songfilters/blacklist.js +++ b/lib/songfilters/blacklist.js @@ -10,14 +10,14 @@ module.exports = { name: 'Blacklist', enabled: true, check: function (booth, now) { - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { //noinspection JSUnresolvedFunction - redis.hget('media:blacklist', now.media.format + ':' + now.media.cid).then(function (blentry) { + redis.hget('media:blacklist', `${now.media.format}:${now.media.cid}`).then(blentry => { if (blentry === null) resolve(); else reject({ type: 'blacklist', preskip: langfile.blacklist.skip_first, - afterskip: function () { + afterskip: (() => { if (blentry !== '1') return utils.replace(langfile.blacklist.skip_reason, { username: plugged.getUserByID(booth.dj).username, song: utils.songtitle(now.media.author, now.media.title), @@ -27,7 +27,7 @@ module.exports = { username: plugged.getUserByID(booth.dj).username, song: utils.songtitle(now.media.author, now.media.title) }); - }(), + })(), do_lockskip: config.blacklist.lockskip, blacklist: false }); diff --git a/lib/songfilters/channelblacklist.js b/lib/songfilters/channelblacklist.js index fbd41ec..875afee 100644 --- a/lib/songfilters/channelblacklist.js +++ b/lib/songfilters/channelblacklist.js @@ -13,11 +13,11 @@ module.exports = { name: 'ChannelBlacklist', enabled: true, check: function (booth, now) { - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { if (config.blacklist.channelblacklist && !config.state.eventmode && now.media.format === 1) { - ytApi.getSong(now.media).then(function (media) { + ytApi.getSong(now.media).then(media => { //noinspection JSUnresolvedFunction,JSUnresolvedVariable - redis.hget('media:channelblacklist', media.snippet.channelId).then(function (bl) { + redis.hget('media:channelblacklist', media.snippet.channelId).then(bl => { if (bl === null) { resolve(); } else { @@ -46,7 +46,7 @@ module.exports = { //noinspection JSUnresolvedVariable db.models.Channel.upsert({cid: media.snippet.channelId, name: media.snippet.channelTitle}); }); - }).catch(function (err) { + }).catch(err => { story.debug('ChannelBlacklist', '', {attach: err}); resolve(); }); diff --git a/lib/songfilters/history.js b/lib/songfilters/history.js index f7ad017..fc7ec3d 100644 --- a/lib/songfilters/history.js +++ b/lib/songfilters/history.js @@ -11,11 +11,11 @@ module.exports = { name: 'History', enabled: true, check: function (booth, now) { - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { if (config.history.skipenabled && !config.state.eventmode) { - redis.exists('media:history:' + now.media.format + ':' + now.media.cid).then(function (isHis) { + redis.exists(`media:history:${now.media.format}:${now.media.cid}`).then(isHis => { if (isHis === 1) { //noinspection JSUnresolvedFunction - redis.ttl('media:history:' + now.media.format + ':' + now.media.cid).then(function (ttl) { + redis.ttl(`media:history:${now.media.format}:${now.media.cid}`).then(ttl => { //noinspection JSUnresolvedFunction reject({ type: 'history', diff --git a/lib/songfilters/soundcloudguard.js b/lib/songfilters/soundcloudguard.js index 9e72a88..88f490f 100644 --- a/lib/songfilters/soundcloudguard.js +++ b/lib/songfilters/soundcloudguard.js @@ -10,7 +10,7 @@ module.exports = { name: 'SoundCloudGuard', enabled: true, check: function (booth, now) { - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { if(now.media.format === 2){ if (config.soundcloudGuard.block) reject({ type: 'soundcloudguard', @@ -20,7 +20,7 @@ module.exports = { blacklist: false }); else if (config.soundcloudGuard.enabled) { - soundCloudApi.check(now.media).spread(function (skip, reasons) { + soundCloudApi.check(now.media).spread((skip, reasons) => { if (skip) reject({ type: 'soundcloudguard', preskip: langfile.soundcloudGuard.skip, diff --git a/lib/songfilters/timeguard.js b/lib/songfilters/timeguard.js index 685f0a6..1e77e32 100644 --- a/lib/songfilters/timeguard.js +++ b/lib/songfilters/timeguard.js @@ -9,7 +9,7 @@ module.exports = { name: 'Timeguard', enabled: true, check: function (booth, now) { - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { if (config.timeguard.enabled && now.media.duration >= config.timeguard.time && !config.state.eventmode) reject({ type: 'Timeguard', preskip: langfile.skip.timeguard.skip, diff --git a/lib/songfilters/titleguard.js b/lib/songfilters/titleguard.js index 90af6d8..e8ffc8c 100644 --- a/lib/songfilters/titleguard.js +++ b/lib/songfilters/titleguard.js @@ -9,8 +9,8 @@ module.exports = { name: 'Titleguard', enabled: true, check: function (booth, now) { - return new Promise(function (resolve, reject) { - if (config.titleguard.enabled && utils.contains(utils.songtitle(now.media.author, now.media.title), config.titleguard.not_contain) && !config.state.eventmode) reject({ + return new Promise((resolve, reject) => { + if (config.titleguard.enabled && !config.state.eventmode && (utils.contains(utils.songtitle(now.media.author, now.media.title), config.titleguard.not_contain) || (config.titleguard.regex_match !== null ? config.titleguard.regex_match.test(utils.songtitle(now.media.author, now.media.title)) : false))) reject({ type: 'titleguard', preskip: langfile.titleguard.skip, afterskip: utils.replace(langfile.titleguard.contained, { diff --git a/lib/songfilters/youtubeguard.js b/lib/songfilters/youtubeguard.js index 34881ff..e0f8143 100644 --- a/lib/songfilters/youtubeguard.js +++ b/lib/songfilters/youtubeguard.js @@ -10,7 +10,7 @@ module.exports = { name: 'YouTubeGuard', enabled: true, check: function (booth, now) { - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { if (now.media.format === 1) { if (config.youtubeGuard.block) reject({ type: 'youtubeguard', @@ -20,7 +20,7 @@ module.exports = { blacklist: false }); else if (config.youtubeGuard.enabled && now.media.format === 1) { - youTubeApi.check(now.media).spread(function (skip, reasons, blacklist) { + youTubeApi.check(now.media).spread((skip, reasons, blacklist) => { if (skip) reject({ type: 'youtubeguard', preskip: langfile.youtubeGuard.skip, diff --git a/lib/userfilters.js b/lib/userfilters.js index d1eb426..7aebb46 100644 --- a/lib/userfilters.js +++ b/lib/userfilters.js @@ -8,26 +8,26 @@ var userfilters = []; loadfilters(); function loadfilters () { - fs.readdir(path.resolve(__dirname, 'userfilters'), function (err, files) { + fs.readdir(path.resolve(__dirname, 'userfilters'), (err, files) => { if (err) { story.fatal('UserFilters', 'Cannot load userfilters', {attach: err}); userfilters.push(Promise.resolve); } else { if (files.length === 0) userfilters.push(Promise.resolve); else { - files.forEach(function (file) { + files.forEach(file => { try { var filter = require(path.resolve(__dirname, 'userfilters', file)); if (filter.enabled) { userfilters.push(filter.check); - story.debug('UserFilters', 'Loaded userfilter ' + filter.name); - } else story.debug('UserFilters', 'Skipping ' + filter.name + ' since it\'s disabled.'); + story.debug('UserFilters', `Loaded userfilter ${filter.name}`); + } else story.debug('UserFilters', `Skipping ${filter.name} since it's disabled.`); } catch (e) { story.warn('UserFilters', 'Failed to load userfilter.', {attach: e}); } }); } - story.info('UserFilters', 'Loaded ' + (userfilters.length) + ' userfilters.'); + story.info('UserFilters', `Loaded ${userfilters.length} userfilters.`); } }); } diff --git a/lib/userfilters/username.js b/lib/userfilters/username.js index 26f3f2a..277b850 100644 --- a/lib/userfilters/username.js +++ b/lib/userfilters/username.js @@ -6,32 +6,40 @@ var utils = require('../utils'); var langfile = require('../../langfile'); var timeouts = require('../chatfilters').timeouts; -config.userfilter.username_disallowed = config.userfilter.username_disallowed.map(function (e) { - return new RegExp(e); -}); +config.userfilter.username_disallowed = config.userfilter.username_disallowed.map(e => new RegExp(e)); module.exports = { name: 'Username', enabled: true, check: function (user) { - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { if (config.userfilter.enabled) { for (var i in config.userfilter.username_disallowed) { if (user.username.match(config.userfilter.username_disallowed[i])) { - reject({ + return reject({ type: 'username', chat: utils.replace(langfile.userfilter.username.warn, {username: user.username}), action: function () { - timeouts[user.id] = setTimeout(function () { + timeouts[user.id] = setTimeout(() => { plugged.sendChat(utils.replace(langfile.userfilter.username.ban, {username: user.username})); plugged.banUser(user.id, plugged.BANDURATION.PERMA, plugged.BANREASON.VIOLATING_COMMUNITY_RULES); timeouts[user.id] = undefined; }, 60 * 1000); } }); - return; } } + if (config.userfilter.regex.test(user.username)) return reject({ + type: 'username', + chat: utils.replace(langfile.userfilter.username.warn, {username: user.username}), + action: function () { + timeouts[user.id] = setTimeout(() => { + plugged.sendChat(utils.replace(langfile.userfilter.username.ban, {username: user.username})); + plugged.banUser(user.id, plugged.BANDURATION.PERMA, plugged.BANREASON.VIOLATING_COMMUNITY_RULES); + timeouts[user.id] = undefined; + }, 60 * 1000); + } + }); resolve(); } else resolve(); }); diff --git a/lib/utils.js b/lib/utils.js index 324e0f6..4322ce3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -11,23 +11,19 @@ var plugged = require('./client'); var langfile = require('../langfile'); var utils = { - replace: function (str, replacer) { + replace: (str, replacer)=> { var keys = _.keys(replacer); var string = S(str); - keys.forEach(function (key) { + keys.forEach(key => { //noinspection JSUnresolvedFunction - string = string.replaceAll('&{' + key + '}', replacer[key] || ''); + string = string.replaceAll(`&{${key}}`, replacer[key] || ''); }); //noinspection JSUnresolvedVariable return string.s; }, - songtitle: function (author, title) { - return author + ' - ' + title; - }, - mediatitle: function (media) { - return media.author + ' - ' + media.title; - }, - role: function (role) { + songtitle: (author, title)=> `${author} - ${title}`, + mediatitle: (media)=> `${media.author} - ${media.title}`, + role: (role)=> { if (role === 'none' || role === 0) return plugged.USERROLE.NONE; else if (role === 'rdj' || role === 1) return plugged.USERROLE.RESIDENTDJ; else if (role === 'bouncer' || role === 2) return plugged.USERROLE.BOUNCER; @@ -36,7 +32,7 @@ var utils = { else if (role === 'host' || role === 5) return plugged.USERROLE.HOST; else return undefined; }, - permlevel: function (role) { + permlevel: (role)=> { if (role === plugged.USERROLE.NONE) return 0; else if (role === plugged.USERROLE.RESIDENTDJ) return 1; else if (role === plugged.USERROLE.BOUNCER) return 2; @@ -45,7 +41,7 @@ var utils = { else if (role === plugged.USERROLE.HOST) return 5; else return undefined; }, - rolename: function (role) { + rolename: (role)=> { if (role === plugged.USERROLE.NONE) return langfile.setstaff.roles.user; else if (role === plugged.USERROLE.RESIDENTDJ) return langfile.setstaff.roles.rdj; else if (role === plugged.USERROLE.BOUNCER) return langfile.setstaff.roles.bouncer; @@ -54,24 +50,19 @@ var utils = { else if (role === plugged.USERROLE.HOST) return langfile.setstaff.roles.host; else return langfile.setstaff.roles.undef; }, - blacklistReason: function (str) { + blacklistReason: (str)=> { var string = S(str); var keys = _.keys(langfile.blacklist.reasons); - keys.forEach(function (key) { + keys.forEach(key => { //noinspection JSUnresolvedFunction - string = string.replaceAll('#' + key, langfile.blacklist.reasons[key]); + string = string.replaceAll(`#${key}`, langfile.blacklist.reasons[key]); }); //noinspection JSUnresolvedVariable return string.s; }, - userLogString: function (user, id) { - return (typeof user === 'object' ? user.username + '[' + user.id + ']' : user + '[' + id + ']'); - }, - mediatitlelog: function (media) { - return media.author + ' - ' + media.title + '[' + media.id + '|' + media.format + '|' + media.cid + ']'; - }, - clone: function (obj, options) { - options = options || {}; + userLogString: (user, id)=> (typeof user === 'object' ? `${user.username}[${user.id}]` : `${user}[${id}]`), + mediatitlelog: (media)=> `${media.author} - ${media.title}[${media.id}|${media.format}|${media.cid}]`, + clone: (obj, options = {})=> { if (options.deep === undefined) options.deep = false; if (options.exclude === undefined) options.exclude = []; function copy(obj, level) { @@ -89,7 +80,7 @@ var utils = { clone = {}; for (i in obj) { if (!obj.hasOwnProperty(i)) continue; - if (options.exclude[level] !== undefined && options.exclude[level].indexOf(i) !== -1) continue; + if (options.exclude[level] !== undefined && options.exclude[level].includes(i)) continue; if (options.deep && level < 4) clone[i] = copy(obj[i], level + 1); else clone[i] = obj[i]; } @@ -99,7 +90,7 @@ var utils = { return copy(obj, 0); }, - contains: function (string, array) { + contains: (string, array)=> { //noinspection JSUnresolvedFunction var str = S(string.toLowerCase()); for (var i = 0; i < array.length; i++) { @@ -108,30 +99,29 @@ var utils = { } return false; }, - wlPosition: function (user, wl) { - wl = wl || plugged.getWaitlist(); + wlPosition: (user, wl = plugged.getWaitlist())=> { if (typeof user === 'object') user = user.id; return wl.indexOf(user); }, - isWlBanned: function (user) { - return new Promise(function (resolve, reject) { - if(Array.isArray(user)){ - Promise.all(user.map(function (u) { - if (typeof user === 'object') u = u.id; - return redis.exists('user:waitlist:ban:' + u); - })).then(function (ex) { - resolve(ex.indexOf(1) === -1); - }); - } else { - if (typeof user === 'object') user = user.id; - redis.exists('user:waitlist:ban:' + user).then(function (ex) { - resolve(ex === '1'); - }).catch(reject); - } + isWlBanned: (user)=> { + return new Promise((resolve, reject) => { + if (Array.isArray(user)) { + Promise.all(user.map(u => { + if (typeof user === 'object') u = u.id; + return redis.exists(`user:waitlist:ban:${u}`); + })).then(ex => { + resolve(!ex.includes(1)); + }); + } else { + if (typeof user === 'object') user = user.id; + redis.exists(`user:waitlist:ban:${user}`).then(ex => { + resolve(ex === '1'); + }).catch(reject); + } }); }, - resolveCID: function (input) { - return new Promise(function (resolve, reject) { + resolveCID: (input)=> { + return new Promise((resolve, reject) => { if (validator.isURL(input, { protocols: ['https'], host_whitelist: ['youtube.com', 'youtu.be', 'soundcloud.com', 'www.youtube.com'] @@ -139,16 +129,16 @@ var utils = { var url = URL.parse(input, true); if (url.hostname === 'youtu.be') { //noinspection JSUnresolvedFunction - resolve('1:' + S(url.pathname).replaceAll('/', '').s); + resolve(`1:${S(url.pathname).replaceAll('/', '').s}`); } else { //noinspection JSUnresolvedVariable if ((url.hostname === 'www.youtbe.com' || url.hostname === 'youtube.com') && url.query.v !== undefined) { //noinspection JSUnresolvedVariable - resolve('1:' + url.query.v) + resolve(`1:${url.query.v}`) } else if (url.hostname === 'soundcloud.com') { - request.get('https://api.soundcloud.com/resolve?client_id=' + config.apiKeys.soundcloud + '&url=' + input, function (err, resp, body) { + request.get(`https://api.soundcloud.com/resolve?client_id=${config.apiKeys.soundcloud}&url=${input}`, (err, resp, body) => { if (!err && resp.statusCode === 200) { body = JSON.parse(body); - resolve('2:' + body.id); + resolve(`2:${body.id}`); } else reject(new Error('SoundCloudApiError')); }); } else reject(new Error('invalid input')); diff --git a/package.json b/package.json index a9b51a6..2891750 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "plugbot", - "version": "1.3.2", + "version": "1.4.0", "main": "bot.js", "description": "A simple bot for plug.dj", - "author": "Fuechschen ", + "author": "Fuechschen ", "license": "MIT", "scripts": { "start": "node bot.js" @@ -16,32 +16,33 @@ "url": "https://github.com/Fuechschen/plugbot/issues" }, "dependencies": { - "bluebird": "^3.4.1", - "cron": "^1.1.0", - "fs": "0.0.2", - "ioredis": "^2.2.0", - "moment": "^2.14.1", - "mysql": "^2.11.1", + "bluebird": "^3.4.6", + "cron": "^1.1.1", + "fs": "0.0.1-security", + "ioredis": "^2.4.0", + "moment": "^2.17.0", + "mysql": "^2.12.0", "path": "^0.12.7", - "plugged": "^2.6.1", - "request": "^2.73.0", - "sequelize": "^3.23.4", - "storyboard": "^1.4.0", - "string": "^3.3.1", + "plugged": "^2.6.2", + "request": "^2.79.0", + "sequelize": "^3.27.0", + "storyboard": "^2.3.0", + "string": "^3.3.3", "underscore": "^1.8.3", - "validator": "^5.4.0" + "validator": "^6.1.0" }, "optionalDependencies": { - "cld": "^2.4.6", - "cleverbot-node": "git://github.com/avatarkava/cleverbot-node.git", + "cld": "^2.4.7", + "cleverbot-node": "github:avatarkava/cleverbot-node", "express": "^4.14.0", + "hiredis": "^0.5.0", "morgan": "^1.7.0", - "pg": "^6.0.1", + "pg": "^6.1.0", "pg-hstore": "^2.3.2", - "pm2": "^1.1.3", - "sqlite3": "^3.1.4", + "pm2": "^2.1.5", + "sqlite3": "^3.1.8", "tedious": "^1.14.0", - "uws": "^0.7.0", + "uws": "^0.9.0", "ws": "^1.1.1" } } diff --git a/readme.md b/readme.md index 5992aeb..6d16456 100644 --- a/readme.md +++ b/readme.md @@ -4,8 +4,9 @@ see all functions here: [functions.md](/docs/functions.md) ## Installation +0. Be sure to have node 6.x.x or higher installed. 1. Run ```npm install```. -2. Copy config.example.js to config.js and insert your data (Redis, SQL-Database, Roomname, [apiKeys](/docs/apikeys.md) and Login-Credentials are required.) +2. Copy config.example.js to config.js and insert your data (Redis, [SQL-Database](/docs/database.md), Roomname, [apiKeys](/docs/apikeys.md) and Login-Credentials are required.) 3. Start the bot ```npm start``` ## PM2 diff --git a/web/index.js b/web/index.js index 61398e2..8ddc732 100644 --- a/web/index.js +++ b/web/index.js @@ -8,7 +8,7 @@ var config = require('../lib/load_config'); var ws = null; var app = null; if (config.web.enabled) { - var Ws = require((config.web.useUWS ? 'u' : '') + 'ws').Server; + var Ws = require(`${config.web.useUWS ? 'u' : ''}ws`).Server; app = express(); @@ -27,104 +27,104 @@ if (config.web.enabled) { } })); - app.use(function (req, res, next) { + app.use((req, res, next) => { res.set('Access-Control-Allow-Origin', config.web.cors); next(); }); app.use('/v1', require('./v1')); - app.get('/', function (req, res) { + app.get('/', (req, res) => { res.json({ versions: { - "1": config.web.path + '/v1' + "1": `${config.web.path}/v1` } }); }); - app.use(function (req, res) { + app.use((req, res) => { res.status(404).json({error: 'Not Found'}); }); if (config.web.websocket) { if (config.web.port !== null) { - ws = new Ws({server: http, path: config.web.path + '/v1/socket'}); + ws = new Ws({server: http, path: `${config.web.path}/v1/socket`}); if (!config.web.useUWS) { - ws.broadcast = function (data) { - ws.clients.forEach(function (client) { + ws.broadcast = data => { + ws.clients.forEach(client => { client.send(data); }); } } - ws.on('connection', function (socket) { - var h = setInterval(function () { + ws.on('connection', socket => { + var h = setInterval(() => { socket.send(JSON.stringify({t: 'hb', d: {}})); }, 30 * 1000); - socket.on('close', function () { + socket.on('close', () => { clearInterval(h); }); }); } else story.warn('web', 'If you want to use the websocket, please provide a port to listen on.'); } - if (config.web.port !== null) http.listen(config.web.port || 3000, function () { - story.info('web', 'Listening on port ' + (config.web.port || 3000)); + if (config.web.port !== null) http.listen(config.web.port || 3000, () => { + story.info('web', `Listening on port ${config.web.port || 3000}`); }); else story.info('web', 'Not Listening on a port because port is set to null'); } module.exports = { - app: app, + app, wsGet: function (type) { switch (type) { case 'advance': - return function (update) { + return update => { if (ws !== null)ws.broadcast(JSON.stringify({t: 'adv', d: update})); }; break; case 'chat': - return function (msg) { + return msg => { if (ws !== null)ws.broadcast(JSON.stringify({t: 'chat', d: msg})); }; break; case 'skip': - return function (user) { + return user => { if (ws !== null)ws.broadcast(JSON.stringify({t: 'skip', d: user})); }; break; case 'userban': - return function (ban) { + return ban => { if (ws !== null)ws.broadcast(JSON.stringify({t: 'ban', d: ban})); }; break; case 'join': - return function (user) { + return user => { if (ws !== null)ws.broadcast(JSON.stringify({t: 'join', d: user})); }; break; case 'leave': - return function (user) { + return user => { if (ws !== null)ws.broadcast(JSON.stringify({t: 'leave', d: user})); }; break; case 'waitlist': - return function (wl) { + return wl => { if (ws !== null)ws.broadcast(JSON.stringify({t: 'wl', d: wl})); }; break; case 'vote': - return function (votes) { + return votes => { if (ws !== null)ws.broadcast(JSON.stringify({t: 'v', d: votes})); }; break; case 'chatDelete': - return function (data) { + return data => { if (ws !== null)ws.broadcast(JSON.stringify({t: 'chatDelete', d: data})); }; break; default: - return function () { + return () => { }; break; diff --git a/web/v1.js b/web/v1.js index 5b0972f..7740501 100644 --- a/web/v1.js +++ b/web/v1.js @@ -7,42 +7,47 @@ var db = require('../lib/db/sql_db'); var utils = require('../lib/utils'); var config = require('../lib/load_config'); -app.get('/', function (req, res) { +app.get('/', (req, res) => { res.json({ plug_data: { - all: config.web.path + '/v1/all', - users: config.web.path + '/v1/users', - media: config.web.path + '/v1/media', - history: config.web.path + '/v1/history', - room: config.web.path + '/v1/room', - waitlist: config.web.path + '/v1/waitlist' + all: `${config.web.path}/v1/all`, + users: `${config.web.path}/v1/users`, + media: `${config.web.path}/v1/media`, + history: `${config.web.path}/v1/history`, + room: `${config.web.path}/v1/room`, + waitlist: `${config.web.path}/v1/waitlist` }, bot_data: { - customCommands: config.web.path + '/v1/customcommands', - bestVotedSongs: config.web.path + '/v1/highscore', - blacklist: config.web.path + '/v1/blacklist', - channelblacklist: config.web.path + '/v1/channelblacklist', - check: config.web.path + '/v1/check?s={string}', - user: config.web.path + '/v1/user?id={userid}&name={username}' + customCommands: `${config.web.path}/v1/customcommands`, + bestVotedSongs: `${config.web.path}/v1/highscore`, + blacklist: `${config.web.path}/v1/blacklist`, + channelblacklist: `${config.web.path}/v1/channelblacklist`, + check: `${config.web.path}/v1/check?s={string}`, + user: `${config.web.path}/v1/user?id={userid}&name={username}` }, - socket: config.web.path + '/v1/socket' + socket: `${config.web.path}/v1/socket` }) }); -app.get('/users', function (req, res) { - res.json(plugged.getUsers().map(function (e) { - return {id: e.id, username: e.username, slug: e.slug, gRole: e.gRole, role: e.role, level: e.level} - })); +app.get('/users', (req, res) => { + res.json(plugged.getUsers().map(e => ({ + id: e.id, + username: e.username, + slug: e.slug, + gRole: e.gRole, + role: e.role, + level: e.level + }))); }); -app.get('/media', function (req, res) { +app.get('/media', (req, res) => { res.json({data: (plugged.getMedia().id !== -1 ? plugged.getMedia() : null)}); }); -app.get('/history', function (req, res) { - plugged.getRoomHistory(function (err, history) { +app.get('/history', (req, res) => { + plugged.getRoomHistory((err, history) => { if (err)res.status(500).end(); - else res.json(history.map(function (e) { + else res.json(history.map(e => { e.room = undefined; return e; }) @@ -50,40 +55,41 @@ app.get('/history', function (req, res) { }); }); -app.get('/room', function (req, res) { - res.json(function () { +app.get('/room', (req, res) => { + res.json((() => { var meta = plugged.getRoomMeta(); meta.favorite = undefined; meta.dj = (plugged.getDJ() !== undefined ? (plugged.getDJ().id !== -1 ? plugged.getDJ() : null) : null); return meta; - }()); + })()); }); -app.get('/waitlist', function (req, res) { +app.get('/waitlist', (req, res) => { res.json({ - data: plugged.getWaitlist().map(function (id) { - return plugged.getUserByID(id); - }) + data: plugged.getWaitlist().map(id => plugged.getUserByID(id)) }); }); -app.get('/all', function (req, res) { - plugged.getRoomHistory(function (err, history) { +app.get('/all', (req, res) => { + plugged.getRoomHistory((err, history) => { res.json({ - room: function () { + room: (() => { var meta = plugged.getRoomMeta(); meta.favorite = undefined; meta.dj = (plugged.getDJ() !== undefined ? (plugged.getDJ().id !== -1 ? plugged.getDJ() : null) : null); return meta; - }(), + })(), media: (plugged.getMedia().id !== -1 ? plugged.getMedia() : null), - users: plugged.getUsers().map(function (e) { - return {id: e.id, username: e.username, slug: e.slug, gRole: e.gRole, role: e.role, level: e.level}; - }), - waitlist: plugged.getWaitlist().map(function (id) { - return plugged.getUserByID(id); - }), - history: (err ? null : history.map(function (e) { + users: plugged.getUsers().map(e => ({ + id: e.id, + username: e.username, + slug: e.slug, + gRole: e.gRole, + role: e.role, + level: e.level + })), + waitlist: plugged.getWaitlist().map(id => plugged.getUserByID(id)), + history: (err ? null : history.map(e => { e.room = undefined; return e; })) @@ -91,31 +97,30 @@ app.get('/all', function (req, res) { }); }); -app.get('/customcommands', function (req, res) { +app.get('/customcommands', (req, res) => { //noinspection JSUnresolvedFunction - db.models.CustomCommand.findAll().map(function (e) { - return {id: e.id, trigger: e.trigger, message: e.message, enabled: e.status}; - }).then(function (ccs) { + db.models.CustomCommand.findAll().map(e => ({ + id: e.id, + trigger: e.trigger, + message: e.message, + enabled: e.status + })).then(ccs => { res.json({data: ccs}); - }).catch(function (err) { + }).catch(err => { story.warn('web', 'Error getting CustomCommands', {attach: err}); res.status(500).end(); }); }); -app.get('/highscore', function (req, res) { +app.get('/highscore', (req, res) => { var limit = parseInt(req.query.limit) || 10; //noinspection JSUnresolvedFunction - db.models.Play.findAll({order: [['woots', 'DESC']], limit: limit}).then(function (plays) { - Promise.all(plays.map(function (e) { - return e.getUser(); - })).then(function (users) { - Promise.all(plays.map(function (e) { - //noinspection JSUnresolvedFunction - return e.getSong(); - })).then(function (songs) { + db.models.Play.findAll({order: [['woots', 'DESC']], limit}).then(plays => { + Promise.all(plays.map(e => e.getUser())).then(users => { + Promise.all(plays.map(e => //noinspection JSUnresolvedFunction + e.getSong())).then(songs => { var data = []; - plays.forEach(function (play, i) { + plays.forEach((play, i) => { var p = { id: play.id, score: {woots: play.woots, mehs: play.mehs, grabs: play.grabs}, @@ -133,57 +138,53 @@ app.get('/highscore', function (req, res) { } : null); data.push(p); }); - res.json({data: data}); + res.json({data}); }); }); }); }); -app.get('/blacklist', function (req, res) { +app.get('/blacklist', (req, res) => { //noinspection JSUnresolvedFunction - db.models.Song.findAll({where: {is_banned: true}}).then(function (songs) { + db.models.Song.findAll({where: {is_banned: true}}).then(songs => { res.json({ - data: songs.map(function (song) { - return { - id: song.id, - author: song.author, - title: song.title, - format: song.format, - cid: song.cid, - image: song.image, - isBanned: song.is_banned, - banReason: song.ban_reason - }; - }) + data: songs.map(song => ({ + id: song.id, + author: song.author, + title: song.title, + format: song.format, + cid: song.cid, + image: song.image, + isBanned: song.is_banned, + banReason: song.ban_reason + })) }); - }).catch(function () { + }).catch(() => { res.status(500).json({error: 'SQL Error'}); }); }); -app.get('/channelblacklist', function (req, res) { +app.get('/channelblacklist', (req, res) => { //noinspection JSUnresolvedFunction - db.models.Channel.findAll({where: {is_banned: true}}).then(function (channels) { + db.models.Channel.findAll({where: {is_banned: true}}).then(channels => { res.json({ - data: channels.map(function (c) { - return { - name: c.name, - channel_id: c.cid, - is_banned: c.is_banned, - ban_reason: c.ban_reason - }; - }) + data: channels.map(c => ({ + name: c.name, + channel_id: c.cid, + is_banned: c.is_banned, + ban_reason: c.ban_reason + })) }); - }).catch(function () { + }).catch(() => { res.status(500).json({error: 'SQL Error'}); }); }); -app.get('/check', function (req, res) { +app.get('/check', (req, res) => { if (req.query.s !== undefined) { - utils.resolveCID(req.query.s).then(function (cid) { + utils.resolveCID(req.query.s).then(cid => { var split = cid.split(':'); - db.models.Song.find({where: {format: split[0], cid: split[1]}}).then(function (song) { + db.models.Song.find({where: {format: split[0], cid: split[1]}}).then(song => { if (song !== undefined && song !== null) { res.json({ data: { @@ -198,23 +199,23 @@ app.get('/check', function (req, res) { } }); } else res.status(404).json({error: 'song not found'}); - }).catch(function () { + }).catch(() => { res.status(500).json({error: 'SQL Error'}); }); - }).catch(function (error) { + }).catch(error => { res.json({error: error.message}); }); } else res.status(400).json({error: 'invalid query'}); }); -app.get('/user', function (req, res) { +app.get('/user', (req, res) => { var search = {}; if (req.query.id !== undefined) search.id = req.query.id; if (req.query.name !== undefined && req.query.id === undefined) search.username = req.query.name; if (req.query.id === undefined && req.query.name === undefined) res.status(400).json({error: 'invalid query'}); else { - db.models.User.find({where: search}).then(function (user) { + db.models.User.find({where: search}).then(user => { if (user !== undefined && user !== null) { res.json({ data: { @@ -229,7 +230,7 @@ app.get('/user', function (req, res) { } }); } else res.statusCode(404).json({error: 'User not found'}); - }).catch(function () { + }).catch(() => { res.status(500).json({error: 'SQL Error'}); }) }