discordrb 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of discordrb might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bef7f70f8f9ba4e684a19ddd8545909f1e81b609
4
- data.tar.gz: 6d8691f3e57f0bff79958ae09cf61aa1b23d6eca
3
+ metadata.gz: e7a553fc163491c4a828dfb1b0ae8eceea31002b
4
+ data.tar.gz: f03090190ede187097ab7c6522e4c46bcab7a76b
5
5
  SHA512:
6
- metadata.gz: e18a5a8ccd4f31162d5407e69061dace62500b5a620140c7354f325978c61d9a2298d2e9312f855f7ea468f967a93919f55f9c72477357460d17f40932640da4
7
- data.tar.gz: 0579638f1f91114752bdaca6afdc2465add207ad7bca65d13c90a38f7da6681ce9a08ece963298304180f4a6dcf05ddb6af512285eb5045571348be31c578139
6
+ metadata.gz: 23c01ad25109395e1d09ff9ca80d7fc84136ddc265d76f3c74cd6e7cf038ceacfffb61eb30ff856ed8abcac6df60eea5d9de07fb85387bd7304a1b174b24c149
7
+ data.tar.gz: aa0d36cc705bab5ac583a3f9a2317e20189e862832e49b76838e81c0106d39c24fba15e70ecda3ef4185ce998ff7232654451e392a3ded38178b95d3edd9a201
@@ -0,0 +1,40 @@
1
+ # This bot has various commands that show off CommandBot.
2
+
3
+ require 'discordrb'
4
+
5
+ bot = Discordrb::Commands::CommandBot.new "email@example.com", "hunter2", "!"
6
+
7
+ bot.command :user do |event|
8
+ event.user.name
9
+ end
10
+
11
+ bot.command :bold do |event, *args|
12
+ "**#{args.join(' ')}**"
13
+ end
14
+
15
+ bot.command :italic do |event, *args|
16
+ "**#{args.join(' ')}**"
17
+ end
18
+
19
+ bot.command(:join, permission_level: 1, chain_usable: false) do |event, invite|
20
+ event.bot.join invite
21
+ end
22
+
23
+ bot.command(:random, min_args: 0, max_args: 2, description: "Generates a random number between 0 and 1, 0 and max or min and max.", usage: "random [min/max] [max]") do |event, min, max|
24
+ if max
25
+ rand(min..max)
26
+ elsif min
27
+ rand(0..min)
28
+ else
29
+ rand
30
+ end
31
+ end
32
+
33
+ bot.command :long do |event|
34
+ event << "This is a long message."
35
+ event << "It has multiple lines that are each sent by doing `event << line`."
36
+ event << "This is an easy way to do such long messages, or to create lines that should only be sent conditionally."
37
+ event << "Anyway, have a nice day."
38
+ end
39
+
40
+ bot.run
data/lib/discordrb/api.rb CHANGED
@@ -100,6 +100,14 @@ module Discordrb::API
100
100
  )
101
101
  end
102
102
 
103
+ # Resolve an invite
104
+ def resolve_invite(token, code)
105
+ RestClient.get(
106
+ "#{APIBASE}/invite/#{code}",
107
+ Authorization: token
108
+ )
109
+ end
110
+
103
111
  # Create a private channel
104
112
  def create_private(token, bot_user_id, user_id)
105
113
  RestClient.post(
@@ -159,10 +167,10 @@ module Discordrb::API
159
167
  end
160
168
 
161
169
  # Send a file as a message to a channel
162
- def send_file(token, channel_id, file, filename = 'filename')
170
+ def send_file(token, channel_id, file)
163
171
  RestClient.post(
164
172
  "#{APIBASE}/channels/#{channel_id}/messages",
165
- (filename.to_sym) => file,
173
+ {:file => file},
166
174
  Authorization: token
167
175
  )
168
176
  end
data/lib/discordrb/bot.rb CHANGED
@@ -91,7 +91,8 @@ module Discordrb
91
91
 
92
92
  def join(invite)
93
93
  invite = invite[invite.rindex('/')+1..-1] if invite.start_with?('http') || invite.start_with?('discord.gg')
94
- API.join_server(@token, invite)
94
+ resolved = JSON.parse(API.resolve_invite(@token, invite))['code']
95
+ API.join_server(@token, resolved)
95
96
  end
96
97
 
97
98
  def user(id)
@@ -111,6 +112,10 @@ module Discordrb
111
112
  API.send_message(@token, channel_id, content)
112
113
  end
113
114
 
115
+ def send_file(channel_id, file)
116
+ API.send_file(@token, channel_id, file)
117
+ end
118
+
114
119
  def debug=(debug)
115
120
  @debug = debug
116
121
  end
@@ -177,6 +177,10 @@ module Discordrb
177
177
  @bot.send_message(@id, content)
178
178
  end
179
179
 
180
+ def send_file(file)
181
+ @bot.send_file(@id, file)
182
+ end
183
+
180
184
  def update_from(other)
181
185
  @topic = other.topic
182
186
  @name = other.name
@@ -1,3 +1,3 @@
1
1
  module Discordrb
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discordrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - meew0
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-31 00:00:00.000000000 Z
11
+ date: 2015-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faye-websocket
@@ -96,6 +96,7 @@ files:
96
96
  - bin/console
97
97
  - bin/setup
98
98
  - discordrb.gemspec
99
+ - examples/commands.rb
99
100
  - examples/ping.rb
100
101
  - examples/pm.rb
101
102
  - lib/discordrb.rb