File tree Expand file tree Collapse file tree 4 files changed +32
-13
lines changed
Expand file tree Collapse file tree 4 files changed +32
-13
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,8 @@ task :start do
3434 c . nick = nick
3535 c . plugins . plugins = [ ClockPlugin , LoggerPlugin , ChannelChangerPlugin ]
3636 end
37-
3837
38+ #just to check if he's responding
3939 on :message , "hello" do |m |
4040 m . reply "Hello, #{ m . user . nick } "
4141 end
Original file line number Diff line number Diff line change 11require 'percival/channel_changer/plugin'
2+ require 'percival/channel_changer/user_role'
Original file line number Diff line number Diff line change 22class ChannelChangerPlugin
33 include Cinch ::Plugin
44
5- @@roles = { channel : [ "colwem" , "jfredett" ] }
65
76 match /join-channel\s +(\S +)/ , :method => :join
8- match /leave-channel(\s +(\S +))?/ , :method => :leave
7+ match /leave-channel(?:\s +(\S +))?/ , :method => :leave
8+
9+ listen_to :error , method : :error
10+
11+ # TODO: respond to error codes
12+ def error irc
13+ debug ( irc . to_s )
14+ end
15+
916
1017 #TODO: get rid of the 'space' var
1118 #TODO: inform if there is an error
12- def leave irc , space , channel
13- if role ? irc . user , :channel
14- channel = channel . nil? ? irc . channel : Channel ( channel )
15- bot . part ( channel )
19+ def leave irc , channel
20+ if UserRole . approved ? irc . user , :channel
21+ channel ||= irc . channel
22+ Channel ( channel ) . part
1623 end
1724 end
1825
1926 #TODO: confirm success or failure
2027 #TODO: inform if there is an error
2128 def join irc , channel
22- Channel ( channel ) . join ( ) if role? irc . user , :channel
23- end
24-
25-
26- def role? user , role
27- @@roles [ role ] . map { |u | User ( u ) } . include? user
29+ Channel ( channel ) . join ( ) if UserRole . approved? irc . user , :channel
2830 end
2931end
3032
Original file line number Diff line number Diff line change 1+ class UserRole
2+
3+ @@roles = { channel : [ "colwem" , "jfredett" ] }
4+
5+ #TODO: figure out how the various names work on irc (authname, nick,
6+ #realname ) Whats the difference between a user and his nick and authname
7+ def self . approved? ( user , role )
8+ if user . is_a? Cinch ::User
9+ user = user . name
10+ elsif ! user . is_? String
11+ throw "user was not a valid type [String, User]" # TODO: raise
12+ # better Exception
13+ end
14+ @@roles [ role ] . include? user
15+ end
16+ end
You can’t perform that action at this time.
0 commit comments