discord_bot 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/discord_bot.rb +1 -0
- data/lib/discord_bot/client.rb +32 -0
- data/lib/discord_bot/client/channels/channel.rb +17 -0
- data/lib/discord_bot/client/channels/create_message.rb +18 -0
- data/lib/discord_bot/client/channels/create_webhook.rb +18 -0
- data/lib/discord_bot/client/guilds/channels.rb +17 -0
- data/lib/discord_bot/client/guilds/members.rb +17 -0
- data/lib/discord_bot/client/users/create_channel.rb +18 -0
- data/lib/discord_bot/client/webhooks/execute.rb +18 -0
- data/lib/discord_bot/version.rb +1 -1
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29a2e95ced84579ca1f268e2c44a9d6e92037de5f9506b1c0732da2517bce630
|
4
|
+
data.tar.gz: fda641bd3d17d0ccff55ae85fa820755dfd06e4d6627a41d1d1435455dbaa4bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 882b73b5df8bd175744a92f1b4eba83be1307156a1c68f844a79e2a025e2cefcd2723e973f0ff1273455737f3e8f3a8faccf24e98814e80cd89a3f7e71acbda5
|
7
|
+
data.tar.gz: be6094f560695e59407837376858c6aca7c18da2e17aaea7ac33417fd27bbd16938edaf318b8913a9eb23795a091b0e3f5ed4d446a5d0518ae173cb16cc92b25
|
data/lib/discord_bot.rb
CHANGED
@@ -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
|
data/lib/discord_bot/version.rb
CHANGED
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.
|
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:
|