Class: Lita::Handlers::Mailer

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/mailer.rb

Instance Method Summary collapse

Instance Method Details

#body(resp) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/lita/handlers/mailer.rb', line 65

def body(resp)
  args = resp.args.dup
  args.shift # get rid of "body"

  key = args.shift # pop off the key

  email = JSON.parse(redis.get(key))

  email["body"] = args # everything else is the body
  redis.set(key, email.to_json)

  resp.reply_privately "Body for `#{key}` set to: \n #{blockify(email["body"].join(" "))}"
  resp.reply_privately "Next Step: lita mail send #{key}"
end

#check(resp) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/lita/handlers/mailer.rb', line 98

def check(resp)
  args = resp.args.dup
  args.shift # get rid of "check"

  key = args.shift # pop off the key

  email = JSON.parse(redis.get(key))

  out = String.new
  out += email["valid"] ? "Email valid... yes\n" : "Email valid... FALSE\n"
  out += email["list"]  ? "Email list.... yes\n" : "Email list.... FALSE\n"
  out += email["subj"]  ? "Email subj.... yes\n" : "Email subj.... FALSE\n"
  out += email["body"]  ? "Email body.... yes\n" : "Email body.... FALSE\n"

  resp.reply_privately blockify(out)
end

#list(resp) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lita/handlers/mailer.rb', line 35

def list(resp)
  args = resp.args.dup
  args.shift # get rid of "list"

  key = args.shift # pop off the key

  email = JSON.parse(redis.get(key))

  email["list"] = args # everything else is the body
  redis.set(key, email.to_json)

  resp.reply_privately "Mail list for #{key} set to: \n #{blockify(email["list"].join("\n"))}"
  resp.reply_privately "Next Step: lita mail subj #{key} SUBJ"
end

#mail(resp) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lita/handlers/mailer.rb', line 15

def mail(resp)
  key = string_gen

  resp.reply_privately "KEY: `#{key}`"
  resp.reply_privately "Next Step: lita mail list #{key} [email protected]"

  redis.set(key, new_email)

  after(600) do # after 10 minutes, invalidate key
    email = JSON.parse(redis.get(key))
    if email["valid"]
      redis.del(key)
      resp.reply_privately "FYI: Email with key '#{key}' now invalid."
    else
      # Just to make sure that we clean this up
      redis.del(key)
    end
  end
end

#send(resp) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/lita/handlers/mailer.rb', line 80

def send(resp)
  args = resp.args.dup
  args.shift # get rid of "send"

  key = args.shift # pop off the key

  email = JSON.parse(redis.get(key))

  email["list"].each do |recipent|
    Mail.deliver do
      from     '[email protected]'
      to       recipent
      subject  email["subj"].join(" ")
      body     email["body"].join(" ") + "\n\nSent by your friendly Lita Bot"
    end
  end
end

#subj(resp) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/lita/handlers/mailer.rb', line 50

def subj(resp)
  args = resp.args.dup
  args.shift # get rid of "subj"

  key = args.shift # pop off the key

  email = JSON.parse(redis.get(key))

  email["subj"] = args # everything else is the body
  redis.set(key, email.to_json)

  resp.reply_privately "Subject for `#{key}` set to: \n #{blockify(email["subj"].join(" "))}"
  resp.reply_privately "Next Step: lita mail body #{key} STUFF"
end