rikutelebot 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cc57b8da288dd2a9fe2f2da55e2e6f2274e60cc
4
- data.tar.gz: 4b9d1157b5b62cba5746b349456d36f23d87dc0c
3
+ metadata.gz: 76b89127099d381383338befe3e006cda84a5876
4
+ data.tar.gz: 11a32e24c90a6df9da6e6753e559fc2a310b5347
5
5
  SHA512:
6
- metadata.gz: 857b8968ae525ba5a879a0ff248d1881e1cc8822ea65841fa914daf30c216df100ca65434ffb91558ff38099badea233d348cd4a60a0eb60a96f2fb33b443af6
7
- data.tar.gz: 0a01e2516b4a65b622a531a0db76503f19ecdd2fa2df6198f10befaa844d7a876f7505633bfa8579ca5bd2e6cb4da2eb1cb82f51cbcb115908cc89fa77a28539
6
+ metadata.gz: 71253d82574234567d333fd39e557a33897c062f8222a657842da0b99440b0d0182dbfaed73b45235fc4373c403f293b81c1424cd5fa27a0e272eef2bc3477b0
7
+ data.tar.gz: b409758a1df343b539cd4cf82894e8000c26128e2b4217d6cb173964cc1b7ef8861a8d88014fab5691f87709ede87363dfbe5c37b62b9cb633a8629534247af1
data/lib/rikutelebot.rb CHANGED
@@ -1,16 +1,52 @@
1
1
  require "rikutelebot/version"
2
+ require 'open-uri'
3
+ require 'json'
2
4
 
3
5
  module Rikutelebot
4
6
 
5
- Config = Struct.new(:token)
7
+ Config = Struct.new(:token) do
8
+ def getupdatesurl
9
+ "https://api.telegram.org/bot#{token}/getUpdates"
10
+ end
11
+ end
12
+
13
+ User = Struct.new(:first_name, :last_name, :id, :username)
14
+
15
+ Chat = Struct.new(:id, :title, :username)
16
+
17
+ Message = Struct.new(:from, :chat, :text) do
18
+ def format
19
+ "<#{from.first_name}@#{chat.username}>: #{text}"
20
+ end
21
+ end
22
+
6
23
  class Bot
7
24
  def initialize
8
25
  @conf = Config.new nil
9
26
  yield @conf
10
27
  end
11
28
 
12
- def token
13
- @conf.token
29
+ def run
30
+ updates = []
31
+ j = JSON.parse open(@conf.getupdatesurl).read()
32
+ for update in j['result']
33
+ fn = update['message']['from']['first_name']
34
+ ln = update['message']['from']['last_name']
35
+ id = update['message']['from']['id']
36
+ un = update['message']['from']['username']
37
+
38
+ usr = User.new(fn, ln, id, un)
39
+
40
+ id = update['message']['chat']['id']
41
+ title = update['message']['chat']['title']
42
+ un = update['message']['chat']['username'] || 'Private chat'
43
+
44
+ chat = Chat.new(id, title, un)
45
+
46
+ yield Message.new(usr, chat, update['message']['text']) unless update['message']['text'].nil?
47
+ end
14
48
  end
49
+
15
50
  end
51
+
16
52
  end
@@ -1,3 +1,3 @@
1
1
  module Rikutelebot
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rikutelebot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Riku