-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisco_navi.rb
executable file
·248 lines (219 loc) · 8.95 KB
/
disco_navi.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
#!/usr/bin/env ruby
# coding: utf-8
# frozen_string_literal: true
::RBNACL_LIBSODIUM_GEM_LIB_PATH = 'D:/Dev/Projects/ivory-dice-rb/libsodium.dll'
require 'dotenv/load'
require 'discordrb'
require 'discordrb/webhooks'
require 'discordrb/webhooks/embeds'
require './dice'
require './gw2'
require './guild_upgrades'
require './calc'
require './zelda_status'
require './zelda_log'
#
# If you don't yet have a token and application ID to put in here, you will need to create a bot account here:
# https://discordapp.com/developers/applications/me
# If you're wondering about what redirect URIs and RPC origins, you can ignore those for now. If that doesn't satisfy
# you, look here: https://github.com/meew0/discordrb/wiki/Redirect-URIs-and-RPC-origins
# After creating the bot, simply copy the token (*not* the OAuth2 secret) and the client ID and put it into the
# respective places.
bot = Discordrb::Bot.new token: ENV['DISCORD_BOT_TOKEN'], client_id: (ENV['DISCORD_BOT_CLIENT_ID'].to_i)
puts "This bot's invite URL is #{bot.invite_url}."
puts 'Click on it to invite it to your server.'
$pesters = Dir["D:/Dev/Projects/ivory-dice-rb/soundboard/*"]
$gw2_api_token = ENV['GW2_API_TOKEN']
$aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
$aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
$zurpg_status = ZURPG::StatusHandler.new
# Respond to '$Xd___', AKA a die roll request
bot.message(contains: Dice::DIE_ROLL_REGEX) do |event|
author_name =
if event.author.respond_to?(:display_name)
then event.author.display_name
else event.author.username
end
message = Dice.new(event.content).roll(author_name)
event << message
end
bot.message(start_with: /\$join\s+/) do |event|
channel_name = event.content.match(/\$join\s+(.+)/).captures[0]
voice_channels = bot.find_channel(channel_name, event.server&.name, type: 2) # 2: voice channel
if voice_channels.empty?
event << "No voice channel found: '#{channel_name}'"
elsif voice_channels.size > 1
channel_names =
voice_channels
.collect { |c| "#{c.server&.name}\##{c.name}" }
.reduce { |accum, x| accum << ", #{x}" }
event << "Ambiguous voice channel name; found options: #{channel_names}"
else
bot.voice_connect(voice_channels[0])
end
end
bot.message(content: '$leave') do |event|
event.voice&.destroy
event << "Okay, okay, I'll leave now..." unless event.voice
end
bot.message(content: '$whereyouat') do |event|
event << event.voice&.channel&.name
end
bot.message(start_with: '$pester') do |event|
captures = event.content.match(/\$pester\s*(\d*)\s*(speak)?/).captures
repetitions = 1
repetitions = captures[0].to_i if captures[0] && !(captures[0].empty?)
speak = true if captures[1]
repetitions.times do
event.voice&.play_file($pesters.sample)
if speak
event.channel.send_message(['Hello!', 'Hey!', 'Listen!', 'Look!', 'Watch out!'].sample, true)
end
end
end
bot.message(start_with: /\$calc\s+/) do |event|
expr = event.content.match(/\$calc\s+(.*)/).captures[0]
calculator = Calculator::Handler.new(expr)
calculator.calculate(event)
end
bot.message(start_with: '$gw2 item') do |event|
item_id = event.content.match(/\$gw2 item\s+(\d+)/).captures[0]
item = GW2::Item.new(item_id)
item.fetch
item_embed = GW2::ItemEmbed.new(item)
item_embed.print(event)
end
bot.message(start_with: '$gw2 guild info') do |event|
guild_name = event.content.match(/\$gw2 guild info\s+'(.+?)'/).captures[0]
GW2::GuildInfoHandler.new(guild_name, $gw2_api_token).handle.render(event)
end
bot.message(start_with: '$gw2 guild list upgrades') do |event|
guild_name = event.content.match(/\$gw2 guild list upgrades\s+'(.+?)'/).captures[0]
GW2::GuildUpgradeListHandler.new(guild_name, $gw2_api_token).handle.render(event)
end
bot.message(start_with: '$gw2 guild list ready upgrades') do |event|
guild_name = event.content.match(/\$gw2 guild list ready upgrades\s+'(.+?)'/).captures[0]
GW2::GuildReadyUpgradesHandler.new(guild_name, $gw2_api_token).handle(event)
end
bot.message(start_with: '$gw2 guild upgrade') do |event|
guild_name, upgrade_name = event.content.match(/\$gw2 guild upgrade\s+'(.+?)'\s+'(.+?)'/).captures
GW2::GuildUpgradeInfoHandler.new(guild_name, upgrade_name, $gw2_api_token).handle(event)
end
bot.message(start_with: '$gw2 guild contrib') do |event|
guild_name = event.content.match(/\$gw2 guild contrib\s+'(.+?)'/).captures[0]
GW2::GuildContributionsHandler.new(guild_name, $gw2_api_token).handle(event)
end
bot.message(start_with: '$gw2 guild item upgrades') do |event|
guild_name, item_name = event.content.match(/\$gw2 guild item upgrades\s+'(.+?)'\s+'(.+?)'/).captures
GW2::GuildIngredientUpgradesHandler.new(guild_name, item_name, $gw2_api_token).handle(event)
end
bot.message(start_with: '$zstatus') do |event|
status_in = event.content.match(/\$zstatus\s*(.*)/).captures[0]
break if status_in.nil?
if status_in.empty?
$zurpg_status.handle_fetch(event)
elsif status_in.strip == 'clear'
$zurpg_status.handle_clear(event)
else
$zurpg_status.handle_save(status_in, event)
end
end
bot.message(content: '$endlog') do |event|
condition = lambda do |message|
message.content.strip.start_with?('$startlog') &&
message.author.id == event.message.author.id
end
ZURPG::ActiveLogGenerator.new(event.message, condition).call
end
bot.reaction_add(emoji: '🛑') do |event|
condition = lambda do |message|
message.reacted_with('✍️').any? { |user| user.id == event.user.id }
end
gen = ZURPG::ActiveLogGenerator.new(event.message, condition)
gen.call
if gen.start_message
gen.start_message.delete_reaction event.user, '✍️'
gen.end_message.delete_reaction event.user, '🛑'
end
end
bot.message(content: '$help') do |event|
event.channel.send_embed do |embed|
embed.title = 'Utility'
embed.color = 0xAA3939
embed.add_field(name: '${x}d{y} or ${x}D{y}', value: 'Roll x dice with y sides, e.g. $5d20')
embed.add_field(
name: '${x}dz or ${x}dZ or ${x}d10',
value: 'Roll x special ZURPG dice: 1-4 = 0, 5-9 = 1, 10 = 2'
)
embed.add_field(
name: '${x}do or ${x}dO or ${x}d6',
value: 'Roll x special Orithan dice: 1-3 = 0, 4-5 = 1, 6 = 2'
)
embed.add_field(
name: '$zstatus {status}',
value: 'Sets your status'
)
embed.add_field(
name: '$zstatus',
value: 'Displays your status'
)
embed.add_field(
name: '$zstatus clear',
value: 'Clears your status'
)
embed.add_field(
name: '$startlog _followed later by_ $endlog',
value: 'Captures and uploads a log between the `$startlog` and `$endlog` commands (max 24 hrs, 100k messages) _Requires message history permissions._'
)
embed.add_field(
name: 'React with ✍️ _followed by_ 🛑 _on a later post_',
value: 'Captures and uploads a log starting with the message reacted with ✍️ and ending with the message reacted with 🛑 (max 24 hrs, 100k messages) _Requires message history permissions, and message management permissions to remove the reactions automatically._'
)
embed.add_field(
name: '$calc {expression}',
value: 'Do integer / rational mathematics. No spaces allowed. +,-,*,/,(), and die rolls permitted, e.g. 10d10-5+2/(2d2+6)'
)
end
event.channel.send_embed do |embed|
embed.title = 'Voice'
embed.color = 0x226666
embed.add_field(
name: '$join {voice-channel}',
value: 'Make Navi join a voice chat channel by name, e.g. $join General'
)
embed.add_field(
name: '$pester [n] [speak]',
value: 'Make Navi nag people in voice n times (1 by default), and in TTS if you tell her to speak; e.g. $pester 10 speak'
)
embed.add_field(name: '$leave', value: "Make Navi leave any voice channel she's in")
end
event.channel.send_embed do |embed|
embed.title = 'Guild Wars 2'
embed.color = 0x7B9F35
embed.add_field(
name: "$gw2 guild info '{guild-name}'",
value: "Show info about the given guild, e.g. $gw2 guild info 'The Shard Warband'"
)
embed.add_field(
name: "$gw2 guild list upgrades '{guild-name}'",
value: "Show upgrades in progress for the given guild, e.g. $gw2 guild list upgrades 'The Shard Warband'"
)
embed.add_field(
name: "$gw2 guild list ready upgrades '{guild-name}'",
value: "Show upgrades ready to build for the given guild, e.g. $gw2 guild list ready upgrades 'The Shard Warband'"
)
embed.add_field(
name: "$gw2 guild upgrade '{guild-name}' '{upgrade-name}'",
value: "Show remaining progress for the given upgrade, e.g. $gw2 guild upgrade 'The Shard Warband' 'Tavern'"
)
embed.add_field(
name: "$gw2 guild contrib '{guild-name}'",
value: "Shows guild treasury contributions over the past day, e.g. $gw2 guild contrib 'The Shard Warband'"
)
embed.add_field(
name: "$gw2 guild item upgrades '{guild-name}' '{item-name}'",
value: "Shows upgrades that use the given item, and quantities required, e.g. $gw2 guild item upgrades 'The Shard Warband' 'Linseed'"
)
end
end
bot.run