-
Notifications
You must be signed in to change notification settings - Fork 1
/
Wakstuff.rb
554 lines (527 loc) · 20.2 KB
/
Wakstuff.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# by Elio-Centrique, All right Reserved 2019
# frozen_string_literal: false
# encoding: UTF-8
# This bot has various commands that show off CommandBot.
require 'json'
require 'discordrb'
require 'discordrb/webhooks'
require 'i18n'
require "date"
require_relative "Classes/Item.rb"
file = File.read("token.txt")
$token = file.split
I18n.load_path << Dir[File.expand_path("locale") + "/*.yml"]
I18n.default_locale = "en"
$listItemsFR = []
$listItemsEN = []
$exampleSort = [31, 56, 41, 57, 191, 192, 161, 160, 184, 20, 166, 162, 167, 163, 175, 174, 173, 174, 176, 171, 150, 168, 126, 875, 120, 130, 122, 132, 123, 124, 125, 149, 151, 1068, 26, 180, 181, 1050, 1051, 1052, 1053, 1055, 1056, 1060, 1061, 80, 100, 1069, 82, 97, 83, 98, 84, 96, 85, 71, 988, 1062, 1063, 234, 2000, 2001, 2002, 2006, 2008]
def checkLanguage(event)
#check language
id_server = event.server.id
id_found = false
language = ""
File.open("config.txt", "r+") { |file_lang|
file_lang.each_line do |line|
if id_server.to_s == line.split(":")[0]
id_found = true
language = line.split(":")[1]
end
end
if(id_found == false)
language = "en"
file_lang.write(id_server.to_s + ":" + language + "\n")
end
}
language = language.gsub("\n", "")
listItem = nil
(language == "fr") ? listItem = $listItemsFR : listItem = $listItemsEN
I18n.locale = language
return listItem
end
def loadItemList()
puts "Creation of the item list, it could take some times"
fileItem = File.open("JSON/items.json", "r")
jsonItem = JSON.load(fileItem)
fileAction = File.open("JSON/actions.json", "r")
jsonAction = JSON.load(fileAction)
jsonItem.each { |item|
rarityNumber = item['definition']['item']['baseParameters']['rarity']
I18n.locale = "fr"
case rarityNumber
when 1
rarity = I18n.t(:common)
color = 16777215
when 2
rarity = I18n.t(:rare)
color = 65280
when 3
rarity = I18n.t(:mythic)
color = 16750592
when 4
rarity = I18n.t(:legendary)
color = 16776960
when 5
rarity = I18n.t(:relic)
color = 11075839
when 6
rarity = I18n.t(:souvenir)
color = 52991
when 7
rarity = I18n.t(:epic)
color = 16711935
end
tmpStats = []
item['definition']['equipEffects'].each { |bonus|
bonusId = bonus['effect']['definition']['actionId']
jsonAction.each { |action|
if bonusId === action['definition']['id']
m = ""
param = bonus['effect']['definition']['params']
level = item['definition']['item']['level'].to_i
if item['definition']['item']['baseParameters']['itemTypeId'] == 582
level += 50
end
if action['description'] != nil
m = action['description']["fr"].encode('utf-8')
m.gsub! '[~3]?[#1] Maîtrise [#3]:', ""
m.gsub! '[~3]?[#1] Mastery [#3]:', ""
m.gsub! '[~3]?[#1] Résistance [#3]:', ""
m.gsub! '[~3]?[#1] Resistance [#3]:', ""
m.gsub! '[#1]', (param[1].to_i * level + param[0].to_i).to_s
m.gsub! '[#2]', (param[3].to_i * level + param[2].to_i).to_s
m.gsub! '[#3]', (param[5].to_i * level + param[4].to_i).to_s
m.gsub! '[>1]?', ""
m.gsub! '{[>2]?:s}', "s"
m.gsub! '{[>2]?s:}', "s"
m.gsub! '{[=2]?:s}', ""
m.gsub! '{[=2]?s:}', ""
m.gsub! '{[=2]?:}', ""
m.gsub! '[~3]?', ""
m.gsub! "{", ""
m.gsub! "}", ""
m.gsub! '[el1]', I18n.t(:fire)
m.gsub! '[el2]', I18n.t(:water)
m.gsub! '[el3]', I18n.t(:earth)
m.gsub! '[el4]', I18n.t(:air)
tmpStats.push [bonusId,
param[1].to_i * level + param[0].to_i,
param[3].to_i * level + param[2].to_i,
param[5].to_i * level + param[4].to_i,
m
]
end
end
}
}
description = ""
if item['description'] != nil
description = "*" + item['description']["fr"] + "*"
end
sortedStats = []
$exampleSort.each_with_index { |idExample, indexExample|
tmpStats.each { |stat|
if stat[0] == idExample
sortedStats[indexExample] = stat
end
}
}
sortedStats = sortedStats.reject! {|stat| stat.nil? }
(item['title'] != nil) ? title = item['title']["fr"] : title = "undefined"
level = item['definition']['item']['level'].to_i
if item['definition']['item']['baseParameters']['itemTypeId'] == 582
level += 50
end
tmpItem = Item.new(
title,
rarity,
color,
level,
description,
sortedStats,
"https://s.ankama.com/www/static.ankama.com/wakfu/portal/game/item/115/" + item['definition']['item']['graphicParameters']['gfxId'].to_s + ".png"
)
$listItemsFR.push tmpItem
}
jsonItem.each { |item|
rarityNumber = item['definition']['item']['baseParameters']['rarity']
I18n.locale = "en"
case rarityNumber
when 1
rarity = I18n.t(:common)
color = 16777215
when 2
rarity = I18n.t(:rare)
color = 65280
when 3
rarity = I18n.t(:mythic)
color = 16750592
when 4
rarity = I18n.t(:legendary)
color = 16776960
when 5
rarity = I18n.t(:relic)
color = 11075839
when 6
rarity = I18n.t(:souvenir)
color = 52991
when 7
rarity = I18n.t(:epic)
color = 16711935
end
tmpStats = []
item['definition']['equipEffects'].each { |bonus|
bonusId = bonus['effect']['definition']['actionId']
jsonAction.each { |action|
if bonusId === action['definition']['id']
m = ""
param = bonus['effect']['definition']['params']
level = item['definition']['item']['level'].to_i
if item['definition']['item']['baseParameters']['itemTypeId'] == 582
level += 50
end
if action['description'] != nil
m = action['description']["en"].encode('utf-8')
m.gsub! '[~3]?[#1] Maîtrise [#3]:', ""
m.gsub! '[~3]?[#1] Mastery [#3]:', ""
m.gsub! '[~3]?[#1] Résistance [#3]:', ""
m.gsub! '[~3]?[#1] Resistance [#3]:', ""
m.gsub! '[#1]', (param[1].to_i * level + param[0].to_i).to_s
m.gsub! '[#2]', (param[3].to_i * level + param[2].to_i).to_s
m.gsub! '[#3]', (param[5].to_i * level + param[4].to_i).to_s
m.gsub! '[>1]?', ""
m.gsub! '{[>2]?:s}', "s"
m.gsub! '{[>2]?s:}', "s"
m.gsub! '{[=2]?:s}', ""
m.gsub! '{[=2]?s:}', ""
m.gsub! '{[=2]?:}', ""
m.gsub! '[~3]?', ""
m.gsub! "{", ""
m.gsub! "}", ""
m.gsub! '[el1]', I18n.t(:fire)
m.gsub! '[el2]', I18n.t(:water)
m.gsub! '[el3]', I18n.t(:earth)
m.gsub! '[el4]', I18n.t(:air)
tmpStats.push([bonusId,
param[1].to_i * level + param[0].to_i,
param[3].to_i * level + param[2].to_i,
param[5].to_i * level + param[4].to_i,
m
])
end
end
}
}
description = ""
if item['description'] != nil
description = "*" + item['description']["en"] + "*"
end
(item['title'] != nil) ? title = item['title']["en"] : title = "undefined"
sortedStats = []
$exampleSort.each_with_index { |idExample, indexExample|
tmpStats.each { |stat|
if stat[0] == idExample
sortedStats[indexExample] = stat
end
}
}
sortedStats = sortedStats.reject! {|stat| stat.nil? }
level = item['definition']['item']['level'].to_i
if item['definition']['item']['baseParameters']['itemTypeId'] == 582
level += 50
end
tmpItem = Item.new(
title,
rarity,
color,
level,
description,
sortedStats,
"https://s.ankama.com/www/static.ankama.com/wakfu/portal/game/item/115/" + item['definition']['item']['graphicParameters']['gfxId'].to_s + ".png"
)
$listItemsEN.push tmpItem
}
puts "Itemlist finished, enjoy the bot !"
end
loadItemList()
bot = Discordrb::Commands::CommandBot.new token: $token[0], prefix: "w!", advanced_functionality: true
bot.command(:almanax, min_args: 0, max_args: 1, description: I18n.t(:almanaxCommand)) do |event, *args|
if !args
checkLanguage(event)
message = I18n.t(:almanaxEvent)
today = Date.today
compare = Date.new(2019, 11, 21)
difference = (today - compare).to_i
if difference % 5 == 0
message += I18n.t(:prospecting)
elsif difference % 5 == 1
message += I18n.t(:craft)
elsif difference % 5 == 2
message += I18n.t(:XPHarvest)
elsif difference %5 == 3
message += I18n.t(:FarmHarvest)
elsif difference %5 == 4
message += I18n.t(:wisdom)
end
event << event.user.name + I18n.t(:checkDM)
event.user.pm(message)
else
if args[0] == 'ici' || args[0] == 'here'
checkLanguage(event)
message = I18n.t(:almanaxEvent)
today = Date.today
compare = Date.new(2019, 11, 21)
difference = (today - compare).to_i
if difference % 5 == 0
message += I18n.t(:prospecting)
elsif difference % 5 == 1
message += I18n.t(:craft)
elsif difference % 5 == 2
message += I18n.t(:XPHarvest)
elsif difference %5 == 3
message += I18n.t(:FarmHarvest)
elsif difference %5 == 4
message += I18n.t(:wisdom)
event << message
end
else
event << I18n.t(:correctUsage) + "w!almanax [ici/here]"
end
end
end
bot.command(:object, min_args: 2, description: I18n.t(:objectCommand)) do |event, *args|
findObject = false
findRarity = false
moreArgs = ""
level = ""
listItem = checkLanguage(event)
if args.length > 2
moreArgs = args.join(' ')
moreArgs.slice!(args[0] + ' ')
else
moreArgs = args[1]
end
listItem.each { |item|
if moreArgs.downcase === item.name.downcase
findObject = true
messageEmbed = ""
if args[0].downcase == item.rarity.downcase
findRarity = true
event.send_embed do |embed|
embed.title = item.name + " " + I18n.t(:level) + " " + item.level.to_s
embed.description = item.getStatsMessage
embed.color = item.color
embed.add_field(name: "Description: ", value: item.description)
embed.image = Discordrb::Webhooks::EmbedImage.new(url: item.image)
end
end
end
}
if !findObject
event << I18n.t(:noObject)
end
if findObject && !findRarity
event << I18n.t(:noRarity)
end
end
bot.command(:compare, max_args: 4, description: I18n.t(:compareCommand)) do |event, *args|
findObject1 = false
findRarity1 = false
findObject2 = false
findRarity2 = false
item1 = nil
item2 = nil
listItems = checkLanguage(event)
#item 1
listItems.each { |item|
if args[1].downcase === item.name.downcase
findObject1 = true
if args[0].downcase == item.rarity.downcase
findRarity1 = true
item1 = item
end
end
}
if !findObject1
event << args[1] + I18n.t(:noObject)
end
if findObject1 && !findRarity1
event << args[1] + ", " + args[0] + I18n.t(:noRarity)
end
#item 2
listItems.each { |item|
if args[3].downcase === item.name.downcase
findObject2 = true
messageEmbed = ""
if args[2].downcase == item.rarity.downcase
findRarity2 = true
item2 = item
end
end
}
unless findObject2
event << args[3] + I18n.t(:noObject)
end
if findObject2 && !findRarity2
event << args[3] + ", " + args[2] + I18n.t(:noRarity)
end
if findObject1 && findObject2
tabStats1 = []
tabStats2 = []
item1.stats.each { |stat1|
id_found = false
item2.stats.each { |stat2|
if stat1[0] == stat2[0]
id_found = true
if stat1[2] == stat2[2]
tabStats1.push [stat1[0], stat1[1] - stat2[1], 0]
else
tabStats1.push [stat1[0], stat1[1] - stat2[1], stat1[2] - stat2[2]]
end
end
}
if !id_found
tabStats1.push [stat1[0], stat1[1], stat1[2]]
end
}
item2.stats.each { |stat1|
id_found = false
item1.stats.each { |stat2|
if stat1[0] == stat2[0]
id_found = true
if stat1[2] == stat2[2]
tabStats2.push [stat1[0], stat1[1] - stat2[1], 0]
else
tabStats2.push [stat1[0], stat1[1] - stat2[1], stat1[2] - stat2[2]]
end
end
}
if !id_found
tabStats2.push [stat1[0], stat1[1], stat1[2]]
end
}
i = 0
j = 0
tmpMessage1 = ""
tmpMessage2 = ""
item1.stats.each { |stat|
indicator = ""
if tabStats1[i][1] >= 0
indicator = "+"
end
statmessage = stat[4].to_s
statmessage += " (" + indicator.to_s + tabStats1[i][1].to_s + ")"
tmpMessage1 += statmessage + "\n"
i += 1
}
item2.stats.each { |stat|
indicator = ""
if tabStats2[j][1] >= 0
indicator = "+"
end
statmessage = stat[4].to_s
statmessage += " (" + indicator.to_s + tabStats2[j][1].to_s + ")"
if tabStats2[j][2] != 0
statmessage += "(" + tabStats2[j][2].to_s + ")"
end
tmpMessage2 += statmessage + "\n"
j += 1
}
event.send_embed do |embed|
embed.title = I18n.t(:itemVS) + item1.name + " " + item1.rarity + " VS " + item2.name + " " + item2.rarity
embed << Discordrb::Webhooks::EmbedField.new(name: item1.name, value: tmpMessage1, inline: true)
embed << Discordrb::Webhooks::EmbedField.new(name: item2.name, value: tmpMessage2, inline: true)
end
end
end
bot.command(:search, description: I18n.t(:searchCommand)) do |event, *args|
findObject = false
listFound = []
listItem = checkLanguage(event)
listItem.each { |item|
if item.name.downcase.include?(args.join(" ").downcase)
findObject = true
listFound.push(item)
end
}
if !findObject
event << I18n.t(:noObject)
else
if listFound.length == 1
event.send_embed do |embed|
embed.title = listFound[0].name + " " +I18n.t(:level) + " " + listFound[0].level.to_s
embed.description = listFound[0].getStatsMessage
embed.color = listFound[0].color
embed.add_field(name: "Description: ", value: listFound[0].description)
embed.image = Discordrb::Webhooks::EmbedImage.new(url: listFound[0].image)
end
else
description = ""
i = 1
listFound.each { |itemFound|
description += i.to_s + ") " + itemFound.name + " " + itemFound.rarity + " " + I18n.t(:level) + " " + itemFound.level.to_s + "\n"
i += 1
}
event.send_embed do |embed|
embed.title = I18n.t(:chooseNumber)
embed.description = description
end
event.user.await(:guess) do |eventGuess|
guess = eventGuess.message.content.to_i
if(guess < 1 or guess > listFound.length)
guessEvent.respond I18n.t(:chooseNumber)
false
else
event.send_embed do |embed|
embed.title = listFound[guess - 1].name + " " +I18n.t(:level) + " " + listFound[guess - 1].level.to_s
embed.description = listFound[guess - 1].getStatsMessage
embed.color = listFound[guess - 1].color
embed.add_field(name: "Description: ", value: listFound[guess - 1].description)
embed.image = Discordrb::Webhooks::EmbedImage.new(url: listFound[guess - 1].image)
end
end
end
end
end
I18n.t(:searchEnd)
end
bot.command(:setLanguage, min_args: 1, max_args: 1, description: I18n.t(:setLanguageCommand), permission_level: 16) do |event, *args|
if(args[0] == "fr" or args[0] == "en")
language = ""
line_file = 0
id_found = false
id_server = event.server.id
File.open("config.txt", "w+") { |file_lang|
file_lang.each_line do |line|
if id_server == line.split(":")[0]
id_found = true
line.puts(id_server + ":" + args[0])
language = args[0]
end
line_file += 1
end
if(id_found == false)
language = args[0]
file_lang.write(id_server.to_s + ":" + language + "\n")
end
}
I18n.locale = language
event << I18n.t(:setLang1) + args[0] + I18n.t(:setLang2)
else
event << I18n.t(:wrongLanguage)
end
end
bot.command(:version, max_args: 0, description: I18n.t(:versionCommand)) do |event|
file = File.open("version.txt", "r")
message = ""
file.each_line do |line|
message += line
end
message
end
bot.ready() do |event|
event.bot.servers.each { |server|
puts event.bot.server(server[0]).name
puts event.bot.server(server[0]).owner.name
}
end
bot.run