-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcommon.rb
169 lines (138 loc) · 6.28 KB
/
common.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
58
59
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
100
101
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# coding: utf-8
require 'base64'
require 'net/http'
class Common < Lita::Handler
route(/^xor ([^ ]+) ([^ ]+)/i) do |response|
begin
data = Base64.decode64(response.args[0])
key = Base64.decode64(response.args[1])
output = data.bytes.zip(key.bytes.cycle).map { |x|
x.reduce(:^).chr
}.join
response.reply(output.inspect)
rescue
response.reply("Usage: xor [base64 data] [base64 key]")
end
end
route(/^ici$/i) do |response|
response.reply('et maintenant')
end
route(/ici et maintenant/i) do |response|
response.reply('https://www.youtube.com/watch?v=DMeyvg1M52k')
end
route(/^allo allo$/i) do |response|
if Time.new.to_i.even?
response.reply('Monsieur l\'ordinateur :dorothee:')
else
phrases = ['Just pick up the phone', 'I wonder what they wanna know', 'They wanna know, comme allo allo', 'I just wanna let you know']
response.reply(phrases.sample + ' :telephone_receiver:')
end
end
route(/^lenny$/i) do |response|
response.reply(':lenny1::lenny2:')
end
route(/^lennyorgy$/i) do |response|
response.reply(':lenny1::lenny1::lenny1::lenny2::lenny2::lenny2:')
end
route(/^8ball/i, command: true) do |response|
phrases = ['It is certain', 'It is decidedly so', 'Without a doubt', 'Yes definitely', 'You may rely on it', 'As I see it, yes', 'Most likely', 'Outlook good', 'Yes', 'Signs point to yes', 'Reply hazy try again', 'Ask again later', 'Better not tell you now', 'Cannot predict now', 'Concentrate and ask again', 'Don\'t count on it', 'My reply is no', 'My sources say no', 'Outlook not so good', 'Very doubtful']
response.reply(phrases.sample + ' :8ball:')
end
route(/^montre nous tes fesses$/i, command: true) do |response|
response.reply('( ^◡^)っ (‿|‿)')
end
route(/^koi$/i, command: true) do |response|
response.reply("Je revenais de faire mon voyage de coopération internationale au Sénégal et les filles du groupe me l'on créé ... Confit pour confiture, parce que se salué dans le dialecte cerrer-lala tu dit \"jammm\" comme confiture en anglais et le phil c'était parce que mon nom d'adoption au Sénégal c'était Philippe")
end
route(/^Je revenais de faire mon voyage de coopération internationale au Sénégal et les filles du groupe me l'on créé ... Confit pour confiture, parce que se salué dans le dialecte cerrer-lala tu dit \"jammm\" comme confiture en anglais et le phil c'était parce que mon nom d'adoption au Sénégal c'était Philippe$/i, command: false) do |response|
response.reply("koi")
end
route(/^:arrow_up: :arrow_up: :arrow_down: :arrow_down: :arrow_left: :arrow_right: :arrow_left: :arrow_right: :b: :a:$/i) do |response|
response.reply(":fireworks: Thanks, this Slack workspace has been upgraded to a PREMIUM workspace :fireworks:")
end
route(/^\+1( :[\w\-\+:]+:)?( :[\w\-\+:]+:)?$/, command: true) do |response|
message = '''_0__0__0__0__0__0__0__0__0__0_
_0__0__0__0__0__0__1__0__0__0_
_0__0__0__0__0__1__1__0__0__0_
_0__0__1__0__0__0__1__0__0__0_
_0__1__1__1__0__0__1__0__0__0_
_0__0__1__0__0__0__1__0__0__0_
_0__0__0__0__0__0__1__0__0__0_
_0__0__0__0__0__1__1__1__0__0_
_0__0__0__0__0__0__0__0__0__0_'''
message.gsub!(/_0_/, response.args[0] || ':ship:')
message.gsub!(/_1_/, response.args[1] || ':+1:')
response.reply(message)
end
route(/^-1( :[\w\-\+:]+:)?( :[\w\-\+:]+:)?$/, command: true) do |response|
message = '''_0__0__0__0__0__0__0__0__0__0_
_0__0__0__0__0__0__1__0__0__0_
_0__0__0__0__0__1__1__0__0__0_
_0__0__0__0__0__0__1__0__0__0_
_0__1__1__1__0__0__1__0__0__0_
_0__0__0__0__0__0__1__0__0__0_
_0__0__0__0__0__0__1__0__0__0_
_0__0__0__0__0__1__1__1__0__0_
_0__0__0__0__0__0__0__0__0__0_'''
message.gsub!(/_0_/, response.args[0] || ':ship:')
message.gsub!(/_1_/, response.args[1] || ':-1:')
response.reply(message)
end
LATEX_URL = URI::HTTP.build(host: 'chart.apis.google.com', path: '/chart', fragment:'.png').freeze
route %r(\A(?:tex|latex)(?:\s+me)?\s+(.*)\Z), :latex, command: true do
expression = CGI.escape(response.matches.first.first)
response.reply image_url(expression)
end
route(/countdown/i, command: false) do |response|
count = (Date.new(2020, 03, 13) - Date.today).to_i
count_launch_party = (Date.new(2019, 11, 8) - Date.today).to_i
if count > 1
output = ":cs-games: *#{count} jours* avant les CS Games :cs-games:"
if count_launch_party == 14
output += " et le launch party est dans un :pogslide: fortnight :pogslide: !"
elsif count_launch_party > 1
output += " et le launch party est dans *#{count_launch_party} jours*!"
elsif count_launch_party == 1
output += " :hypnotroll: :pogslide: MAIS LE LAUNCH PARTY C'EST DEMAIN! :pogslide: :hypnotroll:"
elsif count_launch_party == 0
output += " :hypnotroll: :pogslide: MAIS LE LAUNCH PARTY C'EST AUJOURD'HUI! :pogslide: :hypnotroll:"
end
response.reply output
elsif count == 1
response.reply ":cs-games: :hypnotroll: :pogslide: C'EST DEMAIN! :pogslide: :hypnotroll: :cs-games:"
elsif count >= -2
response.reply ":cs-games: :hypnotroll: :pogslide: C'EST AUJOURD'HUI! :pogslide: :hypnotroll: :cs-games:"
else
response.reply ":cs-games: Les CS reviennent l'année prochaine! :cs-games:"
end
end
route(/qualif/i, command: false) do |response|
response.reply "Les qualifs sont le 25 janvier. Parles-en à tes ami-es :slightly_smiling_face:"
end
route(/^kebac (.+)$/i, command: true) do |response|
expression = response.args.join(' ')
response.reply fetch_kebac(expression).force_encoding(Encoding::UTF_8)
end
route(/^mariechantal (.+)$/i, command: true) do |response|
expression = response.args.join(' ')
response.reply fetch_kebac(expression).force_encoding(Encoding::UTF_8).upcase
end
Lita.register_handler(self)
private
def image_url(expression)
LATEX_URL.dup.tap { |url|
url.query = "cht=tx&chl=#{ expression }"
}.to_s
end
def fetch_kebac(expression)
uri = URI('https://agile-scrubland-53958.herokuapp.com')
uri.query = URI.encode_www_form({ :french => expression })
response = Net::HTTP.get_response(uri)
case response
when Net::HTTPSuccess then
response.body
else
'leu sairver neu répon pa ¯\_(ツ)_/¯'
end
end
end