-
Notifications
You must be signed in to change notification settings - Fork 8
Name changer and channel changer #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,11 @@ coverage/ | |
data/ | ||
.rbx | ||
|
||
|
||
*.swp | ||
*~ | ||
|
||
#emacs files | ||
\#* | ||
.#* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'percival/channel_changer/plugin' | ||
require 'percival/channel_changer/user_role' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
class ChannelChangerPlugin | ||
include Cinch::Plugin | ||
|
||
match /join-channel\s+(\S+)/, :method => :join | ||
match /leave-channel(?:\s+(\S+))?/, :method => :leave | ||
|
||
listen_to :error, method: :error | ||
|
||
def error irc | ||
debug( irc.to_s ) | ||
end | ||
|
||
def leave( irc, channel ) | ||
if UserRole.approved? irc.user, :channel_changer | ||
channel ||= irc.channel | ||
Channel(channel).part | ||
end | ||
end | ||
|
||
def join( irc, channel ) | ||
Channel(channel).join() if UserRole.approved? irc.user, :channel_changer | ||
end | ||
end | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class UserRole | ||
@test_users = ["colwem", "jfredett"] | ||
@roles = { | ||
super_user: @test_users, | ||
channel_changer: @test_users, | ||
name_changer: @test_users} | ||
|
||
def self.approved?(user, role) | ||
user = user.name if user.is_a? Cinch::User | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On thing to note here (not a major issue) It's good practice to ask what something can do rather than what something is. For instance, if I were to build a proxy object for Cinch::User which provided some extra methods or something, it might not .is_a? the way you think, but it still can fulfill the contract of this method (since it just proxies down to Cinch::User#name, perhaps). A concrete example might be a multi-name tracker, we might have a model Cinch::MultiUser, which tracks a user who uses multiple names that don't fit some schema, but we want to grant approval to all of them. We might also want to have a Cinch::AuthenticatedUser, which represents a Freenode auth'd user. etc. Just something to keep in mind. |
||
raise "user not in String, Cinch::User" unless user.is_a? String | ||
@roles[role].include? user | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'percival/name_changer/plugin' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class NameChangerPlugin | ||
include Cinch::Plugin | ||
|
||
match /change-name\s+(\S+)/, :method => :change_name | ||
|
||
def change_name( irc, name ) | ||
if UserRole.approved? irc.user, :name_changer | ||
bot.nick = name | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note, this is another good place to use the guard-style as noted in my other comment about UserRole#approved?