Skip to content

Commit 09031da

Browse files
committed
add lib/
1 parent 20c9e1a commit 09031da

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

lib/percival/channel_changer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
require 'percival/channel_changer/plugin'
2+
require 'percival/channel_changer/user_role'

lib/percival/channel_changer/plugin.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@
22
class 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
2931
end
3032

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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

0 commit comments

Comments
 (0)