diff --git a/.gitignore b/.gitignore index a2e60e8..92cbd37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .env jon.sqlite Gemfile.lock -.idea \ No newline at end of file +.idea +iplocation.bin \ No newline at end of file diff --git a/bot.rb b/bot.rb index 57d0609..b1d6be0 100644 --- a/bot.rb +++ b/bot.rb @@ -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 - displays a quote from the category\n;addquote - adds a quote into a category\n;quotecategories - shows all categories\n;showquote - 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 - displays a quote from the category\n;addquote - adds a quote into a category\n;quotecategories - shows all categories\n;showquote - shows the quote with the id provided``` +**Networking related commands**\n```;ip - 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 diff --git a/systems/network.rb b/systems/network.rb new file mode 100644 index 0000000..7e55cb5 --- /dev/null +++ b/systems/network.rb @@ -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 \ No newline at end of file