Class: Cinch::Plugins::Silly

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/silly.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Silly


22
23
24
25
# File 'lib/cinch/plugins/silly.rb', line 22

def initialize *args
  super
  @pokers = {}
end

Instance Attribute Details

#pokersObject (readonly)

Returns the value of attribute pokers


20
21
22
# File 'lib/cinch/plugins/silly.rb', line 20

def pokers
  @pokers
end

Instance Method Details

#execute_botinsult(m) ⇒ Object


50
# File 'lib/cinch/plugins/silly.rb', line 50

def execute_botinsult(m); m.reply ["Stupid human!","Dumb human!","Stupid meatbag.","Silly human, your insults cannot harm me!"].sample if m.user.nick != "TempTina"; end

#heavymetalize(m, s) ⇒ Object


135
136
137
# File 'lib/cinch/plugins/silly.rb', line 135

def heavymetalize(m, s)
  m.reply s.tr('AEIOUaeiouyYWwXx', 'ÄËÏÖÜäëïöüÿŸẄẅẌẍ')
end

#listen_poke(m, thebot) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cinch/plugins/silly.rb', line 28

def listen_poke(m, thebot)
  if User(thebot) == @bot
    @pokers[m.user] = 0 if !@pokers.include?(m.user)
    @pokers[m.user] += 1
    case @pokers[m.user]
    when 1..3
      m.reply "Do NOT poke the bot!"
    when 4
      m.reply "I said, do NOT poke the bot!"
    when 5
      msg = ["WHAT ARE YOU, AN IDIOT? I SAID DO NOT POKE ME!!","THIS! IS! SPARTA!!"].sample
      if m.channel[@bot].any? {|e| (@bot.irc.isupport['PREFIX'] - 'v').include(e) }
        m.channel.kick m.user, ["WHAT ARE YOU, AN IDIOT? I SAID DO NOT POKE ME!!","THIS! IS! SPARTA!!"].sample
      else
        m.reply msg
      end
      @pokers.delete(m.user)
    end
  end
end

#mayan(m) ⇒ Object


121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/cinch/plugins/silly.rb', line 121

def mayan(m)
  msd = (Date.today.jd - Date.new(1,1,1).jd) + 1137142
  lc = {
    baktun: (msd - (msd % 144000)) / 144000,
    katun:  ((msd - (msd % 7200)) / 7200) % 20,
    tun:    ((msd - (msd % 360)) / 360) % 20,
    uinal:  ((msd - (msd % 20)) / 20) % 18,
    kin:    (msd % 20)
  }

  m.reply '%<baktun>s.%<katun>s.%<tun>s.%<uinal>s.%<kin>s' % lc
end

#newyear(m, tz = nil) ⇒ Object


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/cinch/plugins/silly.rb', line 86

def newyear(m, tz = nil)
  tz ||= "-00:00"
  tz = tzparser(tz)
  begin
    today = Time.now.localtime(tz)
    nyear = Time.new(today.year.succ, 1, 1, 0, 0, 0, tz)
    #nyear = nyear.next_year if nyear.to_date.past?
    message = if nyear.to_date == today.to_date
      "Happy New Year #{today.year}!"
    else
      "There's #{ChronicDuration.output(nyear.to_i - today.to_i, format: :long)} until #{nyear.year}!"
    end
  rescue ArgumentError => ae
    message = ae.message
  ensure
    m.reply message, true
  end
end

#tz(m, tz = nil) ⇒ Object


107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/cinch/plugins/silly.rb', line 107

def tz(m, tz = nil)
  tz ||= "-00:00"
  tz = tzparser(tz)
  begin
    today = Time.now.localtime(tz)
    message = today.to_s
  rescue ArgumentError => ae
    message = ae.message
  ensure
    m.reply message, true
  end
end

#tzparser(tz) ⇒ Object


52
53
54
55
56
57
58
59
60
61
# File 'lib/cinch/plugins/silly.rb', line 52

def tzparser(tz)
  prefix = (tz[0] !~ /(\+|-)/ ? "+" : "")
  suffix = (tz =~ /^(?:\+|-)?(\d{1,2})$/ ? ":00" : "")
  regexp = /^(\+|-)?(\d{1,2})(?::(\d{1,2}))?$/
  if tz =~ regexp
    prefix + tz.gsub(regexp) {|match| (!!$1 ? $1 : "") + $2.rjust(2,"0") + (!!$3 ? ":"+$3.rjust(2,"0") : "") } + suffix
  else
    raise ArgumentError, "A valid timezone was not supplied."
  end
end

#xmas(m, tz = nil) ⇒ Object


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cinch/plugins/silly.rb', line 65

def xmas(m, tz = nil)
  tz ||= "-00:00"
  tz = tzparser(tz)
  begin
    today = Time.now.localtime(tz)
    xmas = Time.new(today.year, 12, 25, 0, 0, 0, tz)
    xmas = xmas.next_year if xmas.to_date.past?
    message = if xmas.to_date == today.to_date
      "Merry Christmas!"
    else
      "There's #{ChronicDuration.output(xmas.to_i - today.to_i, format: :long)} until Christmas!"
    end
  rescue ArgumentError => ae
    message = ae.message
  ensure
    m.reply message, true
  end
end