Class: Plugins::DarkScience

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, Cinch::Helpers, Cinch::Plugin
Defined in:
lib/Zeta/plugins/darkscience.rb

Instance Method Summary collapse

Methods included from Cinch::Plugin

#check?, #log2chan

Instance Method Details

#addquote(m, quote) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/Zeta/plugins/darkscience.rb', line 140

def addquote(m, quote)
  begin
    request = JSON.parse(
        RestClient.post(
            'https://darchoods.net/api/qdb/create',
            {
              auth_token: Config.secrets[:darkscience],
              channel: m.channel,
              author: m.user,
              quote: quote
            }
        )
    )
    quote = Hashie::Mash.new(request)

    m.reply "Quote ##{quote.data.quote.quote_id} added by #{m.user}!"
  rescue RestClient::Unauthorized
    m.action_reply "isn't currently authorized to do that"
  rescue
    m.reply 'QDB is unavailable right now'
  end
end

#finger(msg, nickname) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/Zeta/plugins/darkscience.rb', line 60

def finger(msg, nickname)
  nick = nickname || msg.user.nick

  # JSON request
  begin
    RestClient.proxy = ENV['http_proxy']
    data = JSON.parse(
        RestClient.post(
            'https://darchoods.net/api/irc/user/view',
            {
              auth_token: Config.secrets[:darkscience],
              username: nick,
            }
        )
    )
  rescue RestClient::Unauthorized
    msg.action_reply "isn't currently authorized to do that"
  end

  # Turn JSON into an object
  # request = Hashie::Mash.new(data)


  # Error code replies
  return msg.reply('Finger → User Not Found') if data['data']['user'].empty?
  return msg.reply('Finger → Service Down') if data['status_code'] != 200

  user = data['data']['user']
  stats = data['data']['stats']
  away_msg = data['data']['user']['away_msg'] || "No Message"
  online_last = data['data']['user']['online_last'] || 0

  msg.reply "Finger → #{user['userstring']} ~ " \
            "#{user['identified'] ? 'Identified' : 'Not Identified'} ~ " \
            "Currently in #{stats['channel_count']} channels  ~ " \
            "Seen #{user['online'] ? 'Now' : time_ago_in_words(Time.at(online_last))+ " ago"}  ~ " \
            "Geo: #{user['country']} ~ " \
            "#{user['away'] ? 'Away: ' + away_msg : 'Available' } ~ " \
            "Client: #{user['version']} ~ "
end

#peek(msg, channel) ⇒ Object

Methods



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/Zeta/plugins/darkscience.rb', line 27

def peek(msg, channel)
  chan = channel || msg.user.channel

  # JSON Request
  begin
    RestClient.proxy = ENV['http_proxy']
    data = JSON.parse(
        RestClient.post(
            'https://darchoods.net/api/irc/channel/view',
            {
              auth_token: Config.secrets[:darkscience],
              channel: chan,
            }
        )
    )
  rescue RestClient::Unauthorized
    msg.action_reply "isn't currently authorized to do that"
  end

  # Turn JSON into an object
  request = Hashie::Mash.new(data)

  # Error Code replies
  return msg.reply("Peek → #{request.message}") if request.status_code == 500
  return msg.reply('Peek → Service Down') if request.status_code != 200
  return msg.reply('Peek → Channel Not Found') if request.data.channel.empty?

  msg.reply "Peek → #{request.data.channel.name} (#{request.data.channel.modes}) ~ " \
            "Users: #{request.data.channel.stats.current_users} (#{request.data.channel.stats.peak_users}x̄) ~ " \
            "Last Topic set by #{request.data.channel.topic.author} @ #{Time.at(request.data.channel.topic.time).strftime("%D")}"
end

#quote(m, search) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/Zeta/plugins/darkscience.rb', line 163

def quote(m, search)
  begin
    request = JSON.parse(
        RestClient.post(
            'https://darchoods.net/api/qdb/search/byId',
            {
              auth_token: Config.secrets[:darkscience],
              channel: m.channel,
              quote_id: search
            }
        )
    )
    quote = Hashie::Mash.new(request)

    return m.reply 'There is no quote by that ID' unless quote.data.quote

    m.reply "QDB##{quote.data.quote.quote_id}: #{quote.data.quote.content}"
  rescue RestClient::Unauthorized
    m.action_reply "isn't currently authorized to do that"
  rescue
    m.reply "QDB is unavailable right now"
  end

end

#randomquote(m) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/Zeta/plugins/darkscience.rb', line 188

def randomquote(m)
  begin
    request = JSON.parse(
        RestClient.post(
            'https://darchoods.net/api/qdb/random',
            { auth_token: Config.secrets[:darkscience],
              channel: m.channel
            }
        )
    )
    quote = Hashie::Mash.new(request)

    m.reply "QDB##{quote.data.quote.quote_id}: #{quote.data.quote.content}"
  rescue RestClient::Unauthorized
    m.action_reply "isn't currently authorized to do that"
  rescue
    m.reply "QDB is unavailable right now"
  end

end

#stats(msg, nickname) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/Zeta/plugins/darkscience.rb', line 102

def stats(msg, nickname)
  nick = nickname || msg.user.nick

  # JSON request
  begin
    data = JSON.parse(
        RestClient.post(
            'https://darchoods.net/api/irc/user/view',
            {
              auth_token: Config.secrets[:darkscience],
              username: nick,
            }
        )
    )
  rescue RestClient::Unauthorized
    msg.action_reply "isn't currently authorized to do that"
  end

  # Turn JSON into an object
  # request = Hashie::Mash.new(data)


  # Error code replies
  return msg.reply('Statistics → User Not Found') if data['data']['user'].empty?
  return msg.reply('Statistics → Service Down') if data['status_code'] != 200

  user = data['data']['user']
  stats = data['data']['stats']

  msg.reply "Statistics → #{user['nick']} ~ " \
            "Currently in #{stats['channel_count']} ~ " \
            "Owner of #{stats['mode_counts']['q']} channels ~ " \
            "Admin of #{stats['mode_counts']['a']} channels ~ " \
            "Operator(halfop) of #{stats['mode_counts']['o']}(#{stats['mode_counts']['h']}) channels ~ " \
            "and finally voiced in #{stats['mode_counts']['v']} channels"

end