diff --git a/src/bot.rb b/src/bot.rb index 1e68de9..4a2f0b7 100644 --- a/src/bot.rb +++ b/src/bot.rb @@ -15,6 +15,7 @@ # along with this program. If not, see . require 'discordrb' +require 'securerandom' class CheeseBot def initialize @@ -54,5 +55,41 @@ class CheeseBot puts "#{@bot.profile.username} is online... GIVE ME THE CHEESE." @bot.update_status("online", "We're so back.", nil, 0, false, 0) end + + @bot.server_create do |event| + server = event.server + bot_profile = server.bot + + # Prevent spam on restart + # Check if the bot joined a server in the last 60 seconds + next if bot_profile.joined_at && (Time.now - bot_profile.joined_at) > 60 + + # Try system channel first. + # If nil or no permissions, search text channels. + channel = server.system_channel + + unless channel && bot_profile.permission?(:send_messages, channel) + channel = server.text_channels.find { |c| bot_profile.permission?(:send_messages, c) } + end + + next unless channel + + random_color = ("0x" + Random.bytes(3).unpack1('H*')).to_i(16) + + channel.send_embed do |embed| + embed.title = "cheeseBot has joined!" + embed.description = "What now?" + embed.color = random_color + embed.timestamp = Time.now + + embed.add_field(name: "Well...", value: "You can start with the /help command!") + embed.add_field(name: "And then?", value: "Start trying out the rest of commands!") + embed.add_field(name: "Sounds good!", value: "We hope you enjoy cheeseBot! Stay cheesy :)") + + embed.footer = Discordrb::Webhooks::EmbedFooter.new( + text: "Be advised this bot automatically sends DMs when detected. Use /blacklist to not receive DMs." + ) + end + end end end diff --git a/src/commands/cheese.rb b/src/commands/cheese_related/cheese.rb similarity index 100% rename from src/commands/cheese.rb rename to src/commands/cheese_related/cheese.rb diff --git a/src/commands/facts.rb b/src/commands/cheese_related/facts.rb similarity index 95% rename from src/commands/facts.rb rename to src/commands/cheese_related/facts.rb index 51ff25f..331fd0d 100644 --- a/src/commands/facts.rb +++ b/src/commands/cheese_related/facts.rb @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -require_relative '../lists/cheese_facts' +require_relative '../../lists/cheese_facts.rb' module Commands module Facts diff --git a/src/commands/photos.rb b/src/commands/cheese_related/photos.rb similarity index 96% rename from src/commands/photos.rb rename to src/commands/cheese_related/photos.rb index 519233f..14a4794 100644 --- a/src/commands/photos.rb +++ b/src/commands/cheese_related/photos.rb @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -require_relative '../lists/cheese_photos' +require_relative '../../lists/cheese_photos' module Commands module Photos diff --git a/src/commands/truth.rb b/src/commands/cheese_related/truth.rb similarity index 96% rename from src/commands/truth.rb rename to src/commands/cheese_related/truth.rb index 0db8319..922cd8d 100644 --- a/src/commands/truth.rb +++ b/src/commands/cheese_related/truth.rb @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -require_relative '../lists/cheese_of_truth' +require_relative '../../lists/cheese_of_truth' module Commands module Truth diff --git a/src/commands/not_cheese_related/help.rb b/src/commands/not_cheese_related/help.rb new file mode 100644 index 0000000..c851387 --- /dev/null +++ b/src/commands/not_cheese_related/help.rb @@ -0,0 +1,58 @@ +# cheeseBot +# Copyright (C) 2026 Eri (csxkdv/nxkdv) nxkdv@thenight.club +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +require 'securerandom' + +module Commands + module Help + extend self + + def register(bot) + cmd_key = :help + cmd_desc = "Use this command to know more." + + bot.register_application_command(cmd_key, cmd_desc, server_id: ENV['SERVER_ID']) + + bot.application_command(cmd_key) do |event| + random_color = ("0x" + Random.bytes(3).unpack1('H*')).to_i(16) + author = event.user + + embed_generated = { + title: "About cheeseBot...", + description: "Here's everything you need to know!", + color: random_color, + timestamp: Time.now.iso8601, + author: { + name: author.username, + icon_url: author.avatar_url + }, + fields: [ + { + name: "Who am I?", + value: "I'm cheeseBot. Made by <@396376536070094848> related to cheese stuff." + }, + { + name: "What are your commands?", + value: "/cheese, /fact, /photo, /truth, and more!" + } + ] + } + + event.respond(embeds: [embed_generated]) + end + end + end +end