elephrame 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 481e8c79f0c12a0037677a1eabc2b2676d97baf08376dc9e9c142a35ba13de2f
4
- data.tar.gz: 514d4b9a9a8c2461cb094fd44bbbe983e91ec98c4b0a3c01b2c16abf05a29f90
3
+ metadata.gz: 3c90f8c93681c54e2bea70e936a0b385e18b27e113af9ab920261b33b8966860
4
+ data.tar.gz: d231bce287036398f6100fe510b6b7299bbe742bc8e490dbaaf56c1c771226ac
5
5
  SHA512:
6
- metadata.gz: 83021602cec5f175c20977ceb9db566f376882e30b1e5bdde8582283d84ad401215facda9b943950a06eb167e34c027cf6d04b598a3a3e9a0e676937d1f5d8cd
7
- data.tar.gz: a3dac577c9c91a1d1b2fdea09d6a7211601fdeb3f5bdbb7524c855285a9ab7c47998acf867ab8a51ef80ffa58dea611fbf027e9a4cf825cbf88a3683ecb71f44
6
+ metadata.gz: 513660fa5de9fceac2645e4eacf52c7feaedfe52ec45a7d3bb3c66e930aa3c1360e5e4b9c23daa460381da5b28032eefa2edf91de9e6774726aea939a06cc122
7
+ data.tar.gz: 7cf67f91aaec15bb866cd543a7335d1813bcd11cc74ba25f86586416fe659e834756f8ed44d69aeec844ffdd5dff88de3d199463d20a1f45eb4428ea4ce01222
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elephrame (0.5.1)
4
+ elephrame (0.5.2)
5
5
  htmlentities (~> 4.0)
6
6
  moo_ebooks (~> 1)
7
7
  moostodon (~> 0.4.0)
@@ -11,15 +11,15 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- addressable (2.6.0)
15
- public_suffix (>= 2.0.2, < 4.0)
14
+ addressable (2.7.0)
15
+ public_suffix (>= 2.0.2, < 5.0)
16
16
  buftok (0.2.0)
17
17
  concurrent-ruby (1.1.5)
18
18
  domain_name (0.5.20190701)
19
19
  unf (>= 0.0.5, < 1.0.0)
20
- et-orbi (1.2.1)
20
+ et-orbi (1.2.2)
21
21
  tzinfo
22
- fugit (1.3.1)
22
+ fugit (1.3.3)
23
23
  et-orbi (~> 1.1, >= 1.1.8)
24
24
  raabro (~> 1.1)
25
25
  highscore (1.2.1)
@@ -43,8 +43,8 @@ GEM
43
43
  buftok (~> 0)
44
44
  http (~> 3.0)
45
45
  oj (~> 3.3)
46
- oj (3.8.1)
47
- public_suffix (3.1.1)
46
+ oj (3.9.1)
47
+ public_suffix (4.0.1)
48
48
  raabro (1.1.6)
49
49
  rake (10.5.0)
50
50
  rufus-scheduler (3.6.0)
data/README.md CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
27
27
 
28
28
  ## Quickstart
29
29
 
30
- bot that posts "i'm gay" every three hours:
30
+ bot that posts "trans right are human rights" every three hours:
31
31
 
32
32
  ```ruby
33
33
  require 'elephrame'
@@ -35,7 +35,7 @@ require 'elephrame'
35
35
  my_bot = Elephrame::Bots::Periodic.new '3h'
36
36
 
37
37
  my_bot.run do |bot|
38
- bot.post("i'm gay")
38
+ bot.post("trans rights are human rights")
39
39
  end
40
40
  ```
41
41
 
@@ -56,8 +56,12 @@ So far the framework support 6 bot types: Periodic, Interact, PeroidInteract, Re
56
56
  - `Command` supports running code when mentioned with commands it recognizes
57
57
  - `Watcher` supports watching streaming timelines (including lists, hashtags, public timeline, local timeline, and user timeline)
58
58
  - `TraceryBot` supports automatically loading tracery rules. Overloads post method to automatically expand any text passed through it. This bot type provides certain options that ease the use of tracery grammar rules, please see examples and/or documentation for more explanation.
59
+ - `EbooksBot` provides a very quick and easy way to create an ebooks bot. Please see the example in the examples folder for a detailed explanation.
60
+ - `MarkovBot` provides a quick way to get started with making markov bots. Please see the example in the examples folder.
59
61
 
