mirror of https://github.com/bonobonet/botty
Compare commits
2 Commits
21329400ec
...
08ce59de5a
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 08ce59de5a | |
Tristan B. Velloza Kildaire | 6b03585b53 |
|
@ -8,6 +8,7 @@ import botty.bot : Bot;
|
||||||
import birchwood.protocol.messages : Message;
|
import birchwood.protocol.messages : Message;
|
||||||
import std.net.curl : CurlException;
|
import std.net.curl : CurlException;
|
||||||
import std.json : JSONValue, JSONException, parseJSON;
|
import std.json : JSONValue, JSONException, parseJSON;
|
||||||
|
import birchwood;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Urban dictionary command
|
* Urban dictionary command
|
||||||
|
@ -45,6 +46,7 @@ public final class UrbanDict : Mod
|
||||||
|
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.string : split;
|
import std.string : split;
|
||||||
|
import std.conv : to, ConvException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split the ` .ub dictionarydef`
|
* Split the ` .ub dictionarydef`
|
||||||
|
@ -54,8 +56,34 @@ public final class UrbanDict : Mod
|
||||||
string[] splits = split(messageBody, " ");
|
string[] splits = split(messageBody, " ");
|
||||||
writeln("splits", splits);
|
writeln("splits", splits);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
if(splits.length >= 2)
|
if(splits.length >= 2)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for `.ub:2`
|
||||||
|
*/
|
||||||
|
ulong count = 0;
|
||||||
|
long countIdx = splits[0].indexOf(":");
|
||||||
|
if(countIdx > -1)
|
||||||
|
{
|
||||||
|
string countStr = splits[0].split(":")[1];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
count = to!(ulong)(countStr);
|
||||||
|
}
|
||||||
|
catch(ConvException e)
|
||||||
|
{
|
||||||
|
getBot().channelMessage("Invalid index '"~countStr~"'", channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
writeln("Are we ongod yet? ",messageBody.indexOf(" "));
|
writeln("Are we ongod yet? ",messageBody.indexOf(" "));
|
||||||
string searchTerm = strip(messageBody[messageBody.indexOf(" ")..$]);
|
string searchTerm = strip(messageBody[messageBody.indexOf(" ")..$]);
|
||||||
writeln("search term: '"~searchTerm~"'");
|
writeln("search term: '"~searchTerm~"'");
|
||||||
|
@ -64,13 +92,15 @@ public final class UrbanDict : Mod
|
||||||
{
|
{
|
||||||
// Perform lookup and parsing
|
// Perform lookup and parsing
|
||||||
JSONValue[] definitions = doThing(searchTerm);
|
JSONValue[] definitions = doThing(searchTerm);
|
||||||
|
writeln("Definitions count: ", definitions.length);
|
||||||
|
writeln("Selecting definition: ", count);
|
||||||
|
|
||||||
if(definitions.length > 0)
|
if(definitions.length > 0)
|
||||||
{
|
{
|
||||||
// TODO: Send result below
|
// TODO: Send result below
|
||||||
// getBot().channelMessage(translatedText, channel);
|
// getBot().channelMessage(translatedText, channel);
|
||||||
|
|
||||||
JSONValue firstDef = definitions[0];
|
JSONValue firstDef = definitions[count];
|
||||||
|
|
||||||
string definition = firstDef["definition"].str();
|
string definition = firstDef["definition"].str();
|
||||||
string example = firstDef["example"].str();
|
string example = firstDef["example"].str();
|
||||||
|
@ -120,6 +150,11 @@ public final class UrbanDict : Mod
|
||||||
writeln("IMM A W ");
|
writeln("IMM A W ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(BirchwoodException e)
|
||||||
|
{
|
||||||
|
writeln("Birchwood error: ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static JSONValue[] doThing(string term)
|
private static JSONValue[] doThing(string term)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue