turntabler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.yardopts +7 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +383 -0
- data/Rakefile +11 -0
- data/examples/Gemfile +3 -0
- data/examples/Gemfile.lock +29 -0
- data/examples/autobop.rb +13 -0
- data/examples/autofan.rb +13 -0
- data/examples/blacklist.rb +16 -0
- data/examples/bop.rb +15 -0
- data/examples/bopcount.rb +20 -0
- data/examples/chat_bot.rb +16 -0
- data/examples/modlist.rb +19 -0
- data/examples/switch.rb +40 -0
- data/examples/time_afk_list.rb +46 -0
- data/lib/turntabler/assertions.rb +36 -0
- data/lib/turntabler/authorized_user.rb +217 -0
- data/lib/turntabler/avatar.rb +34 -0
- data/lib/turntabler/boot.rb +22 -0
- data/lib/turntabler/client.rb +457 -0
- data/lib/turntabler/connection.rb +176 -0
- data/lib/turntabler/digest_helpers.rb +13 -0
- data/lib/turntabler/error.rb +5 -0
- data/lib/turntabler/event.rb +239 -0
- data/lib/turntabler/handler.rb +67 -0
- data/lib/turntabler/loggable.rb +11 -0
- data/lib/turntabler/message.rb +24 -0
- data/lib/turntabler/playlist.rb +50 -0
- data/lib/turntabler/preferences.rb +70 -0
- data/lib/turntabler/resource.rb +194 -0
- data/lib/turntabler/room.rb +377 -0
- data/lib/turntabler/room_directory.rb +133 -0
- data/lib/turntabler/snag.rb +16 -0
- data/lib/turntabler/song.rb +247 -0
- data/lib/turntabler/sticker.rb +48 -0
- data/lib/turntabler/sticker_placement.rb +25 -0
- data/lib/turntabler/user.rb +274 -0
- data/lib/turntabler/version.rb +9 -0
- data/lib/turntabler/vote.rb +19 -0
- data/lib/turntabler.rb +102 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/turntabler_spec.rb +4 -0
- data/turntable.gemspec +24 -0
- metadata +173 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Aaron Pfeifer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,383 @@
|
|
1
|
+
# turntabler [![Build Status](https://secure.travis-ci.org/obrie/turntabler.png "Build Status")](http://travis-ci.org/obrie/turntabler) [![Dependency Status](https://gemnasium.com/obrie/turntabler.png "Dependency Status")](https://gemnasium.com/obrie/turntabler)
|
2
|
+
|
3
|
+
*turntabler* is an evented Turntable.FM API for Ruby.
|
4
|
+
|
5
|
+
## Resources
|
6
|
+
|
7
|
+
API
|
8
|
+
|
9
|
+
* http://rdoc.info/github/obrie/turntabler/master/frames
|
10
|
+
|
11
|
+
Bugs
|
12
|
+
|
13
|
+
* http://github.com/obrie/turntabler/issues
|
14
|
+
|
15
|
+
Development
|
16
|
+
|
17
|
+
* http://github.com/obrie/turntabler
|
18
|
+
|
19
|
+
Testing
|
20
|
+
|
21
|
+
* http://travis-ci.org/obrie/turntabler
|
22
|
+
|
23
|
+
Source
|
24
|
+
|
25
|
+
* git://github.com/obrie/turntabler.git
|
26
|
+
|
27
|
+
## Description
|
28
|
+
|
29
|
+
Turntabler makes it dead-simple to interact with the Turntable.FM API. It is
|
30
|
+
designed primarily as an all-purpose library with additional thoughts given to
|
31
|
+
the use of it for bots. It is an opinionated library that attempts to hide the
|
32
|
+
various complexities and inconsistencies with the Turntable API by providing a
|
33
|
+
clean, fresh new perspective on how data is accessed and organized.
|
34
|
+
|
35
|
+
This project was built from the ground-up by Rubyists for Rubyists. While prior
|
36
|
+
projects in other languages were used for guidance on some of the implementation,
|
37
|
+
the design is meant to take advantage of the various features offered by Ruby 1.9+.
|
38
|
+
|
39
|
+
Some brief, high-level features include:
|
40
|
+
|
41
|
+
* Evented, non-blocking IO
|
42
|
+
* Fiber-aware, untangled callbacks
|
43
|
+
* Interactive console support
|
44
|
+
* Clean, object-oriented APIs
|
45
|
+
* Detailed API documentation
|
46
|
+
* 100% complete Turntable API implementation
|
47
|
+
* Lazy-loaded attributes
|
48
|
+
* Auto-reconnects for bots
|
49
|
+
* Consistent API / attribute naming schemes
|
50
|
+
* HTTP / Web Socket interface implementations
|
51
|
+
* Room state / user list management
|
52
|
+
* DSL syntax support
|
53
|
+
|
54
|
+
Turntable features include management of:
|
55
|
+
|
56
|
+
* User status
|
57
|
+
* User profiles
|
58
|
+
* Site preferences
|
59
|
+
* Avatars
|
60
|
+
* Laptops / stickers
|
61
|
+
* Playlists
|
62
|
+
* Fans
|
63
|
+
* Buddies (Twitter / Facebook)
|
64
|
+
* Blocked users
|
65
|
+
* Private messages
|
66
|
+
* Advanced room listings
|
67
|
+
* Room search
|
68
|
+
* Room favorites
|
69
|
+
* Room profiles
|
70
|
+
* Room chat
|
71
|
+
* Moderators
|
72
|
+
* DJs
|
73
|
+
* Booted users
|
74
|
+
* Song search
|
75
|
+
* Song snags
|
76
|
+
* Song voting
|
77
|
+
* User / room reporting
|
78
|
+
|
79
|
+
Examples of the usage patterns for some of the above features are shown below.
|
80
|
+
You can find much more detailed documentation in the actual API.
|
81
|
+
|
82
|
+
## Usage
|
83
|
+
|
84
|
+
### Example
|
85
|
+
|
86
|
+
Below is an example of many of the features offered by this API, including:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
require 'turntabler'
|
90
|
+
|
91
|
+
USER = ENV['USER']
|
92
|
+
AUTH = ENV['AUTH']
|
93
|
+
|
94
|
+
Turntabler.run do
|
95
|
+
client = Turntabler::Client.new(USER, AUTH)
|
96
|
+
|
97
|
+
# Events
|
98
|
+
client.on :user_entered do |user|
|
99
|
+
puts "#{user.name} entered the room"
|
100
|
+
user.become_fan
|
101
|
+
end
|
102
|
+
|
103
|
+
client.on :user_left do |user|
|
104
|
+
puts "#{user.name} left the room"
|
105
|
+
end
|
106
|
+
|
107
|
+
client.on :user_spoke do |message|
|
108
|
+
if message.text =~ /bop/
|
109
|
+
client.room.current_song.vote
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
client.on :dj_added do |user|
|
114
|
+
puts "#{user.name} started DJing"
|
115
|
+
end
|
116
|
+
|
117
|
+
client.on :dj_removed do |user|
|
118
|
+
puts "#{user.name} stopped DJing"
|
119
|
+
end
|
120
|
+
|
121
|
+
# Authorized user interactions
|
122
|
+
user = client.user
|
123
|
+
user.fan_of
|
124
|
+
user.fans
|
125
|
+
user.playlist.songs
|
126
|
+
user.blocks
|
127
|
+
user.buddies
|
128
|
+
|
129
|
+
# Room Directory
|
130
|
+
client.rooms.list(:favorites => true)
|
131
|
+
client.rooms.list(:genre => :rock)
|
132
|
+
client.rooms.list(:genre => :rock, :available_djs => true, :minimum_listeners => 5)
|
133
|
+
client.rooms.with_friends
|
134
|
+
client.room('...').listeners
|
135
|
+
|
136
|
+
# Room interaction
|
137
|
+
room = client.room
|
138
|
+
room.add_as_favorite
|
139
|
+
room.become_dj
|
140
|
+
room.say "Hey guys!"
|
141
|
+
|
142
|
+
# User interaction
|
143
|
+
user.listeners.each do |listener|
|
144
|
+
listener.messages
|
145
|
+
listener.website
|
146
|
+
listener.facebook_url
|
147
|
+
listener.sticker_placements
|
148
|
+
listener.say "Welcome to the room!"
|
149
|
+
end
|
150
|
+
|
151
|
+
# Songs
|
152
|
+
client.search_song('Rolling Stones').each do |song|
|
153
|
+
song.enqueue
|
154
|
+
end
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
158
|
+
The examples above is just a very, very small subset of the possible things you
|
159
|
+
can do with turntabler. For a *complete* list, see the API documentation, especially:
|
160
|
+
|
161
|
+
* [Turntabler::AuthorizedUser](http://rdoc.info/github/obrie/turntabler/master/Turntabler/AuthorizedUser)
|
162
|
+
* [Turntabler::Client](http://rdoc.info/github/obrie/turntabler/master/Turntabler/Client)
|
163
|
+
* [Turntabler::Playlist](http://rdoc.info/github/obrie/turntabler/master/Turntabler/Playlist)
|
164
|
+
* [Turntabler::Room](http://rdoc.info/github/obrie/turntabler/master/Turntabler/Room)
|
165
|
+
* [Turntabler::RoomDirectory](http://rdoc.info/github/obrie/turntabler/master/Turntabler/RoomDirectory)
|
166
|
+
* [Turntabler::Song](http://rdoc.info/github/obrie/turntabler/master/Turntabler/Song)
|
167
|
+
* [Turntabler::User](http://rdoc.info/github/obrie/turntabler/master/Turntabler/User)
|
168
|
+
|
169
|
+
## Additional Topics
|
170
|
+
|
171
|
+
### Differences with existing libraries
|
172
|
+
|
173
|
+
So you may be asking "Why another Turntable.FM API library?" or "Why re-build
|
174
|
+
this in Ruby when you have a stable Javascript project?" Simply put, I felt that
|
175
|
+
all of the high-level features highlighted in the Description section of this
|
176
|
+
document were missing in each of those existing libraries.
|
177
|
+
|
178
|
+
Existing implementations include:
|
179
|
+
|
180
|
+
* [turntable-api-rb](https://github.com/lmcalpin/turntable-api-rb)
|
181
|
+
* [ruby_ttapi](https://github.com/alaingilbert/Turntable-API)
|
182
|
+
* [TurntableBot](https://github.com/mrhazel/TurntableBot)
|
183
|
+
|
184
|
+
My personal believe is that none of these reflect the simplicity that you can
|
185
|
+
build libraries with in Ruby. Those include evented I/O, untangled callbacks,
|
186
|
+
object-oriented APIs, external API consistency, internal state management,
|
187
|
+
auto lazy-loading, etc. Some of these libraries are also either incomplete
|
188
|
+
implementations, difficult to use / play around with, or generally just put
|
189
|
+
together as a script instead of a thoughtfully-designed library.
|
190
|
+
|
191
|
+
However, by no means does that mean I'm attempting to belittle the efforts put
|
192
|
+
forther by these authors -- all of their work provided the foundation necessary
|
193
|
+
to build out this project.
|
194
|
+
|
195
|
+
### Shortcuts
|
196
|
+
|
197
|
+
`Turntabler` is a long name and sometimes it's easier to just have a more brief
|
198
|
+
name available in the same way that `EventMachine` can also be referenced as `EM`.
|
199
|
+
To help you type a little bit fast, `Turntabler` is also aliased as `TT`. As a
|
200
|
+
result, you can interact with the API like so:
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
TT.run do
|
204
|
+
client = TT::Client.new(USER, AUTH, :room => ROOM)
|
205
|
+
client.room.become_dj
|
206
|
+
# ...
|
207
|
+
end
|
208
|
+
```
|
209
|
+
|
210
|
+
### Interactive Console
|
211
|
+
|
212
|
+
Typically it's difficult to debug or run simple tests within IRB when using
|
213
|
+
EventMachine. However, turntabler provides a few simple ways to do this so that
|
214
|
+
you can play around with the API interactively.
|
215
|
+
|
216
|
+
For example:
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
1.9.3-p286 :001 > require 'turntabler'
|
220
|
+
=> true
|
221
|
+
1.9.3-p286 :002 > TT.interactive
|
222
|
+
=> true
|
223
|
+
1.9.3-p286 :003 > client = nil
|
224
|
+
=> nil
|
225
|
+
1.9.3-p286 :004 > TT.run do
|
226
|
+
1.9.3-p286 :005 > client = Turntabler::Client.new(USER, AUTH)
|
227
|
+
1.9.3-p286 :006 > end
|
228
|
+
=> nil
|
229
|
+
D, [2012-11-20T08:36:08.025015 #21419] DEBUG -- : Socket opened
|
230
|
+
D, [2012-11-20T08:36:08.045872 #21419] DEBUG -- : Message received: {"command"=>"no_session"}
|
231
|
+
D, [2012-11-20T08:36:08.046437 #21419] DEBUG -- : Message sent: {:api=>"user.authenticate", ...}
|
232
|
+
D, [2012-11-20T08:36:08.119629 #21419] DEBUG -- : Message received: {"msgid"=>1, "success"=>true, ...}
|
233
|
+
D, [2012-11-20T08:36:08.120213 #21419] DEBUG -- : Message sent: {:api=>"user.get_fan_of", ...}
|
234
|
+
D, [2012-11-20T08:36:08.188266 #21419] DEBUG -- : Message received: {"msgid"=>2, "success"=>true, ...}
|
235
|
+
D, [2012-11-20T08:36:08.189158 #21419] DEBUG -- : Message sent: {:api=>"presence.update", ...}
|
236
|
+
D, [2012-11-20T08:36:08.266749 #21419] DEBUG -- : Message received: {"msgid"=>3, "success"=>true, ...}
|
237
|
+
|
238
|
+
# later on...
|
239
|
+
1.9.3-p286 :008 > TT.run { puts client.user.fan_of.inspect }
|
240
|
+
=> nil
|
241
|
+
D, [2012-11-20T08:39:41.084693 #21419] DEBUG -- : Message sent: {:api=>"user.get_fan_of", ...}
|
242
|
+
D, [2012-11-20T08:39:41.159466 #21419] DEBUG -- : Message received: {"msgid"=>25, "success"=>true, ...}
|
243
|
+
[#<Turntabler::User:0xa0c7da8 @id="...">, #<Turntabler::User:0xa0c7bf0 @id="...">]
|
244
|
+
```
|
245
|
+
|
246
|
+
In this example, an instance of `Turntabler::Client` is created and tracked in
|
247
|
+
the console. Later on, we can then run a command on that client by evaluating
|
248
|
+
it within a `TT.run` block. Note that additional debugging output is displayed --
|
249
|
+
this is for demonstration purposes only and can be turned off simply by changing
|
250
|
+
the logging level of `Turntabler.logger`.
|
251
|
+
|
252
|
+
### DSL usage
|
253
|
+
|
254
|
+
turntabler has basic support for a DSL language in order to simplify some of the
|
255
|
+
scripts you may be writing. The DSL is essentially made available by executing
|
256
|
+
blocks within the context of a Turntabler::Client.
|
257
|
+
|
258
|
+
There are two ways to do this:
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
# Using the TT.run shortcut:
|
262
|
+
|
263
|
+
TT.run(USER, AUTH, :room => ROOM) do
|
264
|
+
room.dj
|
265
|
+
on :user_entered do
|
266
|
+
# ...
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
# Using Turntabler::Client:
|
271
|
+
|
272
|
+
TT.run do
|
273
|
+
Turntabler::Client.new(USER, AUTH, :room => ROOM) do
|
274
|
+
room.dj
|
275
|
+
on :user_entered do
|
276
|
+
# ...
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
```
|
281
|
+
|
282
|
+
*Note* that you will likely not want to use the first example (using the `TT.run`
|
283
|
+
shortcut when running in the context of a web request in a web server, simply
|
284
|
+
because it will start a new Fiber.
|
285
|
+
|
286
|
+
The equivalent, non-DSL example looks like so:
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
TT.run do
|
290
|
+
client = Turntabler::Client.new(USER, AUTH, :room => ROOM)
|
291
|
+
client.room.dj
|
292
|
+
client.on :user_entered do
|
293
|
+
# ...
|
294
|
+
end
|
295
|
+
end
|
296
|
+
```
|
297
|
+
|
298
|
+
Notice that in this example the syntax is essentially the same except that we're
|
299
|
+
one level out and need to interact directly with the Turntabler::Client instance
|
300
|
+
itself.
|
301
|
+
|
302
|
+
### Web Server Usage
|
303
|
+
|
304
|
+
You'll notice that in many places in the documentation, `Turntabler.run` or `TT.run`
|
305
|
+
is used to start running a block of code for interacting with the API. This is
|
306
|
+
done in order to ensure that the block of code is being run with a running
|
307
|
+
EventMachine and within a non-root Fiber.
|
308
|
+
|
309
|
+
When turntabler is being used as part of a web server or anything else that's
|
310
|
+
already running EventMachine and already executing code within a non-root Fiber
|
311
|
+
(such as the rainbows web server) you *should not* using the `run` API. Instead
|
312
|
+
you can just run your block like normal:
|
313
|
+
|
314
|
+
```ruby
|
315
|
+
client = Turntabler::Client.new(USER, AUTH, :room => ROOM)
|
316
|
+
songs = client.user.playlist.songs
|
317
|
+
# ...
|
318
|
+
```
|
319
|
+
|
320
|
+
### Bot Usage
|
321
|
+
|
322
|
+
If you're using turntabler in order to build a bot, the primary thing to keep
|
323
|
+
in mind is how to handle connection loss. This can occur as a result of a lost
|
324
|
+
internet connection or even just Turntable forcefully closing a socket for unknown
|
325
|
+
reasons. To protect against this, you can configure turntabler to automatically
|
326
|
+
keep attempting to re-open a connection when it's been closed.
|
327
|
+
|
328
|
+
For example:
|
329
|
+
|
330
|
+
```ruby
|
331
|
+
TT.run(USER, AUTH, :room => ROOM, :reconnect => true, :reconnect_wait => 60) do
|
332
|
+
# ...
|
333
|
+
end
|
334
|
+
```
|
335
|
+
|
336
|
+
In this example, turntabler will automatically attempt to reconnect if the socket
|
337
|
+
is ever closed by reasons other than you closing it yourself. However, rather
|
338
|
+
than constantly trying to hit Turntable's servers you can configuring a reconnect
|
339
|
+
wait timeout that will cause turntabler to wait a certain number of seconds before
|
340
|
+
attempting to open a connection. This will continue to happen until the connection
|
341
|
+
is successful. If you were previously in a room, this will also automatically
|
342
|
+
enter you into the room. However, it will *not* put you back into the DJ spot.
|
343
|
+
|
344
|
+
## Testing
|
345
|
+
|
346
|
+
To run the core test suite:
|
347
|
+
|
348
|
+
```bash
|
349
|
+
bundle install
|
350
|
+
bundle exec rspec
|
351
|
+
```
|
352
|
+
|
353
|
+
## Caveats
|
354
|
+
|
355
|
+
The following caveats should be noted when using turntabler:
|
356
|
+
|
357
|
+
* Since this library uses EventMachine / Fibers it will only be compatible with
|
358
|
+
web servers that support those technology. Examples of such web servers include:
|
359
|
+
* [Thin](http://code.macournoyer.com/thin/)
|
360
|
+
* [Rainbows](http://rainbows.rubyforge.org/)
|
361
|
+
* [Goliath](http://postrank-labs.github.com/goliath/)
|
362
|
+
* This is *not* an official library and so Turntable may make changes to its API
|
363
|
+
that causes this to break. Hopefully we can build a community that can quickly
|
364
|
+
react and provide fixes to those changes.
|
365
|
+
|
366
|
+
## Things to do
|
367
|
+
|
368
|
+
* Add test coverage
|
369
|
+
* Expand on README and examples
|
370
|
+
|
371
|
+
## Contributions
|
372
|
+
|
373
|
+
The largest contribution for this library is the reference material provided by
|
374
|
+
Alain Gilbert's [Turntable-API](https://github.com/alaingilbert/Turntable-API)
|
375
|
+
library. He provided much of the legwork to get understand how Turntable.FM's
|
376
|
+
API works and made it much easier to bring a Ruby persperctive to it.
|
377
|
+
|
378
|
+
## Dependencies
|
379
|
+
|
380
|
+
* Ruby 1.9.3 or later
|
381
|
+
* [faye-websocket-ruby](https://github.com/faye/faye-websocket-ruby)
|
382
|
+
* [em-http-request](https://github.com/igrigorik/em-http-request)
|
383
|
+
* [em-synchrony](https://github.com/igrigorik/em-synchrony)
|
data/Rakefile
ADDED
data/examples/Gemfile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://www.rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.2)
|
5
|
+
cookiejar (0.3.0)
|
6
|
+
em-http-request (1.0.3)
|
7
|
+
addressable (>= 2.2.3)
|
8
|
+
cookiejar
|
9
|
+
em-socksify
|
10
|
+
eventmachine (>= 1.0.0.beta.4)
|
11
|
+
http_parser.rb (>= 0.5.3)
|
12
|
+
em-socksify (0.2.1)
|
13
|
+
eventmachine (>= 1.0.0.beta.4)
|
14
|
+
em-synchrony (1.0.2)
|
15
|
+
eventmachine (>= 1.0.0.beta.1)
|
16
|
+
eventmachine (1.0.0)
|
17
|
+
faye-websocket (0.4.6)
|
18
|
+
eventmachine (>= 0.12.0)
|
19
|
+
http_parser.rb (0.5.3)
|
20
|
+
turntabler (0.0.1)
|
21
|
+
em-http-request
|
22
|
+
em-synchrony
|
23
|
+
faye-websocket
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
turntabler
|
data/examples/autobop.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Each time a a new song starts, vote it up
|
3
|
+
require 'turntabler'
|
4
|
+
|
5
|
+
AUTH = ENV['AUTH'] # 'auth+live+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
6
|
+
USER = ENV['USER'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
|
+
|
9
|
+
TT.run(USER, AUTH, :room => ROOM) do
|
10
|
+
on :song_started do |song|
|
11
|
+
song.vote
|
12
|
+
end
|
13
|
+
end
|
data/examples/autofan.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Fan users who enter the room
|
3
|
+
require 'turntabler'
|
4
|
+
|
5
|
+
AUTH = ENV['AUTH'] # 'auth+live+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
6
|
+
USER = ENV['USER'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
|
+
|
9
|
+
TT.run(USER, AUTH, :room => ROOM) do
|
10
|
+
on :user_entered do |user|
|
11
|
+
user.become_fan
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Boot users who are on a blacklist
|
3
|
+
require 'turntabler'
|
4
|
+
|
5
|
+
AUTH = ENV['AUTH'] # 'auth+live+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
6
|
+
USER = ENV['USER'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
|
+
|
9
|
+
# List of blacklisted user ids
|
10
|
+
blacklist = ['xxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxx']
|
11
|
+
|
12
|
+
TT.run(USER, AUTH, :room => ROOM) do
|
13
|
+
on :user_entered do |user|
|
14
|
+
user.boot('You are on the blacklist.') if blacklist.include?(user.id)
|
15
|
+
end
|
16
|
+
end
|
data/examples/bop.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Vote up a song when someone says "bop" in the chat
|
3
|
+
require 'turntabler'
|
4
|
+
|
5
|
+
AUTH = ENV['AUTH'] # 'auth+live+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
6
|
+
USER = ENV['USER'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
|
+
|
9
|
+
Turntabler.run(USER, AUTH, :room => ROOM) do
|
10
|
+
on :user_spoke do |message|
|
11
|
+
if message.text =~ /bop/
|
12
|
+
client.room.current_song.vote
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Vote up a song when 2 people say "bop" in the chat
|
3
|
+
require 'turntabler'
|
4
|
+
|
5
|
+
AUTH = ENV['AUTH'] # 'auth+live+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
6
|
+
USER = ENV['USER'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
|
+
|
9
|
+
bops_count = 0
|
10
|
+
|
11
|
+
Turntabler.run(USER, AUTH, :room => ROOM) do
|
12
|
+
on :user_spoke do |message|
|
13
|
+
bops_count += 1 if message.text =~ /bop/
|
14
|
+
room.current_song.vote if bops_count == 2
|
15
|
+
end
|
16
|
+
|
17
|
+
on :song_started do |song|
|
18
|
+
bops_count = 0
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Response to users who say "/hello" in the chat
|
3
|
+
require 'turntabler'
|
4
|
+
|
5
|
+
AUTH = ENV['AUTH'] # 'auth+live+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
6
|
+
USER = ENV['USER'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
|
+
|
9
|
+
TT.run(USER, AUTH, :room => ROOM) do
|
10
|
+
on :user_spoke do |message|
|
11
|
+
# Respond to "/hello" command
|
12
|
+
if (message.text =~ /^\/hello$/)
|
13
|
+
client.user.say("Hey! How are you @#{message.sender.name}?")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/examples/modlist.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Moderator commands
|
3
|
+
require 'turntabler'
|
4
|
+
|
5
|
+
AUTH = ENV['AUTH'] # 'auth+live+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
6
|
+
USER = ENV['USER'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
|
+
|
9
|
+
# List of moderator ids
|
10
|
+
moderator_ids = ['xxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxx']
|
11
|
+
|
12
|
+
TT.run(USER, AUTH, :room => ROOM) do
|
13
|
+
on :user_spoke do |message|
|
14
|
+
# Response to "/mod" command
|
15
|
+
if moderator_ids.include?(message.sender.id) && message.text =~ /^\/mod$/
|
16
|
+
user.say("Yo #{message.sender.name}, it looks like you are a bot moderator!")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/examples/switch.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# On/Off bot switch
|
3
|
+
require 'turntabler'
|
4
|
+
|
5
|
+
AUTH = ENV['AUTH'] # 'auth+live+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
6
|
+
USER = ENV['USER'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
|
+
|
9
|
+
# Bot is on by default
|
10
|
+
is_on = true
|
11
|
+
|
12
|
+
TT.run(USER, AUTH, :room => ROOM) do
|
13
|
+
on :user_spoke do |message|
|
14
|
+
if is_on
|
15
|
+
# The bot is on
|
16
|
+
case message.text
|
17
|
+
when /^\/status$/
|
18
|
+
user.say 'The bot is currently turned on.'
|
19
|
+
when /^\/off$/
|
20
|
+
user.say 'The bot is now turned off.'
|
21
|
+
is_on = false
|
22
|
+
when /^\/hello$/
|
23
|
+
# Add other logic here for when the bot is turned on. For example:
|
24
|
+
# Respond to "/hello" command
|
25
|
+
user.say "Hey! How are you #{message.sender.name}?"
|
26
|
+
end
|
27
|
+
else
|
28
|
+
# The bot is off
|
29
|
+
case message.text
|
30
|
+
when /^\/status$/
|
31
|
+
user.say 'The bot is currently turned on.'
|
32
|
+
when /^\/on$/
|
33
|
+
user.say 'The bot is now turned off.'
|
34
|
+
is_on = true
|
35
|
+
end
|
36
|
+
|
37
|
+
# Add other logic here for when the bot is turned off
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|