Class: Prismarb::Prismalytics
- Inherits:
-
Object
- Object
- Prismarb::Prismalytics
- Defined in:
- lib/prismarb.rb
Instance Method Summary collapse
-
#initialize(key) ⇒ Prismalytics
constructor
A new instance of Prismalytics.
- #process_data(message, server) ⇒ Object
- #send(message) ⇒ Object
Constructor Details
#initialize(key) ⇒ Prismalytics
Returns a new instance of Prismalytics.
8 9 10 11 12 13 |
# File 'lib/prismarb.rb', line 8 def initialize(key) @key = key @commands = {} @servers = [] @time = nil end |
Instance Method Details
#process_data(message, server) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/prismarb.rb', line 15 def process_data(, server) = .content.split(" ")[0] if @commands.has_key? @commands[] += 1 else @commands[] = 1 end match = @servers.find { |i| i["name"] == server.name } if match.nil? new_server = { "name": server.name, "member_count": server.member_count, "region": server.region, "bot_messages": 1 } @servers << new_server else match["bot_messages"] += 1 end end |
#send(message) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/prismarb.rb', line 38 def send() """ processes data and sends every 2 minutes TODO: refactor so that users don't need to use ctx """ unset = false if @time.nil? @time = Time.now unset = true end server = .guild process_data(, server) curr_time = Time.now interval = (curr_time - @time) / 60 if (unset or interval > 5) @time = curr_time data = { "commands": @commands, "save_server": @save_server, "servers": @servers } Net::HTTP.post URI('https://prismalytics.herokuapp.com/send_data'), data.to_json, "key" => @key # reinitialize stored data as it has been sent @commands = {} @servers = [] end end |