commandrb 0.2
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 +7 -0
- data/lib/commandrb.rb +132 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f462953be452407d78e853eccd4e827d05f9e4b7
|
4
|
+
data.tar.gz: 6ad31c9bb61be35936eb43c8cce2c484e315d0b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce1404c5e005bcfba31fa17e6a7d9693b7bac26691e40d869ff5cad4500ab3cd230487af2879cc53684d2c4a033b85f79dfc4e38bd9bb8cf5cacfecaa96c7d44
|
7
|
+
data.tar.gz: 04f8139e8bd4154881a86c8b5ce82ce753b9881e7e211909e69950f27419a5ae9d267cfdf4100b04bc3e75e6f41f2105d3cf57d23d42e6dafa0f583668e408ff
|
data/lib/commandrb.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
class CommandrbBot
|
2
|
+
attr_accessor :commands
|
3
|
+
attr_accessor :prefixes
|
4
|
+
attr_accessor :bot
|
5
|
+
attr_accessor :prefix_type
|
6
|
+
attr_accessor :owners
|
7
|
+
attr_accessor :typing_default
|
8
|
+
|
9
|
+
def initialize(init_hash)
|
10
|
+
|
11
|
+
@commands = {}
|
12
|
+
@prefixes = []
|
13
|
+
@config = init_hash
|
14
|
+
|
15
|
+
@config[:prefix_type] = 'rescue' if @config[:prefix_type].nil?
|
16
|
+
@config[:typing_default] = false if @config[:typing_default].nil?
|
17
|
+
|
18
|
+
if @config[:token].nil? or init_hash[:token] == ''
|
19
|
+
puts 'No token supplied in init hash!'
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
|
23
|
+
init_parse_self = init_hash[:parse_self] rescue nil
|
24
|
+
init_type = init_hash[:type] rescue :bot
|
25
|
+
|
26
|
+
if init_type == :bot
|
27
|
+
if init_hash[:client_id].nil?
|
28
|
+
puts 'No client ID or invalid client ID supplied in init hash!'
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
@prefixes = []
|
34
|
+
|
35
|
+
@config[:owners] = init_hash[:owners]
|
36
|
+
puts 'Invalid owners supplied in init hash!'
|
37
|
+
|
38
|
+
@prefixes = init_hash[:prefixes]
|
39
|
+
puts 'Invalid prefixes supplied in init hash!'
|
40
|
+
|
41
|
+
@bot = Discordrb::Bot.new(
|
42
|
+
token: @config[:token],
|
43
|
+
client_id: @config[:client_id],
|
44
|
+
parse_self: init_parse_self,
|
45
|
+
type: init_type
|
46
|
+
)
|
47
|
+
|
48
|
+
unless init_hash[:ready].nil?
|
49
|
+
@bot.ready do |event|
|
50
|
+
init_hash[:ready].call(event)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_command(name, attributes = {})
|
55
|
+
@commands[name.to_sym] = attributes
|
56
|
+
end
|
57
|
+
|
58
|
+
# Command processing
|
59
|
+
@bot.message do |event|
|
60
|
+
@continue = false
|
61
|
+
@prefixes.each { |prefix|
|
62
|
+
if event.message.content.start_with?(prefix)
|
63
|
+
|
64
|
+
@commands.each { | key, command |
|
65
|
+
if command[:triggers].nil?
|
66
|
+
triggers = [key.to_s]
|
67
|
+
else
|
68
|
+
triggers = command[:triggers]
|
69
|
+
end
|
70
|
+
|
71
|
+
triggers.each { |trigger|
|
72
|
+
@activator = prefix + trigger
|
73
|
+
if event.message.content.start_with?(@activator)
|
74
|
+
puts '@activator picked.'
|
75
|
+
@continue = true
|
76
|
+
break
|
77
|
+
else
|
78
|
+
next
|
79
|
+
end
|
80
|
+
}
|
81
|
+
|
82
|
+
next unless @continue
|
83
|
+
|
84
|
+
# Command flag defaults
|
85
|
+
command[:catch_errors] = @config[:catch_errors] if command[:catch_errors].nil?
|
86
|
+
command[:owners_only] = false if command[:owners_only].nil?
|
87
|
+
command[:max_args] = 2000 if command[:max_args].nil?
|
88
|
+
command[:server_only] = false if command[:server_only].nil?
|
89
|
+
command[:typing] = @config[:typing_default] if command[:typing_default].nil?
|
90
|
+
|
91
|
+
if command[:owners_only]
|
92
|
+
unless YuukiBot.config['owners'].include?(event.user.id)
|
93
|
+
event.respond('❌ You don\'t have permission for that!')
|
94
|
+
break
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
if command[:server_only] && event.channel.private?
|
99
|
+
event.respond('❌ This command will only work in servers!')
|
100
|
+
next
|
101
|
+
end
|
102
|
+
|
103
|
+
if (event.user.bot_account? && command[:parse_bots] == false) || (event.user.bot_account? && @parse_bots == false)
|
104
|
+
next
|
105
|
+
end
|
106
|
+
|
107
|
+
event.channel.start_typing if command[:typing]
|
108
|
+
|
109
|
+
args = event.message.content.slice!(@activator.length, event.message.content.size)
|
110
|
+
args = args.split(' ')
|
111
|
+
|
112
|
+
if args.length > command[:max_args]
|
113
|
+
event.respond("❌ Too many arguments! \nMax arguments: `#{command[:max_args]}`")
|
114
|
+
next
|
115
|
+
end
|
116
|
+
if !command[:catch_errors] || @config['catch_errors']
|
117
|
+
command[:code].call(event, args)
|
118
|
+
else
|
119
|
+
begin
|
120
|
+
command[:code].call(event, args)
|
121
|
+
rescue Exception => e
|
122
|
+
event.respond("❌ An error has occured!! ```ruby\n#{e}```Please contact the bot owner with the above message for assistance.")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
break
|
126
|
+
}
|
127
|
+
break
|
128
|
+
end
|
129
|
+
}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: commandrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seriel Shirogane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A customisable and easy to use Commands System for Discordrb.
|
14
|
+
email: seriel@fl0.co
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/commandrb.rb
|
20
|
+
homepage: https://github.com/Seriell/commandrb
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.6.11
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Commandrb
|
44
|
+
test_files: []
|