60
- The string passed to `Periodic` and `PeroidInteract` must be either a 'Duration' string or a 'Cron' string, as parsable by [fugit](https://github.com/floraison/fugit)
62
+ Both the Ebooks and Markov bots support a few commands out of the box. `!delete`, `!filter`, and `!help`. These commands will only work when sent from an account that the bot is following. The Ebooks bot supports `!update` as well.
63
+
64
+ Any time a 'time' string is needed it must be either a 'Duration' or 'Cron' string as parsable by [fugit](https://github.com/floraison/fugit)
61
65
 
62
66
  ## Usage
63
67
 
@@ -1,4 +1,6 @@
1
1
  require 'net/http'
2
+ require 'digest'
3
+ require 'time'
2
4
 
3
5
  module Elephrame
4
6
  module Bots
@@ -12,6 +14,7 @@ module Elephrame
12
14
  attr_accessor :strip_html, :max_retries
13
15
 
14
16
  NoBotRegex = /#?NoBot/i
17
+ FNGabLink = 'https://fediverse.network/mastodon?build=gab'
15
18
 
16
19
  ##
17
20
  # Sets up our REST +client+, gets and saves our +username+, sets default
@@ -20,6 +23,9 @@ module Elephrame
20
23
  # @return [Elephrame::Bots::BaseBot]
21
24
 
22
25
  def initialize
26
+
27
+ raise "Fuck off Gabber" if Net::HTTP.get(URI.parse(FNGabLink)).include? URI.parse(ENV['INSTANCE']).host
28
+
23
29
  @client = Mastodon::REST::Client.new(base_url: ENV['INSTANCE'],
24
30
  bearer_token: ENV['TOKEN'])
25
31
  @username = @client.verify_credentials().acct
@@ -55,10 +61,16 @@ module Elephrame
55
61
  spoiler_text: spoiler,
56
62
  in_reply_to_id: reply_id,
57
63
  media_ids: @failed[:media] ? [] : uploaded_ids,
58
- sensitive: hide_media,
64
+ sensitive: hide_media
59
65
  }
60
66
 
67
+ # create a unique key for the status
68
+ # this key prevents a status from being posted more than once
69
+ # SHOULD be unique enough, by smooshing time and content together
70
+ idempotency = Digest::SHA256.hexdigest("#{Time.now}#{text}")
71
+
61
72
  @failed[:post] = retry_if_needed {
73
+ options[:headers] = { "Idempotency-Key" => idempotency }
62
74
  @client.create_status text, options
63
75
  }
64
76
  end
@@ -73,7 +73,7 @@ module Elephrame
73
73
  # set up our bot stuff
74
74
  setup_scheduler interval
75
75
  setup_streaming
76
- setup_tracery dirs
76
+ setup_tracery *dirs
77
77
  end
78
78
 
79
79
  ##
@@ -295,6 +295,18 @@ module Elephrame
295
295
  super
296
296
  end
297
297
 
298
+ ##
299
+ # overloads the super's help method
300
+ #
301
+ # @returns [String] default help text
302
+
303
+ def default_help
304
+ txt = []
305
+ txt << '!update -- tells the bot to manually fetch new posts'
306
+ txt << super
307
+ txt.join '\n'
308
+ end
309
+
298
310
  private
299
311
 
300
312
  ##
@@ -15,8 +15,7 @@ module Elephrame
15
15
  # @param dirs [String] path to the directory containing the tracery rules
16
16
 
17
17
  def setup_tracery *dirs
18
- raise "Provided path not a directory" unless Dir.exist?(dir_path)
19
-
18
+
20
19
  @grammar = {}
21
20
 
22
21
  dirs.each do |directory|
@@ -27,7 +26,7 @@ module Elephrame
27
26
 
28
27
  # read the rule file into the files hash
29
28
  @grammar[file.split('.').first] =
30
- createGrammar(JSON.parse(File.read("#{dir_path}/#{file}")))
29
+ createGrammar(JSON.parse(File.read("#{directory}/#{file}")))
31
30
  end
32
31
  end
33
32
  end
@@ -1,3 +1,3 @@
1
1
  module Elephrame
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elephrame
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zac
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-05 00:00:00.000000000 Z
11
+ date: 2019-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  requirements: []
182
- rubygems_version: 3.0.4
182
+ rubygems_version: 3.0.3
183
183
  signing_key:
184
184
  specification_version: 4
185
185
  summary: A framework for assisting in making mastodon/pleroma bots