Created
August 18, 2017 15:39
-
-
Save avighnash/a9c9d6bb23e1dace847c88eeec6fc2b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import framework.Command | |
import framework.CommandCanister | |
import framework.CommandHandler | |
import framework.CommandRegister | |
import org.apache.commons.lang3.StringUtils | |
class ExampleCommand { | |
@Command("/math") fun math(canister: CommandCanister) { | |
val args = canister.args | |
if (StringUtils.isNumeric(args[0]) && args[1].toCharArray()[0] is Char && StringUtils.isNumeric(args[2])) { | |
val one = args[0].toDouble() | |
val two = args[2].toDouble() | |
val res: Double | |
when (args[1].toCharArray()[0]) { | |
'+' -> res = one + two | |
'-' -> res = one - two | |
'*' -> res = one * two | |
'/' -> res = one * two | |
else -> res = 0.0 | |
} | |
canister.event.channel.sendMessage(res.toString()) | |
} | |
} | |
} | |
fun main(args: Array<String>) { | |
// do client stuff | |
client!!.dispatcher.registerListener(CommandHandler()) | |
CommandRegister.register(ExampleCommand::class) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment