rbot 0.9.13 → 0.9.14

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.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ task :default => [:buildext]
6
6
 
7
7
  spec = Gem::Specification.new do |s|
8
8
  s.name = 'rbot'
9
- s.version = '0.9.13'
9
+ s.version = '0.9.14'
10
10
  s.summary = <<-EOF
11
11
  A modular ruby IRC bot.
12
12
  EOF
data/bin/rbot CHANGED
@@ -47,7 +47,7 @@ require 'etc'
47
47
  require 'getoptlong'
48
48
  require 'fileutils'
49
49
 
50
- $version ||= '0.9.13'
50
+ $version ||= '0.9.14'
51
51
  $version_timestamp ||= 0
52
52
  $opts = Hash.new
53
53
 
@@ -122,10 +122,16 @@ class FigletPlugin < Plugin
122
122
  exec_params = [send(:"#{key}_path")] + @params[key] + [message]
123
123
 
124
124
  # run the program
125
- m.reply Utils.safe_exec(*exec_params), :max_lines => 0
125
+ m.reply strip_first_last_empty_line(Utils.safe_exec(*exec_params)), :max_lines => 0
126
126
  end
127
127
  alias :toilet :figlet
128
128
 
129
+ private
130
+
131
+ def strip_first_last_empty_line(txt)
132
+ txt.gsub(/\A(?:^\s*\r?\n)+/m,'').rstrip
133
+ end
134
+
129
135
  end
130
136
 
131
137
  plugin = FigletPlugin.new
@@ -930,9 +930,23 @@ class QuizPlugin < Plugin
930
930
 
931
931
  end
932
932
 
933
- end
934
-
933
+ def stop(m, params)
934
+ unless m.public?
935
+ m.reply 'you must be on some channel to use this command'
936
+ return
937
+ end
938
+ if @quizzes.delete m.channel
939
+ @ask_mutex.synchronize do
940
+ t = @waiting.delete(m.channel)
941
+ @bot.timer.remove t if t
942
+ end
943
+ m.okay
944
+ else
945
+ m.reply(_("there is no active quiz on #{m.channel}"))
946
+ end
947
+ end
935
948
 
949
+ end
936
950
 
937
951
  plugin = QuizPlugin.new
938
952
  plugin.default_auth( 'edit', false )
@@ -950,6 +964,7 @@ plugin.map 'quiz refresh', :action => 'cmd_refresh'
950
964
  plugin.map 'quiz top5', :action => 'cmd_top5'
951
965
  plugin.map 'quiz top :number', :action => 'cmd_top_number'
952
966
  plugin.map 'quiz stats', :action => 'cmd_stats'
967
+ plugin.map 'quiz stop', :action => :stop
953
968
 
954
969
  # Admin commands
955
970
  plugin.map 'quiz autoask :enable', :action => 'cmd_autoask', :auth_path => 'edit'
@@ -336,14 +336,28 @@ class UnoGame
336
336
  # if play is forced, check against the only allowed cards
337
337
  return false if @must_play and not @must_play.include?(card)
338
338
 
339
- # When a +something is online, you can only play a +something of same or
340
- # higher something, or a Reverse of the correct color, or a Reverse on
341
- # a Reverse
342
- # TODO make optional
343
339
  if @picker > 0
344
- return true if card.picker >= @last_picker
345
- return true if card.value == 'Reverse' and (card.color == @color or @discard.value == card.value)
346
- return false
340
+ # During a picker run (i.e. after a +something was played and before a
341
+ # player is forced to pick) you can only play pickers (+2, +4) and
342
+ # Reverse. Reverse can be played if the previous card matches by color or
343
+ # value (as usual), a +4 can always be played, a +2 can be played on a +2
344
+ # of any color or on a Reverse of the correct color unless a +4 was
345
+ # played on it
346
+ # TODO make optional
347
+ case card.value
348
+ when 'Reverse'
349
+ # Reverse can be played if it matches color or value
350
+ return (card.color == @color) || (@discard.value == card.value)
351
+ when '+2'
352
+ return false if @last_picker > 2
353
+ return true if @discard.value == card.value
354
+ return true if @discard.value == 'Reverse' and @color == card.color
355
+ return false
356
+ when '+4'
357
+ return true
358
+ else
359
+ return false
360
+ end
347
361
  else
348
362
  # You can always play a Wild
349
363
  return true if Wild === card
@@ -314,6 +314,10 @@ class RSSFeedsPlugin < Plugin
314
314
  # TODO: load personal ones
315
315
  def define_filters
316
316
  @outkey = :"rss.out"
317
+ @bot.register_filter(:headlines, @outkey) { |s|
318
+ line1 = (s[:handle].empty? ? "%{date}" : "%{handle}") << "%{title}"
319
+ make_stream(line1, nil, s)
320
+ }
317
321
  @bot.register_filter(:blog, @outkey) { |s|
318
322
  author = s[:author] ? (s[:author] + " ") : ""
319
323
  abt = s[:category] ? "about #{s[:category]} " : ""
@@ -329,13 +333,13 @@ class RSSFeedsPlugin < Plugin
329
333
  make_stream(line1, line2, s, :author => author, :abt => abt)
330
334
  }
331
335
  @bot.register_filter(:news, @outkey) { |s|
332
- line1 = "%{handle}%{date}%{title} @ %{link}" % s
336
+ line1 = "%{handle}%{date}%{title}%{at}%{link}" % s
333
337
  line2 = "%{handle}%{date}%{desc}" % s
334
338
  make_stream(line1, line2, s)
335
339
  }
336
340
  @bot.register_filter(:git, @outkey) { |s|
337
341
  author = s[:author] ? (s[:author] + " ") : ""
338
- line1 = "%{handle}%{date}%{author}committed %{title} @ %{link}"
342
+ line1 = "%{handle}%{date}%{author}committed %{title}%{at}%{link}"
339
343
  make_stream(line1, nil, s, :author => author)
340
344
  }
341
345
  @bot.register_filter(:forum, @outkey) { |s|
@@ -353,7 +357,7 @@ class RSSFeedsPlugin < Plugin
353
357
  }
354
358
  @bot.register_filter(:trac, @outkey) { |s|
355
359
  author = s[:author].sub(/@\S+?\s*>/, "@...>") + ": " if s[:author]
356
- line1 = "%{handle}%{date}%{author}%{title} @ %{link}"
360
+ line1 = "%{handle}%{date}%{author}%{title}%{at}%{link}"
357
361
  line2 = nil
358
362
  unless s[:item].title =~ /^(?:Changeset \[(?:[\da-f]+)\]|\(git commit\))/
359
363
  line2 = "%{handle}%{date}%{desc}"
@@ -1149,7 +1153,7 @@ class RSSFeedsPlugin < Plugin
1149
1153
  report_problem("no items found in the feed, maybe try weed?", e, m)
1150
1154
  return nil
1151
1155
  end
1152
- feed.title = title
1156
+ feed.title = title.strip
1153
1157
  feed.items = items
1154
1158
  return true
1155
1159
  end
@@ -55,7 +55,7 @@ class SeenPlugin < Plugin
55
55
  @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "JOIN",
56
56
  m.target.to_s, m.message.dup)
57
57
  when TopicMessage
58
- return if m.address?
58
+ return if m.address? or m.info_or_set == :info
59
59
  @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "TOPIC",
60
60
  m.target.to_s, m.message.dup)
61
61
  end
@@ -167,13 +167,13 @@ class IrcLogModule < CoreBotModule
167
167
  end
168
168
 
169
169
  def log_nick(m)
