-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
58 lines (44 loc) · 1.11 KB
/
main.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
# frozen_string_literal: true
require 'bundler/setup'
require 'discordrb'
require 'dotenv'
class Unchimpo
attr_reader :non_overlap
def initialize(non_overlap = generate_non_overlap?)
@non_overlap = non_overlap
end
def input(text)
Unchimpo.new(@non_overlap.call(text))
end
def lose?
!@non_overlap
end
private
def generate_non_overlap?(former = nil)
lambda do |latter|
return generate_non_overlap?(latter) unless violate?(former, latter)
end
end
def violate?(former, latter)
latter == former || !%w[うんち ちんぽ うんちんぽ].include?(latter)
end
end
Dotenv.load
bot = Discordrb::Bot.new token: ENV['UNCHIMPO_TOKEN']
game = nil
bot.message(in: 'トイレ') do |event|
next unless event.content.unicode_normalize == 'うんちんぽ'
if game.nil?
game = Unchimpo.new
event.respond('うんちんぽしりとり!w')
end
end
bot.message(in: 'トイレ') do |event|
next if game.nil?
game = game.input(event.content.unicode_normalize)
if game.lose?
event.respond("#{event.author.mention} お前の負けw")
game = nil
end
end
bot.run