atheme-ruby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/atheme-ruby.png)](http://badge.fury.io/rb/atheme-ruby) [![Dependency Status](https://gemnasium.com/Flauschbaellchen/atheme-ruby.png)](https://gemnasium.com/Flauschbaellchen/atheme-ruby)
2
2
 
3
+ This gem is a work-in-process. If you expire some bugs or search for features, try the master-branch first.
4
+ I try to maintain the interface as stable as I can, but until I release version 0.1.0 or 1.0.0 it'll probably change sometimes.
5
+
6
+ This README reflects the state of the master-branch.
7
+ Please consider that some features might not have been officially released yet.
8
+ Take a look at the commit history and the release date of the latest gem.
9
+
3
10
  # atheme-ruby
4
11
  The gem was inspired by [jameswritescode/atheme-ruby](https://github.com/jameswritescode/atheme-ruby/).
5
12
  However, his gem use module-methods and thus does not allow concurrent connections within the same script.
@@ -65,21 +72,30 @@ You may logout after you finished your work:
65
72
  ### Service-Calls
66
73
 
67
74
  This gem supports all service-bots of atheme, like chanserv, nickserv etc.
68
- You can call any commands you want to perform like you do on IRC; subcommands goes into the first argument of the method:
75
+ You can call any commands you want to perform like you do on IRC; Each param goes into a different argument of the method:
69
76
 
70
- @session.chanserv.info('#opers') # /msg chanserv info #opers
71
- @session.chanserv.list # /msg chanserv list
72
- @session.nickserv.help('set password') # /msg nickserv help password
77
+ @session.chanserv.info('#opers') # /msg chanserv info #opers
78
+ @session.chanserv.list # /msg chanserv list
79
+ @session.nickserv.mark("Nick", "ON", "marking Nick") # Marks Nick with a note
73
80
 
74
81
  I think you're getting the point...
75
82
  However, you can perform additional questions on these return values:
76
83
 
77
- @session.chanserv.info('#opers').founder #=> #<Atheme::User ...>
78
- @session.chanserv.info('#opers').founder.name #=> "Nick_Of_Founder"
79
- @session.chanserv.info('#opers').registered #=> #<Date: 2013-05-13 ((2456426j,0s,0n),+0s,2299161j)>
84
+ @session.chanserv.info('#opers').founder #=> #<Atheme::User ...>
85
+ @session.chanserv.info('#opers').founder.name #=> "Nick_Of_Founder"
86
+ @session.chanserv.info('#opers').registered #=> #<Date: 2013-05-13 ((2456426j,0s,0n),+0s,2299161j)>
87
+ @session.nickserv.info("Nick").mark!("marking Nick") #=> Marks an user
88
+
89
+ Or a bit simplier if you want to run multiple ones on one User/Channel/...
90
+
91
+ @session.nickserv.info("Nick") do |n|
92
+ n.mark!("marking...")
93
+ n.set_vhost!("omg.that.is.awesome")
94
+ n.reset_password!
95
+ end
80
96
 
81
- Take a look into _lib/atheme/services/*_ to find available subcommands.
82
- The commands return a Atheme::Entity or a subclass like Atheme::User or Atheme::Channel. You can call #raw_output on these to get the raw service reply of the command you called.
97
+ Take a look into _lib/atheme/services/*_ and _lib/atheme/entities/*_ to find available subcommands.
98
+ The commands which call the API return a Atheme::Entity or a subclass like Atheme::User or Atheme::Channel etc. You can call #raw_output on these to get the raw service reply of the command you called.
83
99
 
84
100
  TODO
85
101
  ----
@@ -1,7 +1,177 @@
1
1
  module Atheme
2
2
  class Channel < Entity
3
- def fetch!
3
+
4
+ def fetch! #:nodoc:
4
5
  @session.chanserv.info(@token)
5
6
  end
7
+
8
+ # Forcefully removes the channel, including
9
+ # all data associated with it (like access lists etc)
10
+ # and cannot be restored.
11
+ # Only opers may use this.
12
+ def fdrop!
13
+ @session.chanserv.fdrop(self.name)
14
+ end
15
+
16
+ # close! prevents a channel from being used. Anyone
17
+ # who enters is immediately kickbanned. The channel
18
+ # cannot be dropped and foundership cannot be
19
+ # transferred.
20
+ #
21
+ # On executing this method, it will immediately kick all
22
+ # users from the channel.
23
+ #
24
+ # Use unclose!/open! to reopen a channel. While closed,
25
+ # channels will still expire.
26
+ #
27
+ # Only opers may use this.
28
+ def close!(reason)
29
+ @session.chanserv.close(self.name, :on, reason)
30
+ end
31
+
32
+ # Opens a previously closed channel.
33
+ #
34
+ # Only opers may use this.
35
+ def open!
36
+ @session.chanserv.close(self.name, :off)
37
+ end
38
+ alias_method :unclose!, :open!
39
+
40
+ # Gives someone channel admin/protection (+a) permissions
41
+ # If the nick is omitted the action is performed
42
+ # on the person requesting the command.
43
+ # Nick can be a single user or an array of users (as strings or Atheme::Users).
44
+ def protect(nick)
45
+ change_permissions(:protect, nick)
46
+ end
47
+ alias_method :admin, :protect
48
+
49
+ # Takes channel operator (-a) permissions from someone.
50
+ # If the nick is omitted the action is performed
51
+ # on the person requesting the command.
52
+ # Nick can be a single user or an array of users (as strings or Atheme::Users).
53
+ def deprotect(nick)
54
+ change_permissions(:deprotect, nick)
55
+ end
56
+ alias_method :deadmin, :deprotect
57
+
58
+ # Gives someone channel operator (+o) permissions
59
+ # If the nick is omitted the action is performed
60
+ # on the person requesting the command.
61
+ # Nick can be a single user or an array of users (as strings or Atheme::Users).
62
+ def op(nick)
63
+ change_permissions(:op, nick)
64
+ end
65
+
66
+ # Takes channel operator (-o) permissions from someone.
67
+ # If the nick is omitted the action is performed
68
+ # on the person requesting the command.
69
+ # Nick can be a single user or an array of users (as strings or Atheme::Users).
70
+ def deop(nick)
71
+ change_permissions(:deop, nick)
72
+ end
73
+
74
+ # Gives someone channel halfop (+h).
75
+ # If the nick is omitted the action is performed
76
+ # on the person requesting the command.
77
+ # Nick can be a single user or an array of users (as strings or Atheme::Users).
78
+ def halfop(nick)
79
+ change_permissions(:halfop, nick)
80
+ end
81
+
82
+ # Takes channel halpop (-h) from someone.
83
+ # If the nick is omitted the action is performed
84
+ # on the person requesting the command.
85
+ # Nick can be a single user or an array of users (as strings or Atheme::Users).
86
+ def dehalfop(nick)
87
+ change_permissions(:dehalfop, nick)
88
+ end
89
+
90
+ # Gives someone channel voice (+v).
91
+ # If the nick is omitted the action is performed
92
+ # on the person requesting the command.
93
+ # Nick can be a single user or an array of users (as strings or Atheme::Users).
94
+ def voice(nick)
95
+ change_permissions(:voice, nick)
96
+ end
97
+
98
+ # Takes channel voice (-v) from someone.
99
+ # If the nick is omitted the action is performed
100
+ # on the person requesting the command.
101
+ # Nick can be a single user or an array of users (as strings or Atheme::Users).
102
+ def devoice(nick)
103
+ change_permissions(:devoice, nick)
104
+ end
105
+
106
+ # mark! allows operators to attach a note to a channel.
107
+ # For example, an operator could mark the channel to be a botnet channel.
108
+ def mark!(reason)
109
+ @session.chanserv.mark(self.name, :on, reason)
110
+ end
111
+
112
+ # Unmark a previously marked channel.
113
+ def unmark!
114
+ @session.chanserv.mark(self.name, :off)
115
+ end
116
+
117
+ # Allows you to regain control of your
118
+ # channel in the event of a takeover.
119
+ #
120
+ # More precisely, everyone will be deopped,
121
+ # limit and key will be cleared, all bans
122
+ # matching you are removed, a ban exception
123
+ # matching you is added (in case of bans Atheme
124
+ # can't see), the channel is set invite-only
125
+ # and moderated and you are invited.
126
+ #
127
+ # If you are on channel, you will be opped and
128
+ # no ban exception will be added.
129
+ def recover!
130
+ @session.chanserv.recover(self.name)
131
+ end
132
+
133
+ # Allows you to ban a user or hostmask from a channel.
134
+ def ban!(nick_or_host)
135
+ @session.chanserv.ban(self.name, nick_or_host)
136
+ end
137
+
138
+ # Allows you to unban a user or hostmask from a channel.
139
+ def unban!(nick_or_host)
140
+ @session.chanserv.unban(self.name, nick_or_host)
141
+ end
142
+
143
+ # The KICK command allows for the removal of a user from
144
+ # a channel. The user can immediately rejoin.
145
+ #
146
+ # Your nick will be added to the kick reason.
147
+ # The reason is optional./cs
148
+ def kick!(reason=nil)
149
+ reason.kind_of?(String) ? @session.chanserv.kick(self.name, nick) : @session.chanserv.kick(self.name, nick, reason)
150
+ end
151
+
152
+ # Sets a topic on the channel.
153
+ def topic!(topic)
154
+ @session.chanserv.topic(self.name, topic)
155
+ end
156
+
157
+ # Prepends something to the topic on the channel.
158
+ def prepend_topic!(topic)
159
+ @session.chanserv.topicprepend(self.name, topic)
160
+ end
161
+
162
+ private
163
+ def change_permissions(perm, nick=nil)
164
+ case
165
+ when nick.kind_of?(String)
166
+ @session.chanserv.send(perm, self.name, nick)
167
+ when nick.kind_of?(Atheme::User)
168
+ @session.chanserv.send(perm, self.name, nick.name)
169
+ when nick.kind_of?(Array)
170
+ nick.each do |n|
171
+ change_permissions(perm, self.name, n)
172
+ end
173
+ end
174
+ end
175
+
6
176
  end
7
177
  end
@@ -1,7 +1,60 @@
1
1
  module Atheme
2
2
  class User < EntityBase
3
- def fetch!
3
+
4
+ def fetch! #:nodoc:
4
5
  @session.nickserv.info(@token)
5
6
  end
7
+
8
+ # Forcefully removes the account, including
9
+ # all nicknames, channel access and memos attached to it.
10
+ # Only opers may use this.
11
+ def fdrop!
12
+ @session.nickserv.fdrop(self.name)
13
+ end
14
+
15
+ # freeze! allows operators to "freeze" an abusive user's
16
+ # account. This logs out all sessions logged in to the
17
+ # account and prevents further logins. Thus, users
18
+ # cannot obtain the access associated with the account.
19
+ def freeze!(reason)
20
+ @session.nickserv.freeze(self.name, :on, reason)
21
+ end
22
+
23
+ # Unfreeze an previously frozen account.
24
+ def unfreeze!
25
+ @session.nickserv.freeze(self.name, :off)
26
+ end
27
+
28
+ # mark! allows operators to attach a note to an account.
29
+ # For example, an operator could mark the account of
30
+ # a spammer so that others know the user has previously
31
+ # been warned.
32
+ def mark!(reason)
33
+ @session.nickserv.mark(self.name, :on, reason)
34
+ end
35
+
36
+ # Unmark a previously marked account.
37
+ def unmark!
38
+ @session.nickserv.mark(self.name, :off)
39
+ end
40
+
41
+ # vhost! allows operators to set a virtual host (also
42
+ # known as a spoof or cloak) on an account. This vhost
43
+ # will be set on the user immediately and each time
44
+ # they identify
45
+ def set_vhost!(vhost)
46
+ @session.nickserv.vhost(self.name, :on, vhost)
47
+ end
48
+
49
+ # Removes a previously added vhost from the account
50
+ def remove_vhost!
51
+ @session.nickserv.vhost(self.name, :off)
52
+ end
53
+
54
+ # Sets a random password for this account.
55
+ # Only opers may use this.
56
+ def reset_password!
57
+ @session.nickserv.resetpass(self.name)
58
+ end
6
59
  end
7
60
  end
data/lib/atheme/entity.rb CHANGED
@@ -14,6 +14,8 @@ module Atheme
14
14
  @updated = false
15
15
  @token = hash_or_token
16
16
  end
17
+
18
+ yield self if block_given?
17
19
  end
18
20
 
19
21
  def method_missing(meth, *args, &block)
@@ -81,12 +81,12 @@ module Atheme
81
81
  response = {raw_output: raw_output}
82
82
  parser = @@parsers.has_key?(service_name) && @@parsers[service_name][method]
83
83
 
84
- return Atheme::Entity.new(@session, response) unless parser
84
+ return Atheme::Entity.new(@session, response, &block) unless parser
85
85
 
86
86
  parser.commands.each do |command|
87
87
  response[command.name] = command.call(@session, raw_output)
88
88
  end
89
- parser.responder.new(@session, response) if parser.responder
89
+ parser.responder.new(@session, response, &block) if parser.responder
90
90
  end
91
91
 
92
92
  private
@@ -21,7 +21,8 @@ module Atheme
21
21
  end
22
22
 
23
23
  command :last_used do
24
- Date.parse(match(/Last\sused\s+:\s+(\w+ [0-9]{2} [0-9(:?)]+ [0-9]{4})/))
24
+ time = match(/Last\sused\s+:\s+(\w+ [0-9]{2} [0-9(:?)]+ [0-9]{4})/)
25
+ time && Date.parse(time)
25
26
  end
26
27
 
27
28
  command :mode_lock do
@@ -1,3 +1,3 @@
1
1
  module Atheme
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atheme-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-28 00:00:00.000000000 Z
12
+ date: 2013-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler