Skip to content

Commit

Permalink
Add slash command to create channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Quintasan committed Mar 28, 2024
1 parent 01da8d6 commit 1949efe
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,40 @@
DB.loggers << LOGGER
require_relative('models')

bot = Discordrb::Bot.new(token: PRZYPOMINACZ_TOKEN)
bot = Discordrb::Bot.new(token: PRZYPOMINACZ_TOKEN, fancy_log: true)
bot.register_application_command(:create_section, "Tworzy rolę, kategorię i kanały dla strefy", server_id: SERVER_ID) do |cmd|
cmd.string('section_name', 'Nazwa strefy', required: true)
end
bot.application_command(:create_section) do |event|
event.respond(content: "On it sir!", ephemeral: true)

section_name = event.options['section_name']
server = event.channel.server

LOGGER.info "Creating role #{section_name}"
role = server.create_role(name: section_name)

allow_role_to_communicate = Discordrb::Permissions.new [:read_messages, :send_messages, :connect, :speak]
add_role_to_category = Discordrb::Overwrite.new(role, allow: allow_role_to_communicate)

deny_everyone = Discordrb::Permissions.new [:read_messages, :connect]
private_category = Discordrb::Overwrite.new(SERVER_ID, type: "role", deny: deny_everyone)

LOGGER.info "Creating category #{section_name}"
category = server.create_channel(section_name, 4, permission_overwrites: [private_category, add_role_to_category])

text_channels = %w[ogłoszenia-org ogólny pomysły do-orgów voicespam]
text_channels.each do |channel_name|
LOGGER.info "Creating text channel #{channel_name}"
server.create_channel(channel_name, parent: category)
end

voice_channels = %w[voice]
voice_channels.each do |channel_name|
LOGGER.info "Creating voice channel #{channel_name}"
server.create_channel(channel_name, 2, parent: category)
end
end
bot.run(:async)

require_relative('fetch_discord_user_map')
Expand Down

0 comments on commit 1949efe

Please sign in to comment.