-
Notifications
You must be signed in to change notification settings - Fork 2
/
classes.rb
152 lines (133 loc) · 3.3 KB
/
classes.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
require 'rmagick'
require 'open-uri'
require 'mp3info'
require 'youtube-dl.rb'
include Magick
class String
def numeric?
begin
Integer(self)
rescue
false # not numeric
else
true # numeric
end
end
end
class Object
def blank?
if self.nil? || self.empty?
true # no value or nil value
else
false # numeric
end
end
end
def reformat_wrapped(s, width)
lines = []
line = ''
s.split(/\s+/).each do |word|
if line.size + word.size >= width
lines << line
line = word
elsif line.empty?
line = word
else
line << ' ' << word
end
end
lines << line if line
return lines.join "\n"
end
def createSpoiler(text, text2, messageid)
gc = Magick::Draw.new {
self.stroke = 'transparent'
self.font = 'helvetica'
self.pointsize = 16
}
if text2.length >= text.length
metrics = gc.get_multiline_type_metrics(text2)
width = metrics.width + 40
height = metrics.height
elsif text.length > text2.length
metrics = gc.get_multiline_type_metrics(text)
width = metrics.width + 40
height = metrics.height
end
spoiler = Magick::Image.new(width, height) {
self.background_color = '#36393E'
}
spoilerText = Draw.new
spoiler.annotate(spoilerText, 0,0,0,0, text){
self.gravity = Magick::CenterGravity
self.pointsize = 16
self.fill = 'white'
}
spoiler2 = Magick::Image.new(width, height) {
self.background_color = '#36393E'
}
spoilerText2 = Draw.new
spoiler2.annotate(spoilerText2, 0,0,0,0, text2){
self.gravity = Magick::NorthWestGravity
self.pointsize = 16
#txt.stroke = ‘#000000’
self.fill = 'white'
}
gif = ImageList.new()
gif << spoiler
gif << spoiler2
gif.iterations = 1
gif.format = 'gif'
gif.write("images/spoiler/#{messageid}.gif")
end
def manageMusic(server)
music = "data/#{server}/music"
if File.exists?(music)
Dir.foreach(music) do |file|
if ((file.to_s != ".") and (file.to_s != ".."))
File.delete("#{music}/#{file}")
end
end
elsif !File.exists?(music)
FileUtils.mkpath music unless File.exist?(music)
end
end
def addYoutube(server, message, url)
options = {
format: 'bestaudio',
extract_audio: true,
audio_format: 'mp3',
output: "data/#{server}/music/#{message}.%(ext)s"
}
YoutubeDL.download url, options
end
def pollLoop(server)
Thread::abort_on_exception = true
pollthread = Thread.new do
db = SQLite3::Database.new "db/#{server}.db"
time = db.execute('SELECT poll_time FROM poll WHERE id=1')[0][0].to_i
channel = db.execute('SELECT channel_id FROM poll WHERE id=1')[0][0].to_i
loop do
break_loop = false
x = db.execute('SELECT elapsed_time FROM poll WHERE id = 1')[0][0]
if x <= time
db.execute('UPDATE poll SET elapsed_time = elapsed_time + 1 WHERE id = 1')
sleep 1
else
break_loop = true
end
break if break_loop
end
winner = 'Poll Results:' + "\n\n"
winners = db.execute(
'SELECT * FROM poll WHERE votes = (SELECT MAX(votes) FROM poll)'
)
winners.each do |w|
winner << w[3] + ': with ' + w[4].to_s + ' votes!' + "\n"
end
BruhBot.bot.send_message(channel, winner)
db.execute('DELETE FROM poll')
db.execute('DELETE FROM poll_voters')
Thread.exit
end
end