LearnProgramming / percival

An IRC bot designed to help the LPMCers track quotes, log channels, and all sorts of things
22 stars 8 forks source link

Channel Changer Plugin #7

Open jfredett opened 12 years ago

jfredett commented 12 years ago

When an approved user sends the command

!join-channel <channel>

Percy should join that channel

When an approve user sends the command

!leave-channel <channel>

Percy should leave, the channel in this case should default to the current channel.

colwem commented 12 years ago

Starting work on this issue.

colwem commented 12 years ago

I need some assistance. for some reason I can't get anything to match using

match /match_regex/

or any of the other forms of that feature in cinch. I even tried making my own cinch project in which I simple copied their demo of that feature and it still isn't working. Could I have something miss configured? could I be missing a prereq. I can't believe that this feature would need any other package since regex is built in.

jfredett commented 12 years ago

Hmm, do you have your code up in a fork somewhere?

One thing to make sure is that you're loading the plugin in the rake start command. In the plugin list.

jfredett commented 12 years ago

Ah- I see (looked at your fork) -- you don't need to add the ! at the beginning of the command. Cinch will add that for you.

colwem commented 12 years ago

Ok thank you. I now have it mostly working. It also defaults to

!leave-channel

is equivalent to

!leave-channel [current_channel]

Future work

Git?

I've updated my branch of the fork. will that be included in the pull request I issued earlier or will I need to request a pull again.

jfredett commented 12 years ago

Cool.

As for User Privileges. I think it can just be controlled by an ENV Var at start up, and a command for any privileged user to add another.

IRC does have a notion of a 'registered' user -- but that's per-server (eg, on freenode, you can register your nickname). Ideally, we only allow registered nicknames to do anything required by an approved user. I think you would need to learn Freenode's IRC API (a series of messages, usually sent to/received from the ChanServ and NickServ users). For a first pass, a series of hardcoded names should suffice.

When updating a branch associated with a pull request, any update is automatically propagated to the PR. Thus, if you intend to submit two separate PR's, you should have two separate branches. I recommend trying to only have one open at a time, because otherwise you'll end up in rebase hell.

colwem commented 12 years ago

I've got an issue I would like some help with. I'm trying to extend the Cinch::User class to contain something like

class Cinch::User

  roles = [:channel => ["colwem", "jfredett"]]

  def role? role
    roles[role].include? self
  end
end

#so that I can call 

do_role_action if irc.user.role? :role

But I'm really at a loss for exactly how to do this. It's a matter of scope and I've never been very good at scope in ruby (I've never been very good at ruby actually).

I would like to share my code however I've run into a problem with my understanding of git and github. I've made a branch 'channel_changer' and I would like to push it to github so you can look at it. However I did

git checkout channel_changer
git add .
git commit -m "comment"
git push

But I can't find branch on github. How do I push the branch such that I can get it on github?

jfredett commented 12 years ago

As for the first bit, I would recommend, emphatically, not monkey patching the Cinch::User class. since it's responsibility (representing an IRC user) is highly dissimilar from the responsibility of determine user capabilities. Essentially, the relationship between users and their 'approved' status is that of a "HAS_A", not an "IS_A" -- that is to say, it's not a property, but an association. A user may be associated with a "Role" of being approved. To accomplish this, I would structure it as follows:


class UserRole
  def self.approved?(username)
    ENV["APPROVED_USERS"].include?(username)
  end
end

This way, you code becomes:


do_action if UserRole.approved?(irc.user)

(mod API mistakes on my part).

We could then naturally extend that UserRole object to include other roles. Also, we could do:


class UserRole
  def self.if_approved?(user)
    yield if approved?(user)
  end
end

This way, we alter the API to look like:


UserRole.if_approved?(user) do
  do_action
end

Which I think reads a little nicer.

This way also avoids any sort of weird scope bugs.


As for the git issue, you probably need to specify git push origin channel_changer, git push -- iirc -- will not, by default, push branches. I could be wrong on that, but it's usually better to do 'git push origin ' (even in the case of master) -- so that you never accidentally push the wrong branch.

After that, there is a 'branch' dropdown in the upper lefthand corner of the directory listing, should be able to push that and see where the branch lives.

colwem commented 12 years ago

Ok jfredett I've added a UserRole class with one class method approved?. I've pushed it with git push origin channel_changer.