mirror of https://github.com/bonobonet/botty
Compare commits
2 Commits
46d8847533
...
ab83859175
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | ab83859175 | |
Tristan B. Velloza Kildaire | 94c5403ebd |
|
@ -29,12 +29,14 @@ public class Bot : Client
|
|||
import botty.modules.ping : Ping;
|
||||
import botty.modules.rot13 : Rot13;
|
||||
import botty.modules.translate : Translate;
|
||||
import botty.modules.urbandict : UrbanDict;
|
||||
modules ~= [
|
||||
new DeavmiComedy(this),
|
||||
new EskomCalendarAPI(this),
|
||||
new Ping(this),
|
||||
new Rot13(this),
|
||||
new Translate(this)
|
||||
new Translate(this),
|
||||
new UrbanDict(this)
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* Urban Dictionary module
|
||||
*/
|
||||
module botty.modules.urbandict;
|
||||
|
||||
import botty.mod;
|
||||
import botty.bot : Bot;
|
||||
import birchwood.protocol.messages : Message;
|
||||
|
||||
/**
|
||||
* Urban dictionary command
|
||||
*/
|
||||
public final class UrbanDict : Mod
|
||||
{
|
||||
private static string commandStr = ".ub";
|
||||
|
||||
/**
|
||||
* Base URL to use for constructing requests
|
||||
*/
|
||||
private static string ubBase = "http://api.urbandictionary.com/v0/define?term=";
|
||||
|
||||
/**
|
||||
* Constructs a new `UrbanDict` module with the provided
|
||||
* bot to associate with
|
||||
*
|
||||
* Params:
|
||||
* bot = the `Bot` to associate with
|
||||
*/
|
||||
this(Bot bot)
|
||||
{
|
||||
super(bot);
|
||||
}
|
||||
|
||||
public override bool accepts(Message fullMessage, string channel, string messageBody)
|
||||
{
|
||||
import std.string : startsWith;
|
||||
return messageBody.startsWith(commandStr);
|
||||
}
|
||||
|
||||
public override void react(Message fullMessage, string channel, string messageBody)
|
||||
{
|
||||
import std.string : indexOf, strip;
|
||||
|
||||
import std.stdio;
|
||||
import std.string : split;
|
||||
|
||||
/**
|
||||
* Split the ` .ub dictionarydef`
|
||||
* into two parts `[.ub, dictionarydef]`
|
||||
*/
|
||||
string[] splits = split(strip(messageBody), " ");
|
||||
writeln("splits", splits);
|
||||
|
||||
if(splits.length >= 2)
|
||||
{
|
||||
string searchTerm = splits[1];
|
||||
getBot().channelMessage("hehe", channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue