diff --git a/main.rb b/main.rb index 582c7c6..270ce5c 100755 --- a/main.rb +++ b/main.rb @@ -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')