Last active
December 20, 2015 11:59
-
-
Save azenla/6127658 to your computer and use it in GitHub Desktop.
KenBot v3 base code
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
server { | |
host = 'irc.esper.net' | |
port = 6667 | |
nickname = 'KenBotv3' | |
} | |
bot { | |
channels = ['#Minetweak', '#Minetweak-dev', '#DirectMyFile'] | |
} | |
actions { | |
joinOnInvite = true | |
} |
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
package com.directmyfile.kenbot | |
import org.pircbotx.hooks.ListenerAdapter | |
import org.pircbotx.hooks.events.MessageEvent | |
class BotListener extends ListenerAdapter { | |
def prefix = '!' | |
@Override | |
def void onMessage(MessageEvent event) { | |
def msg = event.message.trim() | |
if (!msg.startsWith(prefix)) {return} | |
def split = msg.split(' ') | |
def cmd = split[0].substring(1) | |
CommandRegistry.run(cmd, event) | |
} | |
} |
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
package com.directmyfile.kenbot | |
class CommandRegistry { | |
static def Map<String, Closure> commands = [:] | |
static def addCommand(String name, Closure closure) { | |
commands[name] = closure | |
} | |
static def run(name, event) { | |
if (!commands.containsKey(name)) {return} | |
def closure = commands.get(name) | |
closure.call(event) | |
} | |
} |
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
package com.directmyfile.kenbot | |
import org.pircbotx.PircBotX | |
class KenBot { | |
def PircBotX manager | |
def BotConfig config | |
KenBot(BotConfig config) { | |
this.config = config | |
def host = config.getServer().get('host') as String | |
def port = config.getServer().get('port') as int | |
def nickname = config.getServer().get('nickname') as String | |
manager = new PircBotX() | |
manager.setName nickname | |
manager.getListenerManager().addListener(new BotListener()) | |
manager.connect(host, port) | |
config.getChannels().each { | |
println 'Joining ' + it | |
manager.joinChannel(it) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment