File tree Expand file tree Collapse file tree 6 files changed +58
-3
lines changed
Expand file tree Collapse file tree 6 files changed +58
-3
lines changed Original file line number Diff line number Diff line change @@ -9,5 +9,11 @@ coverage/
99data /
1010.rbx
1111
12+
1213* .swp
1314* ~
15+
16+ # emacs files
17+ \# *
18+ . #*
19+
Original file line number Diff line number Diff line change 2121desc "start percival, connect to all channels in the CHANNELS env var"
2222task :start do
2323 system 'mkdir -p data/timesheets/'
24- channels = ENV [ "CHANNELS" ] . split ( /,\s */ )
24+ channels = ENV [ "CHANNELS" ] && ENV [ "CHANNELS" ] . split ( /,\s */ ) || [ "#lpmc-bot" ]
25+ nick = ENV [ "NICK" ] || "percival"
2526 server = 'irc.freenode.com'
2627
2728 require 'percival'
@@ -30,8 +31,10 @@ task :start do
3031 configure do |c |
3132 c . server = server
3233 c . channels = channels
33- c . nick = 'percival'
34- c . plugins . plugins = [ ClockPlugin , LoggerPlugin ]
34+ c . nick = nick
35+ c . plugins . plugins = [ ClockPlugin ,
36+ LoggerPlugin ,
37+ ChannelChangerPlugin ]
3538 end
3639 end
3740
Original file line number Diff line number Diff line change 33require 'percival/version'
44require 'percival/clock'
55require 'percival/logger'
6+ require 'percival/channel_changer'
67
78PERCIVAL_ROOT = File . dirname ( File . dirname ( __FILE__ ) )
89
Original file line number Diff line number Diff line change 1+ require 'percival/channel_changer/plugin'
2+ require 'percival/channel_changer/user_role'
Original file line number Diff line number Diff line change 1+
2+ class ChannelChangerPlugin
3+ include Cinch ::Plugin
4+
5+ match /join-channel\s +(\S +)/ , :method => :join
6+ match /leave-channel(?:\s +(\S +))?/ , :method => :leave
7+
8+ listen_to :error , method : :error
9+
10+ def error irc
11+ debug ( irc . to_s )
12+ end
13+
14+ def leave irc , channel
15+ if UserRole . approved? irc . user , :channel_changer
16+ channel ||= irc . channel
17+ Channel ( channel ) . part
18+ end
19+ end
20+
21+ def join irc , channel
22+ Channel ( channel ) . join ( ) if UserRole . approved? irc . user , :channel_changer
23+ end
24+ end
25+
26+
27+
Original file line number Diff line number Diff line change 1+ class UserRole
2+ @@test_users = [ "colwem" , "jfredett" ]
3+ @@roles = {
4+ super_user : @@test_users ,
5+ channel_changer : @@test_users ,
6+ name_changer : @@test_users }
7+
8+ def self . approved? ( user , role )
9+ if user . is_a? Cinch ::User
10+ user = user . name
11+ elsif ! user . is_a? String
12+ throw "user was not a valid type [String, User]"
13+ end
14+ @@roles [ role ] . include? user #or @@roles[:super_user].include? user
15+ end
16+ end
You can’t perform that action at this time.
0 commit comments