discord_bot 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2806d9da6b3c0ec3c3c0d1d273df54290a2559607bf8dbf82b4a7d0505ccfe8e
4
- data.tar.gz: 969edb53e2cfbb1e10256d7f329a9f7f460468f40f365e93865290c5e29f5f37
3
+ metadata.gz: 29a2e95ced84579ca1f268e2c44a9d6e92037de5f9506b1c0732da2517bce630
4
+ data.tar.gz: fda641bd3d17d0ccff55ae85fa820755dfd06e4d6627a41d1d1435455dbaa4bc
5
5
  SHA512:
6
- metadata.gz: 16a686cce1133bb197c2223a8a1507698b004354bd3ddfb45e68171d7aba20bb5038150c5fd73618f3a22b508be79e063beb221b22d4fd877db4727648e3a2ac
7
- data.tar.gz: e4ac1c2666daeed9cfc55a1f212a9b3a8a24a03ab10189314759c19062e639f6d9c5ef080b20dabc39e48cf3e6b1a2dc3a86022102ded9c08037d4bdbfb1860c
6
+ metadata.gz: 882b73b5df8bd175744a92f1b4eba83be1307156a1c68f844a79e2a025e2cefcd2723e973f0ff1273455737f3e8f3a8faccf24e98814e80cd89a3f7e71acbda5
7
+ data.tar.gz: be6094f560695e59407837376858c6aca7c18da2e17aaea7ac33417fd27bbd16938edaf318b8913a9eb23795a091b0e3f5ed4d446a5d0518ae173cb16cc92b25
data/lib/discord_bot.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative 'discord_bot/version'
2
+ require_relative 'discord_bot/client'
2
3
 
3
4
  # Base module
4
5
  module DiscordBot
