Skip to content

Commit

Permalink
moved register command to the new delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Jun 20, 2015
1 parent 47266f8 commit 2ac738f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
4 changes: 2 additions & 2 deletions grails-app/views/registration/saved.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
One more step remains, but don't worry, it is an easy step.<br>
Go to the Stack Exchange chat room <a href="http://chat.stackexchange.com/rooms/20298/dugas-playground">Duga's Playground</a>
and ping @Duga with a one-time token that has been generated for you:<br>
Write the following in chat: <pre>@Duga register ${key}</pre>
Write the following in chat: <pre>@Duga register '${key}'</pre>
<br>
If successful, @Duga will respond to you.<br>
@Duga should respond to you with the result.<br>
</div>
</body>
</html>
25 changes: 0 additions & 25 deletions src/main/groovy/net/zomis/duga/ChatCommands.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,6 @@ class ChatCommands {
}
}
}
consumers << {ChatMessageIncoming event ->
def command = 'register'
int index = event.content.indexOf(command)
if (index != -1) {
String str = event.content.substring(index + command.length() + 1)
User.withNewSession { status ->
User user = User.findByPingExpect(str)
if (user == null) {
event.reply('No such user found.')
} else {
user.setAccountLocked(false)
user.setChatName(event.user_name)
user.chatId = event.user_id
if (!user.save(failOnError: true, flush: true)) {
event.reply('Unable to save')
info.errors.each {
event.reply it
}
} else {
event.reply('You have been registered!')
}
}
}
}
}
consumers << {ChatMessageIncoming event ->
if (event.content.contains('add stats')) {
DailyInfo.withNewSession { status ->
Expand Down
24 changes: 23 additions & 1 deletion src/main/groovy/net/zomis/duga/tasks/ChatCommandDelegate.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.zomis.duga.tasks

import net.zomis.duga.DugaChatListener
import net.zomis.duga.User
import net.zomis.duga.chat.WebhookParameters

/**
Expand All @@ -17,7 +18,7 @@ class ChatCommandDelegate {
}

Closure ping = {
message.reply('debug pong')
message.reply('pong!')
}

def say(String text) {
Expand All @@ -28,4 +29,25 @@ class ChatCommandDelegate {
}]
}

def register(String githubKey) {
User.withNewSession {status ->
User user = User.findByPingExpect(githubKey)
if (user == null) {
message.reply('No such user found.')
} else {
user.setAccountLocked(false)
user.setChatName(message.user_name)
user.chatId = message.user_id
if (!user.save(failOnError: true, flush: true)) {
message.reply('Unable to save')
user.errors.each {
message.reply it
}
} else {
message.reply('You have been registered!')
}
}
}
}

}

0 comments on commit 2ac738f

Please sign in to comment.