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
|
# File 'lib/lita/adapters/discord_oauth.rb', line 14
def run
Lita.logger.debug('Starting discord_oauth adapter')
@client.ready do |e|
robot.trigger(:connected)
version = Gem.loaded_specs['lita-discord_oauth'].version
@client.game = "Version #{version}"
@client.message do |event|
message = event.message
channel = event.channel.id.to_s
author_id = message.author.id.to_s
if event.channel.pm?
author_name = message.author.username.to_s
else
author_name = message.author.display_name.to_s
end
Lita.logger.debug("Received message from #{author_name}(#{author_id}): #{message.content}")
Lita.logger.debug("Finding user #{author_name}")
user = Lita::User.find_by_name(author_name)
if user == nil
Lita.logger.debug("User #{author_name} not found, trying ID #{author_id}")
user = Lita::User.find_by_id(author_id)
if user != nil
Lita.logger.debug("User #{author_id} found, updating name to #{author_name}")
user = Lita::User.create(author_id, {name: author_name})
end
Lita.logger.debug("User #{author_id} not found, creating now")
user = Lita::User.create(author_id, {name: author_name}) unless user
end
Lita.logger.debug('User ID: ' + user.id)
Lita.logger.debug('Channel ID: ' + channel)
source = Lita::Source.new(user: user, room: channel)
msg = Lita::Message.new(robot, message.content, source)
robot.receive(msg) unless message.from_bot?
end
end
@client.run
end
|