-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.rb
50 lines (43 loc) · 1.42 KB
/
system.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Validates origin and permissions over request
module Validate
ADMIN_LIST = ''.freeze
CHANNEL_LIST = ''.freeze
BAN_LIST = ''.freeze
# Validates if user is banned
def worthy?(user)
'NOT' if BAN_LIST.include?(user) # || !ADMIN_LIST.include?(user)
end
# Validates if the specified channel is whitelisted
def channel?(chan)
'LOCKED ORIGIN' unless CHANNEL_LIST.include?(chan)
end
# Differentiates the permissions for the calling user based on the channel
def redirect(value, user, channel)
case value
when 'NOT'
if BAN_LIST.include?(user)
LERN.response(channel, 'You are still banned until i forget it')
elsif ADMIN_LIST.include?(user)
LERN.response('#logs', "User #{user} tried to do something nasty")
end
when 'LOCKED ORIGIN'
LERN.response('#logs', "User #{user} making me work on #{channel}")
end
end
end
# Differentiates the request type and triggers the happy response
class Reply
extend Validate
def initialize(data, reply)
if data.respond_to? :channel
user = data.user
channel = data.channel
access = Reply.worthy?(user)
scope = Reply.channel?(channel)
LERN.response('#bots', reply) unless Reply.redirect(scope, user, channel).nil?
LERN.response(channel, reply) if Reply.redirect(access, user, channel).nil?
else
LERN.response(data, reply) if Reply.redirect(access, user, channel).nil?
end
end
end