170
- m.is_on.each { |ch|
170
+ (m.is_on & @bot.myself.channels).each { |ch|
171
171
  irclog "@ #{m.oldnick} is now known as #{m.newnick}", ch
172
172
  }
173
173
  end
174
174
 
175
175
  def log_quit(m)
176
- m.was_on.each { |ch|
176
+ (m.was_on & @bot.myself.channels).each { |ch|
177
177
  irclog "@ Quit: #{m.source}: #{m.logmessage}", ch
178
178
  }
179
179
  end
@@ -610,8 +610,8 @@ class HttpUtil
610
610
  opts = {:method => :head}.merge(options)
611
611
  begin
612
612
  resp = get_response(uri, opts, &block)
613
- raise "http error #{resp}" if Net::HTTPClientError === resp ||
614
- Net::HTTPServerError == resp
613
+ # raise "http error #{resp}" if Net::HTTPClientError === resp ||
614
+ # Net::HTTPServerError == resp
615
615
  return resp
616
616
  rescue Exception => e
617
617
  error e
data/lib/rbot/irc.rb CHANGED
@@ -4,6 +4,8 @@
4
4
  # Channels is the User on (of those the client is on too)?
5
5
  # We may want this so that when a User leaves all Channels and he hasn't
6
6
  # sent us privmsgs, we know we can remove him from the Server @users list
7
+ # FIXME for the time being, we do it with a method that scans the server
8
+ # (if defined), so the method is slow and should not be used frequently.
7
9
  # * Maybe ChannelList and UserList should be HashesOf instead of ArrayOf?
8
10
  # See items marked as TODO Ho.
9
11
  # The framework to do this is now in place, thanks to the new [] method
@@ -1041,6 +1043,14 @@ module Irc
1041
1043
  raise "Can't resolve channel #{channel}"
1042
1044
  end
1043
1045
  end
1046
+
1047
+ def channels
1048
+ if @server
1049
+ @server.channels.select { |ch| ch.has_user?(self) }
1050
+ else
1051
+ Array.new
1052
+ end
1053
+ end
1044
1054
  end
1045
1055
 
1046
1056
 
data/lib/rbot/ircbot.rb CHANGED
@@ -591,6 +591,8 @@ class Bot
591
591
  # '*' means all channels
592
592
  #
593
593
  @quiet = Set.new
594
+ # but we always speak here
595
+ @not_quiet = Set.new
594
596
 
595
597
  # the nick we want, if it's different from the irc.nick config value
596
598
  # (e.g. as set by a !nick command)
@@ -784,24 +786,30 @@ class Bot
784
786
 
785
787
  # checks if we should be quiet on a channel
786
788
  def quiet_on?(channel)
787
- return @quiet.include?('*') || @quiet.include?(channel.downcase)
789
+ ch = channel.downcase
790
+ return (@quiet.include?('*') && !@not_quiet.include?(ch)) || @quiet.include?(ch)
788
791
  end
789
792
 
790
793
  def set_quiet(channel = nil)
791
794
  if channel
792
795
  ch = channel.downcase.dup
796
+ @not_quiet.delete(ch)
793
797
  @quiet << ch
794
798
  else
795
799
  @quiet.clear
800
+ @not_quiet.clear
796
801
  @quiet << '*'
797
802
  end
798
803
  end
799
804
 
800
805
  def reset_quiet(channel = nil)
801
806
  if channel
802
- @quiet.delete channel.downcase
807
+ ch = channel.downcase.dup
808
+ @quiet.delete(ch)
809
+ @not_quiet << ch
803
810
  else
804
811
  @quiet.clear
812
+ @not_quiet.clear
805
813
  end
806
814
  end
807
815
 
@@ -1289,6 +1297,7 @@ class Bot
1289
1297
  m = PrivMessage.new(*args)
1290
1298
  when "QUIT"
1291
1299
  m = QuitMessage.new(*args)
1300
+ m.was_on = myself.channels
1292
1301
  end
1293
1302
  @plugins.delegate('sent', m)
1294
1303
  end
data/lib/rbot/message.rb CHANGED
@@ -195,7 +195,9 @@ module Irc
195
195
  @plainmessage = BasicUserMessage.strip_formatting(@message)
196
196
  @message = BasicUserMessage.strip_initial_formatting(@message)
197
197
 
198
- @address = true if source == @bot.myself
198
+ if target && target == @bot.myself
199
+ @address = true
200
+ end
199
201
 
200
202
  end
201
203
 
@@ -321,8 +323,9 @@ module Irc
321
323
  @ctcp = false
322
324
  @action = false
323
325
 
324
- if @address = (target == @bot.myself)
326
+ if target == @bot.myself
325
327
  @private = true
328
+ @address = true
326
329
  @channel = nil
327
330
  @replyto = source
328
331
  else
@@ -517,6 +520,7 @@ module Irc
517
520
  attr_accessor :is_on
518
521
  def initialize(bot, server, source, oldnick, newnick)
519
522
  super(bot, server, source, oldnick, newnick)
523
+ @address = (source == @bot.myself)
520
524
  @is_on = []
521
525
  end
522
526
 
@@ -540,6 +544,7 @@ module Irc
540
544
  attr_accessor :modes
541
545
  def initialize(bot, server, source, target, message="")
542
546
  super(bot, server, source, target, message)
547
+ @address = (source == @bot.myself)
543
548
  @modes = []
544
549
  end
545
550
 
@@ -554,6 +559,7 @@ module Irc
554
559
  attr_reader :whois
555
560
  def initialize(bot, server, source, target, whois)
556
561
  super(bot, server, source, target, "")
562
+ @address = (target == @bot.myself)
557
563
  @whois = whois
558
564
  end
559
565
 
@@ -624,6 +630,7 @@ module Irc
624
630
  super(bot, server, source, channel, message)
625
631
  @channel = channel
626
632
  # in this case sourcenick is the nick that could be the bot
633
+ @address = (source == @bot.myself)
627
634
  end
628
635
  end
629
636
 
data/po/it/rbot-quotes.po CHANGED
@@ -93,7 +93,7 @@ msgstr "[%{num}] %{quote}"
93
93
 
94
94
  #: data/rbot/plugins/quotes.rb:187
95
95
  msgid "quote %{num} added by %{source}"
96
- msgstr "citazione %{num} aggiunto da %{source}"
96
+ msgstr "citazione %{num} aggiunta da %{source}"
97
97
 
98
98
  #: data/rbot/plugins/quotes.rb:201
99
99
  msgid "quote %{num} added on %{date}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.13
4
+ version: 0.9.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Gilbert
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-02 00:00:00 +02:00
12
+ date: 2008-10-16 00:00:00 +02:00
13
13
  default_executable: rbot
14
14
  dependencies: []
15
15