-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.rb
executable file
·71 lines (61 loc) · 2.15 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env ruby
require 'discordrb'
require 'fullwidth'
require 'yaml'
require 'figlet'
require 'cowsay'
require 'fortune_gem'
require_relative 'lib/patches'
require_relative 'lib/utilities'
require_relative 'lib/fun'
require_relative 'lib/admin'
$config = YAML.load_file('config.yaml')
$pasta = YAML.load_file('pasta.yaml')
# Figlet initialization
$figlet = Figlet::Typesetter.new(Figlet::Font.new("fonts/#{$config['figletFont']}.flf"))
$bot = Discordrb::Commands::CommandBot.new(token: $config['token'],
prefix: $config['prefix'],
advanced_functionality: true,
spaces_allowed: true,
chain_delimiter: '|',
previous: '-',
ignore_bots: true,
command_doesnt_exist_message: 'zsh: command not found')
$bot.include! Utilities
$bot.include! Fun
$bot.include! Admin
$user_type = 'normal'
$bot.command :sudo do |event, *args|
if event.author.roles.select { |role| role.id == $config['sudoersRole'] }.empty?
event.channel.send_message("<@#{event.author.id}> is not in the sudoers file. This incident will be reported.")
else
run_command = args[0]
args.slice!(0)
$user_type = 'sudoer'
$bot.execute_command(run_command.to_sym, event, args)
$user_type = 'normal'
break # Avoids garbage messages
end
end
$pasta.keys.each do |pasta| # Slightly improved
$bot.command pasta.to_sym do |event, *args|
catch :RegexError do
sed = []
args.each { |string| string.split('/').each { |subs| sed.push(subs) } }
$pasta = YAML.load_file('pasta.yaml') # Required to reload the pastas
message = $pasta[pasta]
unless sed.empty?
sed.each_slice(2) do |match, replace|
begin
message.gsub!(/#{match}/i, replace || '')
rescue RegexpError
event.channel.send_message('Error: Invalid Regex')
throw :RegexError
end
end
end
message
end
end
end
$bot.run