Initial commit

This commit is contained in:
Bill Rossi 2025-08-12 06:09:47 -04:00
commit f70a16ec43
4 changed files with 70 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
token

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

20
ika.rb Normal file
View File

@ -0,0 +1,20 @@
require 'discordrb'
require_relative './session'
token = File.read("./token")
bot = Discordrb::Bot.new(token:)
current_session = nil
bot.message do |event|
if event.message.content == "!init"
next event.respond("There's already a session running") unless current_session.nil?
next current_session = Session.new(event, event.message.author)
end
current_session&.respond_to event
end
bot.run

49
session.rb Normal file
View File

@ -0,0 +1,49 @@
class Session
attr_reader :bot, :owner, :users
def initialize(event, owner)
@bot = event.bot
@owner = owner
@users = [owner]
event.respond "New Ika session created!"
end
COMMANDS = %w[
join
]
def command_join(event)
user = event.message.author
if contains_user? user
"#{event.message.author.username} is already in this session"
else
"#{event.message.author.username} joined"
end
end
def add_user(user)
users << user
end
def contains_user?(user)
users.include? user
end
def valid_command(message_content)
prebang, cmd = message_content.split("!")
cmd if prebang.empty? && COMMANDS.include?(cmd)
end
def respond_to(event)
if command = valid_command(event.message.content)
puts "running !#{command} from #{event.message.author.username}"
event.respond send("command_#{command}", event)
else
respond_to_normal_message event
end
end
def respond_to_normal_message(event)
puts "received '#{event.message.content}' from #{event.message.author.username}"
end
end