@@ -0,0 +1,32 @@
1
+ require 'httparty'
2
+ require_relative 'client/guilds/members'
3
+ require_relative 'client/guilds/channels'
4
+ require_relative 'client/channels/channel'
5
+ require_relative 'client/channels/create_message'
6
+ require_relative 'client/channels/create_webhook'
7
+ require_relative 'client/webhooks/execute'
8
+ require_relative 'client/users/create_channel'
9
+
10
+ module DiscordBot
11
+ # Client library
12
+ class Client
13
+ include HTTParty
14
+ include DiscordBot::Client::Guilds::Members
15
+ include DiscordBot::Client::Guilds::Channels
16
+ include DiscordBot::Client::Channels::Channel
17
+ include DiscordBot::Client::Channels::CreateMessage
18
+ include DiscordBot::Client::Channels::CreateWebhook
19
+ include DiscordBot::Client::Webhooks::Execute
20
+ include DiscordBot::Client::Users::CreateChannel
21
+
22
+ base_uri 'https://discordapp.com/api'
23
+ format :json
24
+
25
+ attr_reader :bot_token, :user_agent
26
+
27
+ def initialize(bot_token:)
28
+ @bot_token = bot_token
29
+ @user_agent = "ComConBot #{DiscordBot::VERSION}"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,17 @@
1
+ module DiscordBot
2
+ class Client
3
+ # Channel module
4
+ module Channels
5
+ # Message module
6
+ module Channel
7
+ # Get channel
8
+ def get_channel(channel_id:)
9
+ # define params for request
10
+ headers = { 'Content-Type' => 'application/json', 'Authorization' => "Bot #{bot_token}", 'User-Agent' => user_agent }
11
+ # make request
12
+ self.class.get("/channels/#{channel_id}", query: {}, headers: headers).parsed_response
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module DiscordBot
2
+ class Client
3
+ # Channel module
4
+ module Channels
5
+ # Message module
6
+ module CreateMessage
7
+ # Create message to channel
8
+ def create_channel_message(channel_id:, content:)
9
+ # define params for request
10
+ body = { 'content' => content }.to_json
11
+ headers = { 'Content-Type' => 'application/json', 'Authorization' => "Bot #{bot_token}", 'User-Agent' => user_agent }
12
+ # make request
13
+ self.class.post("/channels/#{channel_id}/messages", body: body, headers: headers).parsed_response
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module DiscordBot
2
+ class Client
3
+ # Channel module
4
+ module Channels
5
+ # Message module
6
+ module CreateWebhook
7
+ # Create webhook to channel
8
+ def create_channel_webhook(channel_id:, name:)
9
+ # define params for request
10
+ body = { 'name' => name }.to_json
11
+ headers = { 'Content-Type' => 'application/json', 'Authorization' => "Bot #{bot_token}", 'User-Agent' => user_agent }
12
+ # make request
13
+ self.class.post("/channels/#{channel_id}/webhooks", body: body, headers: headers).parsed_response
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module DiscordBot
2
+ class Client
3
+ # Guild module
4
+ module Guilds
5
+ # Members module
6
+ module Channels
7
+ # Get guild channels list
8
+ def get_guild_channels(guild_id:)
9
+ # define params for request
10
+ headers = { 'Content-Type' => 'application/json', 'Authorization' => "Bot #{bot_token}", 'User-Agent' => user_agent }
11
+ # make request
12
+ self.class.get("/guilds/#{guild_id}/channels", query: {}, headers: headers).parsed_response
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module DiscordBot
2
+ class Client
3
+ # Guild module
4
+ module Guilds
5
+ # Members module
6
+ module Members
7
+ # Get guild members list
8
+ def get_guild_members(guild_id:)
9
+ # define params for request
10
+ headers = { 'Content-Type' => 'application/json', 'Authorization' => "Bot #{bot_token}", 'User-Agent' => user_agent }
11
+ # make request
12
+ self.class.get("/guilds/#{guild_id}/members", query: {}, headers: headers).parsed_response
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module DiscordBot
2
+ class Client
3
+ # Channel module
4
+ module Users
5
+ # Message module
6
+ module CreateChannel
7
+ # Create message to channel
8
+ def create_user_channel(recipient_id:)
9
+ # define params for request
10
+ body = { 'recipient_id' => recipient_id }.to_json
11
+ headers = { 'Content-Type' => 'application/json', 'Authorization' => "Bot #{bot_token}", 'User-Agent' => user_agent }
12
+ # make request
13
+ self.class.post('/users/@me/channels', body: body, headers: headers).parsed_response
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module DiscordBot
2
+ class Client
3
+ # Webhooks module
4
+ module Webhooks
5
+ # Execute module
6
+ module Execute
7
+ # Create webhook to channel
8
+ def execute_webhook(webhook_id:, webhook_token:, content:)
9
+ # define params for request
10
+ body = { 'content' => content }.to_json
11
+ headers = { 'Content-Type' => 'application/json', 'Authorization' => "Bot #{bot_token}", 'User-Agent' => user_agent }
12
+ # make request
13
+ self.class.post("/webhooks/#{webhook_id}/#{webhook_token}", body: body, headers: headers).parsed_response
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module DiscordBot
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discord_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Bogdanov
@@ -87,6 +87,14 @@ files:
87
87
  - bin/setup
88
88
  - discord_bot.gemspec
89
89
  - lib/discord_bot.rb
90
+ - lib/discord_bot/client.rb
91
+ - lib/discord_bot/client/channels/channel.rb
92
+ - lib/discord_bot/client/channels/create_message.rb
93
+ - lib/discord_bot/client/channels/create_webhook.rb
94
+ - lib/discord_bot/client/guilds/channels.rb
95
+ - lib/discord_bot/client/guilds/members.rb
96
+ - lib/discord_bot/client/users/create_channel.rb
97
+ - lib/discord_bot/client/webhooks/execute.rb
90
98
  - lib/discord_bot/version.rb
91
99
  homepage: https://github.com/kortirso/discord_bot
92
100
  licenses: