add networking stuff

This commit is contained in:
fzorb 2024-10-04 19:02:48 +03:00
parent efa6ada5bb
commit 22a226402c
3 changed files with 31 additions and 2 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
jon.sqlite
Gemfile.lock
.idea
iplocation.bin

9
bot.rb
View File

@ -13,11 +13,18 @@ bot.message do |event|
end
bot.command :help do |event, *message|
event.author.pm("You've asked for help. In order not to flood the channel where you sent the command, I have sent the list of commands here, in your PMs. Enjoy! \n\n**Quote system**\n```;quote <category> - displays a quote from the category\n;addquote <category> <quote> - adds a quote into a category\n;quotecategories - shows all categories\n;showquote <id> - shows the quote with the id provided```")
event.author.pm("You've asked for help. In order not to flood the channel where you sent the command, I have sent the list of commands here, in your PMs. Enjoy!
**Quote system**\n```;quote <category> - displays a quote from the category\n;addquote <category> <quote> - adds a quote into a category\n;quotecategories - shows all categories\n;showquote <id> - shows the quote with the id provided```
**Networking related commands**\n```;ip <ips> - Display basic information about an IP address. You can input multiple IPs. We are required to state that the information provided by this command comes from the IP2Location database.```
")
event.message.delete
nil
end
require_relative 'systems/quote'
require_relative 'systems/network'
bot.include! QuoteSystem
bot.include! NetworkModule
bot.run

21
systems/network.rb Normal file
View File

@ -0,0 +1,21 @@
# frozen_string_literal: true
require 'discordrb'
require 'ip2location_ruby'
module NetworkModule
extend Discordrb::Commands::CommandContainer
command :ip do |event, *message|
database = Ip2location.new.open("#{__dir__}/../iplocation.bin")
records = []
for ip in message do
records.push(database.get_all(ip).merge!("ip" => ip))
end
response = ""
for record in records do
response = response + "**:flag_#{record['country_short'].downcase}: #{record['ip']}**\n**Region**: #{record['region']}\n**City**: #{record['city']}\n\n"
end
event.channel.send(response)
database.close()
nil
end
end