Skip to content

Commit

Permalink
Split disallow command into two commands
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearace committed Oct 2, 2014
1 parent 2caf182 commit 69eb1e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Require rank/permission:
- `$shuffle` - Shuffles the playlist. Requries mod or permission
- `$blockuser username [true|false]` - Stops username from adding videos. Requires owner rank to use
- `$settime time` - Sets the time on the video to time. Whereas time is in seconds. Requires mod or "T" permission.
- `$disallow (user) (true|false)` - Makes it so `user` cannot use the bot. Requires mod or "M" permission.
- `$allow (user)` - Makes it so `user` can use the bot. Requires mod or "M" permission.
- `$disallow (user)` - Makes it so `user` cannot use the bot. Requires mod or "M" permission.

Don't require rank/permission:

Expand Down
47 changes: 37 additions & 10 deletions lib/chatcommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,40 @@ var chatHandlers = {
})
},

"allow": function(bot, username, data, fromIRC) {
if (!data || fromIRC)
return

bot.checkPermission(username, 2, "M", function(hasPermission) {
if (!hasPermission)
return

var match = data.match(/(\w*)/)

if (!match)
return

var user = match[1]

var caller = utils.handle(bot, "getUser", username)
var user2 = utils.handle(bot, "getUser", user)

if (user === bot.username || !user2)
return

bot.checkPermission(user, 2, "M", function(userAlsoHasPermission) {
var lesserOrEqualUser = user2 && caller.rank <= user2.rank

if (lesserOrEqualUser && !userAlsoHasPermission) {
return bot.disallowUser(user, false)
} else if (lesserOrEqualUser && userAlsoHasPermission)
return

return bot.disallowUser(user, false)
})
})
},

"anagram": function(bot, username, msg) {
if ((new Date().getTime() - bot.timeSinceLastAnagram) / 1000 < 5)
return bot.sendPM(username, "Anagram cooldown")
Expand Down Expand Up @@ -263,13 +297,12 @@ var chatHandlers = {
if (!hasPermission)
return

var match = data.match(/(\w*) (true|false)/)
var match = data.match(/(\w*)/)

if (!match)
return

var user = match[1]
var flag = match[2]

var caller = utils.handle(bot, "getUser", username)
var user2 = utils.handle(bot, "getUser", user)
Expand All @@ -281,17 +314,11 @@ var chatHandlers = {
var lesserOrEqualUser = user2 && caller.rank <= user2.rank

if (lesserOrEqualUser && !userAlsoHasPermission) {
if (flag === "true")
return bot.disallowUser(user, true)
else
return bot.disallowUser(user, false)
return bot.disallowUser(user, true)
} else if (lesserOrEqualUser && userAlsoHasPermission)
return

if (flag === "true")
return bot.disallowUser(user, true)
else
return bot.disallowUser(user, false)
return bot.disallowUser(user, true)
})
})
},
Expand Down

0 comments on commit 69eb1e2

Please sign in to comment.