public IProcessingResult LastPostedImageID(IBot bot, IProcessingResult pr, IChatMessage msg, string arg)
    {
        pr.Solved         = true;
        pr.Respond        = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var v = bot.GetModuleByName("Potato");

        if (v != null)
        {
            var last = (string)v.GetParameter("last posted image url");

            string gris      = @"https://www.google.com/searchbyimage?image_url=";
            string snao      = @"http://saucenao.com/search.php?url=";
            string iqdb      = @"http://iqdb.org/?url=";
            string tin       = @"http://tineye.com/search?url=";
            string imagelink = last;
            string grislink  = gris + imagelink;
            string snaolink  = snao + imagelink;
            string iqdblink  = iqdb + imagelink;
            string tinlink   = tin + imagelink;

            string niceresponse  = "[Google Reverse Image Search](" + grislink + "), [TinEye](" + tinlink + "), [SauceNAO](" + snaolink + "), [iqdb](" + iqdblink + ").";
            string shortresponse = grislink + " | " + tinlink + " | " + snaolink + " | " + iqdblink;

            pr.ResponseText = niceresponse.Length < 500 ? niceresponse : shortresponse;
        }

        return(pr);
    }
    IProcessingResult AliasAdd(IProcessingResult pr, IBot bot, IChatMessage msg, string command, string alias, bool overwrite)
    {
        var ca = bot.CommandAliases;
        var c  = command;
        var a  = alias;

        if (!overwrite)
        {
            if (ca.ContainsKey(a))
            {
                var cmdname = ca[a];

                pr.ResponseText = "Command *" + cmdname + "* was already aliased to *" + a + "*. If you want to overwrite it, add \"-overwrite\" or \"-o\" to your request.";
                return(pr);
            }
        }

        if (c.Contains("alias") || a.Contains("alias") || c == a || commandsList.Contains(a)) // sanity check
        {
            pr.ResponseText = "You can't do that.";
            return(pr);
        }

        // just set
        ca[a] = c;
        Log("[+] Added new alias: \"" + alias + "\" for command \"" + command + "\".");

        pr.ReplyMessageID = msg.MessageID;
        pr.ResponseText   = "Command *" + c + "* was aliased to *" + a + "*";
        return(pr);
    }
Esempio n. 3
0
    IProcessingResult ManualPost(IBot bot, IProcessingResult pr, IChatMessage msg, string arg)
    {
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.Respond        = true;
        pr.Solved         = true;

        if (msg.RoomID != bot.MainRoomID)
        {
            pr.ResponseText   = "*This feature is intended to work in the [main room](" + @"http://chat.stackexchange.com/rooms/6697/maid-cafe-" + ") only.*";
            pr.ReplyMessageID = msg.MessageID;
            pr.TargetRoomID   = msg.RoomID;

            return(pr);
        }

        if (string.IsNullOrEmpty(arg))
        {
            pr = PostRandomPotato(bot, pr);
        }
        else
        {
            pr = PostPotatoTagged(bot, pr, msg, arg);
        }

        return(pr);
    }
        public async Task SendResponse(IProcessingResult result)
        {
#if WINDEBUG
            if (result.WebSocketMessages != null && WebSocket.IsRunning)
            {
                var   sendingTask = SendWebSocketMessages(result.WebSocketMessages);
                await sendingTask;
            }
#else
            var sendingTasks = new Task[2] {
                Task.FromResult(true), Task.FromResult(true)
            };

            if (!UnixSocket.IsRunning)
            {
                log.Error("Unix socket is not running!");
            }

            if (result.SmartBrickMessages != null && UnixSocket.IsRunning)
            {
                sendingTasks[0] = SendUnixSocketMessages(result.SmartBrickMessages);
            }
            if (result.WebSocketMessages != null && WebSocket.IsRunning)
            {
                sendingTasks[1] = SendWebSocketMessages(result.WebSocketMessages);
            }

            await Task.WhenAll(sendingTasks);
#endif
        }
Esempio n. 5
0
        public IProcessingResult ProcessMessage(IBot bot, IProcessingResult pr, IChatMessage msg)
        {
            if (!CheckIfMessageShouldBeProcessed(bot, pr, msg))
            {
                pr.Solved = true;
                return(pr);
            }

            var txt = Helper.RemoveBotNamesAndTriggerSymbol(bot.Name, msg.Text, bot.TriggerSymbol);

            var w1  = Helper.FirstWord(txt);
            var cmd = w1.ToLowerInvariant();
            var arg = Helper.TextAfter(txt, w1).Trim();

            pr = InvokeExplicitCommand(bot, pr, msg, cmd, arg);

            if (pr.SolvedSet && pr.Solved)
            {
                return(pr);
            }

            pr = InvokeImplicitCommand(bot, pr, msg, cmd, arg);

            if (pr.SolvedSet && pr.Solved)
            {
                return(pr);
            }

            pr = CheckIfIProcessingResultIsOkay(bot, pr, msg);

            return(pr);
        }
Esempio n. 6
0
    IProcessingResult PostPotatoTagged(IBot bot, IProcessingResult pr, IChatMessage msg, string tag)
    {
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.Respond        = true;
        pr.Solved         = true;

        // find alias
        string aliasedOriginalTag = null;

        if (tagAliasesDic.ContainsKey(tag))
        {
            aliasedOriginalTag = tagAliasesDic[tag];
        }

        // find all images with that tag

        var list = new List <TaggedImage>();

        foreach (var ti in unpostedImages)
        {
            if (ti.tag != null)
            {
                if (ti.tag == tag || ti.tag == aliasedOriginalTag)
                {
                    list.Add(ti);
                }
            }
        }

        if (list.Count < 1)
        {
            return(PostRandomPotato(bot, pr));
        }
        else
        {
            // post random pic from list and do the rest as usual

            // get a random link to post
            var n         = r.Next(list.Count);
            var nextImage = list[n];
            nextLink = nextImage;

            // set it
            pr.ResponseText = nextLink.url;
            pr.TargetRoomID = msg.RoomID;

            // move image from one list to another
            unpostedImages.Remove(nextImage);
            postedImages.Add(nextImage);

            lastPostedImage = nextLink;

            dt_LastMessageTime = DateTime.Now;
            SetLastMessageIDWhenPosted(bot, msg.RoomID);

            Save();

            return(pr);
        }
    }
Esempio n. 7
0
    // admins can rename any tags
    // uploaders can rename their own tags (warn about merging with existing tag pool)
    // remove all images uploaded by userid
    // ban userid from uploading (admin rights)

    IProcessingResult Tag(IProcessingResult pr, IChatMessage msg, string arg)
    {
        /// _______ arg1
        // #post tag ghost in the shell = gits
        // #post tag jintai += jinrui wa suitai shimashita

        // #post tag remove naruto shipuuden
        // #post tag -= kuroko basket


        if (arg.Contains(" = "))
        {
            var add1W1 = Helper.TextBefore(arg, " = ").ToLowerInvariant();
            var add1W2 = Helper.TextAfter(arg, " = ").ToLowerInvariant();

            return(TagAdd(pr, msg, add1W1, add1W2));
        }

        var arg1 = Helper.FirstWord(arg);
        var rest = Helper.TextAfter(arg, arg1).Trim();

        switch (arg1)
        {
        case "":
        case "*": return(TagPostAll(pr, msg));

        case "alias":
        case "aliases": return(TagPostAllAliases(pr, msg, rest));

        case "remove": return(TagRemove(pr, msg, rest));
        }

        pr.ResponseText = "Unexpected argument. Refer to manual for help.";
        return(pr);
    }
    // ext

    public IProcessingResult Meme(IBot bot, IProcessingResult pr, IChatMessage msg, string arg)
    {
        pr.Solved         = true;
        pr.Respond        = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var w1   = Helper.WordNumberN(arg, 1);
        var rest = Helper.TextAfter(arg, w1);
        var w2   = "";
        var w3   = "";

        var reg     = new Regex("\".*?\"");
        var matches = reg.Matches(rest);

        if (matches.Count < 1)
        {
            pr.ResponseText = "You must provide some text, or else the image will return unmodified.";
            return(pr);
        }

        w2 = matches[0].Value.Trim('"');

        if (matches.Count == 2) // could be only top text
        {
            w3 = matches[1].Value.Trim('"');
        }


        var response = Thing(w1, w2, w3);

        pr.ResponseText = response.Result.ToString();

        return(pr);
    }
    IProcessingResult Alias_case_Delete(IProcessingResult pr, IBot bot, IChatMessage msg, string args)
    {
        var wc = Helper.WordCount(args);
        var w2 = Helper.WordNumberN(args, 2);
        var ca = bot.CommandAliases;

        if (wc < 1)
        {
            pr.ResponseText = "Specify which alias you want to remove.";
            return(pr);
        }
        if (wc > 1)
        {
            return(AliasesDelete(pr, bot, msg, args));
        }
        else
        {
            if (ca.ContainsKey(w2)) /// uhh wut?
            {
                return(AliasDelete(pr, bot, msg, w2));
            }
            else
            {
                pr.ResponseText = "There was no such alias defined.";
                return(pr);
            }
        }
    }
Esempio n. 10
0
    public IProcessingResult Modules(IBot bot, IProcessingResult pr)
    {
        pr.Solved         = true;
        pr.Respond        = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);


        // get all module files and their build date

        var modules = bot.GetLoadedModules();

        if (modules.Count < 1)
        {
            pr.ResponseText = "No modules loaded. This is very bad.";
            return(pr);
        }

        var ret = "List of " + modules.Count + " loaded modules (name − build date):" + Environment.NewLine;

        foreach (var module in modules)
        {
            ret += module.Name + " − " + module.BuildDate + Environment.NewLine;
        }



        pr.ResponseText = ret;
        return(pr);
    }
Esempio n. 11
0
    IProcessingResult AliasList(IProcessingResult pr, IBot bot, IChatMessage msg, string args)
    {
        var ca = bot.CommandAliases;
        var w2 = Helper.WordNumberN(args, 2);

        var aliases = new List <string>();

        foreach (var a in ca)
        {
            if (a.Value == w2)
            {
                aliases.Add(a.Key);
            }
        }

        if (aliases.Count == 0)
        {
            pr.ResponseText = "Command *" + w2 + "* does not have any aliases.";
            return(pr);
        }

        var txt1  = string.Join(", ", aliases);
        var reply = "Command *" + w2 + "* has ";

        if (txt1 != "")
        {
            reply += aliases.Count + " aliases: " + txt1;
        }
        reply += ".";

        pr.ReplyMessageID = msg.MessageID;
        pr.ResponseText   = reply;
        return(pr);
    }
Esempio n. 12
0
    public IProcessingResult Add(IBot bot, IProcessingResult pr, IChatMessage msg, string arg)
    {
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.Respond        = true;
        pr.Solved         = true;

        if (arg == "")
        {
            pr.ResponseText = "*Argument cannot be empty.*";
            return(pr);
        }

        Log("[…] Processing argument.");

        string link = null;
        string tag  = null;

        var words = arg.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

        if (words.Length > 0)
        {
            link = words[0].Trim();
        }

        if (words.Length > 1)
        {
            tag = Helper.TextAfter(arg, link).Trim();
        }

        return(AddTextFileLinks(bot, pr, msg, link, tag));

        //pr.ResponseText = "You can only add raw text files with image links on each line. Make sure the url ends with `.txt` or contains `pastebin.com/raw.php?i=`.";
        //return pr;
    }
Esempio n. 13
0
    IProcessingResult AliasListAll(IProcessingResult pr, IBot bot, IChatMessage msg)
    {
        var ca = bot.CommandAliases;

        var oad = new Dictionary <string, List <string> >();

        foreach (var kvp in ca)
        {
            if (!oad.ContainsKey(kvp.Value))
            {
                oad[kvp.Value] = new List <string>();
            }
            oad[kvp.Value].Add(kvp.Key);
        }

        string reply = "List of all " + ca.Count + " command aliases:" + Environment.NewLine;

        foreach (var list in oad)
        {
            reply += "[" + list.Key + "] " + string.Join(", ", list.Value) + Environment.NewLine;
        }

        reply  = reply.Substring(0, reply.Length - 2);
        reply += ".";

        pr.ReplyMessageID = msg.MessageID;
        pr.ResponseText   = reply;
        return(pr);
    }
Esempio n. 14
0
    IProcessingResult Alias_case_List(IProcessingResult pr, IBot bot, IChatMessage msg, string args)
    {
        var ca = bot.CommandAliases;
        var wc = Helper.WordCount(args);
        var w2 = Helper.WordNumberN(args, 2);

        if (ca.Count < 1)
        {
            pr.ResponseText = "There are no aliases currently set.";
            return(pr);
        }

        if (wc > 2)
        {
            pr.ResponseText = "You typed too many words in that request.";
            return(pr);
        }

        if (w2 == "*")
        {
            return(AliasListAll(pr, bot, msg));
        }

        return(AliasList(pr, bot, msg, args));
    }
Esempio n. 15
0
    public IProcessingResult Isch(IBot bot, IProcessingResult pr, IChatMessage msg, string arg)
    {
        pr.Solved         = true;
        pr.Respond        = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var ts = bot.TriggerSymbol;

        string link        = @"https://www.google.com/search?tbm=isch&q=";
        string unparsedtxt = msg.Text;
        string firstw      = Helper.FirstWord(unparsedtxt);
        string args        = unparsedtxt.Replace(firstw, "");

        args = System.Web.HttpUtility.UrlEncode(args);
        var    words = args.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
        string slink = link + string.Join("+", words);

        pr.ResponseText = "[Google Image Search](" + slink + ").";

        if (string.IsNullOrEmpty(arg))
        {
            pr.ResponseText = "Which images do you want to find? Say `" + ts + "isch anime vampire loli` to get the relevant image search results.";
        }

        return(pr);
    }
Esempio n. 16
0
        private bool CheckIfMessageShouldBeProcessed(IBot bot, IProcessingResult pr, IChatMessage msg)
        {
            if (msg.UserID == bot.UserID)
            {
                return(false);
            }

            if (bot.BannedUserIDs.Contains(msg.UserID))
            {
                return(false);
            }

            // if msg.replyMID is to a bot's message, then it's true
            var owns = GetOwnMessagesFromTranscript();

            foreach (var own in owns)
            {
                if (own.MessageID == msg.ReplyMessageID && own.UserID == this.UserID)
                {
                    pr.RespondIfUnrecognized = false;
                    return(true);
                }
            }

            bool b = false;
            var  n = Helper.MessageContainsBotNameOrBeginsWithTriggerSymbol(bot.Name, msg.Text, bot.TriggerSymbol);

            switch (n)
            {
            case 0:
            {
                Log("[−] " + msg.MessageID + " Message didn't address bot.");
                b = false;
                break;
            }

            case 1:
            {
                Log("[!] " + msg.MessageID + " Message didn't address bot, but contained bot's name.");
                b = false;
                break;
            }

            case 2:
            {
                Log("[@] " + msg.MessageID + " Message directly addresses bot: \"" + msg.GetMaxDescription() + "\"");
                b = false;
                break;
            }

            case 3:
            {
                Log("[" + bot.TriggerSymbol + "] " + msg.MessageID + " Message starts with trigger symbol " + bot.TriggerSymbol + ": \"" + msg.GetMaxDescription() + "\"");
                b = true;
                break;
            }
            }
            return(b);
        }
Esempio n. 17
0
    public new IProcessingResult Command(IBot bot, IProcessingResult pr, IChatMessage msg, string cmd, string arg, string cmdOriginal, string argOriginal)
    {
        switch (cmd)
        {
            default: return pr;

            // core commands

            case "about": return About(bot, pr, arg);
            case "help": return Help(bot, pr, arg);
            case "commands": return GetCommandList(bot, pr, arg);
            case "uptime": return Uptime(bot, pr);
            case "modules": return Modules(bot, pr);

            case "edit": return Edit(pr, bot, msg, arg);
            case "unonebox":
            case "unbox": return Unonebox(pr, bot, msg, arg);
            case "undo": return Undo(bot, pr, arg);

            case "status": return Status(bot, pr);

            case "trust": return TrustedUsers(bot, pr, arg);
            case "ignore": return BannedUsers(bot, pr, arg);

            case "say": return Say(pr, arg);
            case "tell": return Tell(pr, arg);

            case "alias": return Alias(pr, bot, msg, arg);

            case "save": return Save(bot, pr, msg.UserID);
            case "shutdown": return Shutdown(bot, pr, arg, msg.UserID);


            // hoihoi-san borrowed

            case "google": return Google(pr, msg, arg);
            case "wiki": return Wiki(pr, msg, arg);
            case "urban": return Urban(pr, msg, arg);
            case "youtube": return Youtube(pr, msg, arg);
            case "weather": return Weather(pr, msg, arg);


            // advanfaged

            case "id": return ID(bot, pr, msg, arg);
            case "isch": return Isch(bot, pr, msg, arg);

            case "whois":
            case "what":
            case "last": return LastPostedImageID(bot, pr, msg, arg);


            // bonus

            case "hats": return Hats(pr);
            case "meme": return Meme(bot, pr, msg, arg);

        }
    }
Esempio n. 18
0
 public IProcessingResult Enable(IProcessingResult pr)
 {
     Enabled = true;
     pr.Solved = true;
     pr.Respond = true;
     pr.ResponseText = "*Enabled module " + Name + "*";
     return pr;
 }
Esempio n. 19
0
 public IProcessingResult Help(IBot bot, IProcessingResult pr, string arg)
 {
     pr.Solved         = true;
     pr.Respond        = true;
     pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
     pr.ResponseText   = "Check [this meta post on Anime&Manga.SE](http://meta.anime.stackexchange.com/q/1166/) or ask around at Maid Café!";
     return(pr);
 }
Esempio n. 20
0
 public IProcessingResult Disable(IProcessingResult pr)
 {
     Enabled         = false;
     pr.Solved       = true;
     pr.Respond      = true;
     pr.ResponseText = "*Disabled module " + Name + "*";
     return(pr);
 }
Esempio n. 21
0
    // bonus
    public IProcessingResult Hats(IProcessingResult pr)
    {
        pr.Solved         = true;
        pr.Respond        = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.ResponseText   = "Burn the hats.";

        return(pr);
    }
Esempio n. 22
0
    public IProcessingResult Weather(IProcessingResult pr, IChatMessage msg, string arg)
    {
        pr.Solved         = true;
        pr.Respond        = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.ResponseText   = "!!tell :" + msg.MessageID + " weather " + arg;

        return(pr);
    }
Esempio n. 23
0
    IProcessingResult TagPostAll(IProcessingResult pr, IChatMessage msg)
    {
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.Respond        = true;
        pr.Solved         = true;
        pr.ReplyMessageID = msg.MessageID;

        // make a list of all categories
        var tagPoolDic = new Dictionary <string, int>();
        var uncat      = 0;

        foreach (var ti in unpostedImages)
        {
            var cat = ti.tag;

            if (cat == null)
            {
                uncat++;
            }
            else
            if (!tagPoolDic.ContainsKey(cat))
            {
                tagPoolDic[cat] = 1;
            }
            else
            {
                tagPoolDic[cat]++;
            }
        }

        if (tagPoolDic.Count < 1)
        {
            pr.ResponseText = "There are no images with categories set in unposted images list.";
            return(pr);
        }

        var r = "There are " + unpostedImages.Count + " unposted images in " + tagPoolDic.Count + " tagged lists: ";

        if (uncat > 0)
        {
            r += "(untagged − " + uncat + "); ";
        }

        var sorted = GetTagPoolItemCountsDescending(tagPoolDic);

        foreach (var cat in sorted)
        {
            r += cat.Key + " − " + cat.Value + "; ";
        }

        r = r.Substring(0, r.Length - 2) + "."; // replace last ; with .

        pr.ResponseText = r;

        return(pr);
    }
Esempio n. 24
0
    public new IProcessingResult Disable(IProcessingResult pr)
    {
        Enabled = false;

        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.ResponseText   = Name + " module disabled.";
        pr.Respond        = true;
        pr.Solved         = true;

        return(pr);
    }
Esempio n. 25
0
    //public IProcessingResult Invite(IProcessingResult pr, string arg) // under construction
    //{
    //    pr.Solved = true;
    //    pr.Respond = false;
    //    pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
    //    //pr.ResponseContent = "status message";
    //    pr.Result = IProcessingResultType.Default;
    //    //ResponseText = "Uptime: " + Helper.GetUptime(Bot.initTime) + ". Firefox memory use: "
    //    //pr.ResponseText = "(not implemented yet)";


    //    //{

    //    //}

    //    return pr;
    //}

    public IProcessingResult TrustedUsers(IBot bot, IProcessingResult pr, string arg) // ugh…
    {
        pr.Solved         = true;
        pr.Respond        = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        pr.ResponseText = "*Not implemented*";

        //ResponseType = MessageType.Success,
        //ResponseContent = "listcommands"

        //var ts = bot.TriggerSymbol;

        //var w1 = Helper.FirstWord(arg);
        //switch (w1)
        //{
        //    case "*":
        //    case "list":
        //    case "all":
        //        {
        //            pr.ResponseText = "Trusted user IDs: " + string.Join(", ", bot.TrustedUserIDs) + ".";
        //            return pr;
        //        }

        //    case "add":
        //        {
        //            pr.ResponseText = "This isn't implemented yet.";
        //            return pr;
        //        }
        //    case "remove":
        //        {
        //            pr.ResponseText = "This isn't implemented yet.";
        //            return pr;
        //        }
        //    case "change": // change trust level (specific commands?)
        //        {
        //            pr.ResponseText = "This isn't implemented yet.";
        //            return pr;
        //        }
        //    case "find":
        //        {
        //            pr.ResponseText = "This isn't implemented yet.";
        //            return pr;
        //        }

        //    default:
        //        {
        //            pr.ResponseText = "Command `trust` requires one of the following parameters: list, add, remove, change, find. Say `" + ts + "help trust` for more info.";
        //            return pr;
        //        }
        //}

        return(pr);
    }
Esempio n. 26
0
    public IProcessingResult Say(IProcessingResult pr, string arg) // looks fine
    {
        pr.Solved         = true;
        pr.Respond        = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        //ResponseType = MessageType.Success,
        //ResponseContent = "listcommands"

        pr.ResponseText = Helper.ReplaceChatTags(Helper.UnescapeChatMessages(arg));

        return(pr);
    }
Esempio n. 27
0
        private IProcessingResult CheckIfIProcessingResultIsOkay(IBot bot, IProcessingResult pr, IChatMessage msg)
        {
            // if it hasn't been changed, it's probably unknown
            if (pr.Respond == false &&
                pr.ResponseText == "")
            {
                Log("[?] Don't know what to do with this message (processing result has not been changed by any processing methods since instantiation).");

                pr.Solved         = true; // not really solved, but yeah
                pr.ReplyMessageID = msg.MessageID;

                if (pr.RespondIfUnrecognized)
                {
                    pr.Respond = true;
                }

                var replies = new string[] {
                    "I don't know how to deal with this message.", "I don't understand your request.", "I don't know that command.",
                    "Looks like there is no such command.",

                    "I think your syntax might be wrong.", "Perhaps you mistyped something.", "You probably made a typo in that command.",

                    "That's not a command I understand.",
                    "I don't get it.", "I don't understand what you mean by that.", "I'm not sure what that means.",
                    "It doesn't make perfect sense.", "This doesn't make sense.", "It's not making a lot of sense.", "Something about sense not being made.",

                    "You gotta post a correct command.", "You must type a proper request.", "That command is not correct.",
                    "I'm not completely sure what you meant by that, and I am not allowed to guess.",

                    "This is not how you request pictures.", "That is not a correct way to ask for images.", "It's not how you order more pictures.",

                    "If you want to bind that to a " + bot.TriggerSymbol + "post command, you have to edit-post that again.",

                    "Did you mean \"!!lolis\"?", "Could you rephrase your request?", "Perhaps you want me to `" + bot.TriggerSymbol + "post` a picture?",
                };

                pr.ResponseText = Helper.RandomItem(replies.ToList());

                return(pr);
            }
            else
            {
                if (!pr.SolvedSet)
                {
                    pr.Solved       = true;
                    pr.Respond      = true;
                    pr.ResponseText = "*error: processing result's `solved` attribute was unset*";
                    return(pr);
                }
            }
            return(pr);
        }
Esempio n. 28
0
    public IProcessingResult Tell(IProcessingResult pr, string arg) // not implemented
    {
        pr.Solved         = true;
        pr.Respond        = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var w1    = Helper.FirstWord(arg);
        var wrest = Helper.TextAfter(arg, w1).Trim();

        pr.ResponseText = "@" + w1 + " " + wrest;

        return(pr);
    }
Esempio n. 29
0
        private SoapResultDescription ConvertToSoapResult(IProcessingResult<XElement> result)
        {
            var executed =
                from ecr in result.ExecutedCommandResults
                let data = ecr.Result.Data
                select SoapCommandResultDescription.Create(
                    ecr.RequestID,
                    ecr.Result.Status,
                    ecr.Result.Message,
                    data != null ? data.ToString() : null);

            return SoapResultDescription.Create(result.Message, executed.ToArray());
        }
Esempio n. 30
0
    IProcessingResult LastPostedImageInfo(IProcessingResult pr, IChatMessage msg)
    {
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.Respond        = true;
        pr.Solved         = true;
        pr.ReplyMessageID = msg.MessageID;

        var ti = lastPostedImage;

        pr.ResponseText = GetLastPostedImageInfo();

        return(pr);
    }
Esempio n. 31
0
        public async Task SaveAsync(IProcessingResult result, CancellationToken token)
        {
            using var context = new OutputContext(_dbSettings);

            var newResult = new ProcessingResult
            {
                ProcessingResultValue = result.GetStringRepresentation()
            };

            await context.ProcessingResults.AddAsync(newResult, token);

            await context.SaveChangesAsync(token);
        }
Esempio n. 32
0
        private SoapResultDescription ConvertToSoapResult(IProcessingResult <XElement> result)
        {
            var executed =
                from ecr in result.ExecutedCommandResults
                let data = ecr.Result.Data
                           select SoapCommandResultDescription.Create(
                    ecr.RequestID,
                    ecr.Result.Status,
                    ecr.Result.Message,
                    data != null?data.ToString() : null);

            return(SoapResultDescription.Create(result.Message, executed.ToArray()));
        }
Esempio n. 33
0
        /// <summary>
        /// Handle the <see cref="IProcessingResult" /> from the procssing of a <see cref="StreamEvent" />..
        /// </summary>
        /// <param name="processingResult">The <see cref="IProcessingResult" />.</param>
        /// <param name="processedEvent">The processed <see cref="StreamEvent" />.</param>
        /// <param name="currentState">The current <see cref="IStreamProcessorState" />.</param>
        /// <returns>A <see cref="Task" /> that, when resolved, returns the new <see cref="IStreamProcessorState" />.</returns>
        protected Task <IStreamProcessorState> HandleProcessingResult(IProcessingResult processingResult, StreamEvent processedEvent, IStreamProcessorState currentState)
        {
            if (processingResult.Retry)
            {
                return(OnRetryProcessingResult(processingResult as FailedProcessing, processedEvent, currentState));
            }
            else if (!processingResult.Succeeded)
            {
                return(OnFailedProcessingResult(processingResult as FailedProcessing, processedEvent, currentState));
            }

            return(OnSuccessfulProcessingResult(processingResult as SuccessfulProcessing, processedEvent, currentState));
        }
Esempio n. 34
0
    public IProcessingResult Edit(IProcessingResult pr, IBot bot, IChatMessage msg, string arg)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var editablePosts = bot.GetStillEditableMessages();

        if (editablePosts.Count < 1)
        {
            pr.ResponseText = "2 minutes have passed since last message was posted, apparently. Can't edit or delete it myself now.";
            pr.ReplyMessageID = msg.MessageID;
        }

        var wc = Helper.WordCount(arg);

        if (wc < 2)
        {
            pr.ResponseText = "You must specify a messageid and the new message text with a space between them.";
            return pr;
        }

        var a1 = Helper.FirstWord(arg).Trim().TrimStart(':');
        var wrest = Helper.TextAfter(arg, a1);

        if (a1.ToLowerInvariant() == "last")
        {
            pr.OwnResponseMessageIDToEdit = editablePosts[0].MessageID;
            pr.ResponseText = wrest;
        }
        else
        {
            int mid = 0;
            if (int.TryParse(a1, out mid))
            {

                pr.OwnResponseMessageIDToEdit = mid;
                pr.ResponseText = wrest;
            }
            else
            {
                pr.ResponseText = "Could not parse messageid.";
                return pr;
            }
        }

        return pr;
    }
Esempio n. 35
0
    public IProcessingResult Modules(IBot bot, IProcessingResult pr)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);


        // get all module files and their build date

        var modules = bot.GetLoadedModules();

        if (modules.Count < 1)
        {
            pr.ResponseText = "No modules loaded. This is very bad.";
            return pr;
        }

        var ret = "List of " + modules.Count + " loaded modules (name − build date):" + Environment.NewLine;
        foreach (var module in modules)
            ret += module.Name + " − " + module.BuildDate + Environment.NewLine;



        pr.ResponseText = ret;
        return pr;
    }
Esempio n. 36
0
    public IProcessingResult Alias(IProcessingResult pr, IBot bot, IChatMessage msg, string arg)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        // w1      // set         // list      // remove
        // w2      // post       // post    // asd, 
        // w3      // tomato   //           // fasd,

        var wc = Helper.WordCount(arg);
        var w1 = Helper.FirstWord(arg);
        var args = Helper.TextAfter(arg, w1).Trim();

        var ts = bot.TriggerSymbol;
        var ca = bot.CommandAliases;

        switch (w1)
        {
            //case "*":
            //case "list":
            case "all":
            case "list":
                return Alias_case_List(pr, bot, msg, args);

            case "learn":
            case "add":
            case "set":
                return Alias_case_Add(pr, bot, msg, args);


            case "forget":
            case "remove":
            case "delete":
            case "unset":
                return Alias_case_Delete(pr, bot, msg, args);

            default:
                return Alias_case_Default(pr, bot, msg, args);
        }
    }
Esempio n. 37
0
    // bonus
    public IProcessingResult Hats(IProcessingResult pr)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.ResponseText = "Burn the hats.";

        return pr;
    }
Esempio n. 38
0
    public IProcessingResult Shutdown(IBot bot, IProcessingResult pr, string arg, int userid)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.ResponseText = "This command is limited to trusted users. Let's hope they won't abuse it.";

        if (bot.TrustedUserIDs != null && bot.TrustedUserIDs.Contains(userid) ||
            userid == int.MinValue)
        {
            Log("[X] Shutdown initiated by userid " + userid + " with reason " + arg + ". Shutting down.");
            //DebugLogManager.Save();
            bot.SoftShutdown(arg);
            return pr; // it won't really be posted
        }

        return pr;
    }
Esempio n. 39
0
    public IProcessingResult Uptime(IBot bot, IProcessingResult pr)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var now = DateTime.UtcNow;
        var then = bot.StartTimeUTC;
        var diff = now - then;

        pr.ResponseText = "Bot app was launched at " + then + " (UTC), and has been running for " + diff + ".";

        return pr;
    }
Esempio n. 40
0
    IProcessingResult Alias_case_Add(IProcessingResult pr, IBot bot, IChatMessage msg, string args)
    {
        var wc = Helper.WordCount(args);

        var a1 = Helper.WordNumberN(args, 1);
        var a2 = Helper.WordNumberN(args, 2);
        var wrest = Helper.TextAfter(args, a2);

        var ts = bot.TriggerSymbol;
        var ca = bot.CommandAliases;

        // currently only accepting 1 at a time

        if (wc < 2)
        {
            pr.ResponseText = "You must provide both target command name and at least one alias.";
            return pr;
        }

        if (wc > 2) // multiple aliases
        {
            bool o = false;
            if (args.EndsWith(" -overwrite") || args.EndsWith(" -o"))
                o = true;

            return AliasAdd(pr, bot, msg, a1, a2, wrest, o);
        }

        // one alias
        if (wc == 2 || (wc == 3 && (args.EndsWith("-o") || args.EndsWith("-overwrite"))))
        {
            bool o = false;
            if (args.EndsWith(" -overwrite") || args.EndsWith(" -o"))
                o = true;

            return AliasAdd(pr, bot, msg, a1, a2, o);
        }

        Log("[!] Unexpected!");
        pr.ResponseText = "(this was not supposed to happen)";
        return pr;
    }
Esempio n. 41
0
    IProcessingResult AliasList(IProcessingResult pr, IBot bot, IChatMessage msg, string args)
    {
        var ca = bot.CommandAliases;
        var w2 = Helper.WordNumberN(args, 2);

        var aliases = new List<string>();
        foreach (var a in ca)
            if (a.Value == w2)
                aliases.Add(a.Key);

        if (aliases.Count == 0)
        {
            pr.ResponseText = "Command *" + w2 + "* does not have any aliases.";
            return pr;
        }

        var txt1 = string.Join(", ", aliases);
        var reply = "Command *" + w2 + "* has ";
        if (txt1 != "")
            reply += aliases.Count + " aliases: " + txt1;
        reply += ".";

        pr.ReplyMessageID = msg.MessageID;
        pr.ResponseText = reply;
        return pr;
    }
Esempio n. 42
0
    IProcessingResult AliasListAll(IProcessingResult pr, IBot bot, IChatMessage msg)
    {
        var ca = bot.CommandAliases;

        var oad = new Dictionary<string, List<string>>();

        foreach (var kvp in ca)
        {
            if (!oad.ContainsKey(kvp.Value))
                oad[kvp.Value] = new List<string>();
            oad[kvp.Value].Add(kvp.Key);
        }

        string reply = "List of all " + ca.Count + " command aliases:" + Environment.NewLine;

        foreach (var list in oad)
            reply += "[" + list.Key + "] " + string.Join(", ", list.Value) + Environment.NewLine;

        reply = reply.Substring(0, reply.Length - 2);
        reply += ".";

        pr.ReplyMessageID = msg.MessageID;
        pr.ResponseText = reply;
        return pr;
    }
Esempio n. 43
0
    IProcessingResult Alias_case_List(IProcessingResult pr, IBot bot, IChatMessage msg, string args)
    {
        var ca = bot.CommandAliases;
        var wc = Helper.WordCount(args);
        var w2 = Helper.WordNumberN(args, 2);

        if (ca.Count < 1)
        {
            pr.ResponseText = "There are no aliases currently set.";
            return pr;
        }

        if (wc > 2)
        {
            pr.ResponseText = "You typed too many words in that request.";
            return pr;
        }

        if (w2 == "*")
            return AliasListAll(pr, bot, msg);

        return AliasList(pr, bot, msg, args);
    }
Esempio n. 44
0
 IProcessingResult Alias_case_Default(IProcessingResult pr, IBot bot, IChatMessage msg, string args)
 {
     pr.ReplyMessageID = msg.MessageID;
     pr.ResponseText = @"Command `alias` requires a parameter: *set*, *remove* or *list*. Refer to [this meta post](http://meta.anime.stackexchange.com/q/1166/) for more info.";
     return pr;
 }
Esempio n. 45
0
    public IProcessingResult Unonebox(IProcessingResult pr, IBot bot, IChatMessage msg, string arg)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        { }
        // basically add "…" to the last message

        //pr = Edit(pr,bot,msg,);

        var editablePosts = bot.GetStillEditableMessages();

        if (editablePosts.Count < 1)
        {
            pr.ResponseText = "2 minutes have passed since last message was posted, apparently. Can't edit or delete it myself now.";
            pr.ReplyMessageID = msg.MessageID;
        }

        IChatMessage lastbotpost = null;
        try { lastbotpost = editablePosts[0]; }
        catch
        {
            pr.ResponseText = "Exception occurred while getting last editable post. Perhaps it's too late to edit the last message.";
            return pr;
        }

        // check if it's an image
        var regex = new System.Text.RegularExpressions.Regex(@"<div class=\""onebox ob-image\""><a rel=\""nofollow\""href=(.*)><img src=\"".*"" class=\""user-image\"" alt=\""user image\"" /></a>");
        var matches = regex.Matches(lastbotpost.Text);
        if (matches.Count == 1)
        {
            var b = matches[0].Groups[1].Value.Trim('"');
            pr.OwnResponseMessageIDToEdit = lastbotpost.MessageID;
            pr.ResponseText = b + " …";

            return pr;
        }

        var text = lastbotpost.Text;
        var untagged = Helper.ReplaceChatTags(text);

        pr.OwnResponseMessageIDToEdit = lastbotpost.MessageID;
        pr.ResponseText = untagged + " …";

        return pr;
    }
Esempio n. 46
0
    IProcessingResult AliasAdd(IProcessingResult pr, IBot bot, IChatMessage msg, string w2, string w3, string wrest, bool overwrite)
    {
        var ca = bot.CommandAliases;
        var arr = wrest.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        var before = ca.Count;

        foreach (var alias in arr)
        {
            var alia = alias.TrimEnd(',');
            AliasAdd(pr, bot, msg, w2, alia, overwrite);
        }

        var delta = ca.Count - before;

        pr.ReplyMessageID = msg.MessageID;
        pr.ResponseText = "Set " + delta + " aliases out of " + arr.Length + ".";
        return pr;
    }
Esempio n. 47
0
    public IProcessingResult Undo(IBot bot, IProcessingResult pr, string arg)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var editablePosts = bot.GetStillEditableMessages();

        var wc = Helper.WordCount(arg);
        var a1 = Helper.FirstWord(arg).Trim().TrimStart(':');

        if (wc == 0)
        {
            if (editablePosts.Count > 0)
            {
                var last = editablePosts[0];
                bot.DeleteMessage(last.RoomID, last.MessageID);
                pr.Respond = false;
                return pr;
            }
            else
            {
                pr.ResponseText = "No messages less than 2 minutes old.";
                return pr;
            }
        }

        if (wc == 1)
        {
            if (a1 == "last")
            {
                if (editablePosts.Count > 0)
                {
                    var last = editablePosts[0];
                    bot.DeleteMessage(last.RoomID, last.MessageID);
                    pr.Respond = false;
                    return pr;
                }
                else
                {
                    pr.ResponseText = "No messages less than 2 minutes old.";
                    return pr;
                }
            }
            else
            {
                int i = 0;
                var b = int.TryParse(a1, out i);
                if (!b)
                {
                    pr.ResponseText = "Could not parse the number of messages to delete or messageid, whatever it was.";
                    return pr;
                }
                else
                {
                    if (i < 100)
                    {
                        if (editablePosts.Count > 0)
                        {
                            if (editablePosts.Count >= i)
                            {
                                // get i first posts to delete
                                var todel = new List<IChatMessage>();
                                for (int n = 0; n < i; n++)
                                    todel.Add(editablePosts[n]);

                                foreach (var tod in todel)
                                    bot.DeleteMessage(tod.RoomID, tod.MessageID);

                                pr.Respond = false;
                                return pr;
                            }
                            else
                            {
                                foreach (var tod in editablePosts)
                                    bot.DeleteMessage(tod.RoomID, tod.MessageID);

                                pr.Respond = false;
                                return pr;
                            }
                        }
                        else
                        {
                            pr.ResponseText = "No messages less than 2 minutes old.";
                            return pr;
                        }
                    }
                    else // delete by messageid
                    {
                        // try to get the messageid
                        foreach (var v in editablePosts)
                            if (v.MessageID == i)
                            {
                                bot.DeleteMessage(v.RoomID, v.MessageID);

                                pr.Respond = false;
                                return pr;
                            }
                    }
                }
            }
        }

        var wrest = Helper.TextAfter(arg, a1);

        if (a1.ToLowerInvariant() == "last")
        {
            var v = editablePosts[0].MessageID;

            var last = editablePosts[0];
            bot.DeleteMessage(last.RoomID, last.MessageID);

            pr.Respond = false;
            return pr;
        }
        else
        {
            int mid = 0;
            if (int.TryParse(a1, out mid))
            {

                pr.OwnResponseMessageIDToEdit = mid;
                pr.ResponseText = wrest;
            }
            else
            {
                pr.ResponseText = "Could not parse messageid.";
                return pr;
            }
        }


        return pr;
    }
Esempio n. 48
0
    public IProcessingResult Say(IProcessingResult pr, string arg) // looks fine
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        //ResponseType = MessageType.Success,
        //ResponseContent = "listcommands"

        pr.ResponseText = Helper.ReplaceChatTags(Helper.UnescapeChatMessages(arg));

        return pr;
    }
Esempio n. 49
0
    public IProcessingResult Status(IBot bot, IProcessingResult pr)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        //pr.ResponseContent = "status message";
        //ResponseText = "Uptime: " + Helper.GetUptime(Bot.initTime) + ". Firefox memory use: " 
        var uptime = DateTime.UtcNow - bot.StartTimeUTC;
        var memusage = Helper.GetBotAppMemoryUsage();



        var logDir = bot.LogDirectoryPath;

        var logDirInfo = new DirectoryInfo(logDir);

        var logFileInfos = logDirInfo.GetFiles("*.log", SearchOption.AllDirectories);
        var logZipInfo = logDirInfo.GetFiles("*.zip", SearchOption.AllDirectories);

        long logFileSize = 0;
        foreach (var info in logFileInfos)
            logFileSize += info.Length;

        long logZipSize = 0;
        foreach (var info in logZipInfo)
            logZipSize += info.Length;

        var logText = logFileInfos.Length + " log files, size: " + logFileSize + "; " +
                              logZipInfo.Length + " archives, size: " + logZipSize + ".";


        var potatoDir = bot.GetModuleByName("Potato").ModuleDir;
        var potDirInfo = new DirectoryInfo(potatoDir);

        var potFileInfos = potDirInfo.GetFiles("*.txt", SearchOption.AllDirectories);
        var potZipInfo = potDirInfo.GetFiles("*.zip", SearchOption.AllDirectories);

        long potSize = 0;
        long potZipSize = 0;

        foreach (var info in potFileInfos)
            potSize += info.Length;

        foreach (var info in potZipInfo)
            potZipSize += info.Length;

        var potText = potFileInfos.Length + " list files, size: " + potSize + "; " +
                              potZipInfo.Length + " archives, size: " + potZipSize + ".";


        pr.ResponseText = "Bot app memory use: " + memusage + " bytes." +
            " Uptime: " + uptime + "." +
            " " + logText +
            " " + potText;

        return pr;
    }
Esempio n. 50
0
    public IProcessingResult Isch(IBot bot, IProcessingResult pr, IChatMessage msg, string arg)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var ts = bot.TriggerSymbol;

        string link = @"https://www.google.com/search?tbm=isch&q=";
        string unparsedtxt = msg.Text;
        string firstw = Helper.FirstWord(unparsedtxt);
        string args = unparsedtxt.Replace(firstw, "");
        args = System.Web.HttpUtility.UrlEncode(args);
        var words = args.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
        string slink = link + string.Join("+", words);

        pr.ResponseText = "[Google Image Search](" + slink + ").";

        if (string.IsNullOrEmpty(arg))
            pr.ResponseText = "Which images do you want to find? Say `" + ts + "isch anime vampire loli` to get the relevant image search results.";

        return pr;
    }
Esempio n. 51
0
    // ext

    public IProcessingResult Meme(IBot bot, IProcessingResult pr, IChatMessage msg, string arg)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var w1 = Helper.WordNumberN(arg, 1);
        var rest = Helper.TextAfter(arg, w1);
        var w2 = "";
        var w3 = "";

        var reg = new Regex("\".*?\"");
        var matches = reg.Matches(rest);

        if (matches.Count < 1)
        {
            pr.ResponseText = "You must provide some text, or else the image will return unmodified.";
            return pr;
        }

        w2 = matches[0].Value.Trim('"');

        if (matches.Count == 2) // could be only top text
            w3 = matches[1].Value.Trim('"');


        var response = Thing(w1, w2, w3);

        pr.ResponseText = response.Result.ToString();

        return pr;
    }
Esempio n. 52
0
    public IProcessingResult LastPostedImageID(IBot bot, IProcessingResult pr, IChatMessage msg, string arg)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var v = bot.GetModuleByName("Potato");

        if (v != null)
        {
            var last = (string)v.GetParameter("last posted image url");

            string gris = @"https://www.google.com/searchbyimage?image_url=";
            string snao = @"http://saucenao.com/search.php?url=";
            string iqdb = @"http://iqdb.org/?url=";
            string tin = @"http://tineye.com/search?url=";
            string imagelink = last;
            string grislink = gris + imagelink;
            string snaolink = snao + imagelink;
            string iqdblink = iqdb + imagelink;
            string tinlink = tin + imagelink;

            string niceresponse = "[Google Reverse Image Search](" + grislink + "), [TinEye](" + tinlink + "), [SauceNAO](" + snaolink + "), [iqdb](" + iqdblink + ").";
            string shortresponse = grislink + " | " + tinlink + " | " + snaolink + " | " + iqdblink;

            pr.ResponseText = niceresponse.Length < 500 ? niceresponse : shortresponse;
        }

        return pr;
    }
Esempio n. 53
0
    public IProcessingResult Weather(IProcessingResult pr, IChatMessage msg, string arg)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.ResponseText = "!!tell :" + msg.MessageID + " weather " + arg;

        return pr;
    }
Esempio n. 54
0
    public IProcessingResult GetCommandList(IBot bot, IProcessingResult pr, string arg)
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        var modules = bot.GetLoadedModules();
        var commandsByModule = new Dictionary<string, List<string>>();

        foreach (var module in modules)
        {
            commandsByModule[module.Name] = new List<string>();

            foreach (var command in module.CommandList)
                commandsByModule[module.Name].Add(command);
        }

        if (modules.Count > 0)
        {
            string reply = "";

            foreach (var module in commandsByModule)
                reply += "[" + module.Key + "] " + string.Join(", ", module.Value) + Environment.NewLine;

            pr.ResponseText = reply;
        }
        else
            pr.ResponseText = "No modules are currently loaded.";

        return pr;
    }
Esempio n. 55
0
    public IProcessingResult ID(IBot bot, IProcessingResult pr, IChatMessage msg, string arg) // related to "Other" method above
    {
        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);

        string gris = @"https://www.google.com/searchbyimage?image_url=";
        string snao = @"http://saucenao.com/search.php?url=";
        string iqdb = @"http://iqdb.org/?url=";
        string tin = @"http://tineye.com/search?url=";
        string unparsedimagelink = msg.Text;
        string unescapedimagelink = System.Web.HttpUtility.HtmlDecode(unparsedimagelink);
        string uimagelink = Helper.WordNumberN(unescapedimagelink, 2);
        string imagelink = System.Web.HttpUtility.UrlEncode(uimagelink);
        string grislink = gris + imagelink;
        string snaolink = snao + imagelink;
        string iqdblink = iqdb + imagelink;
        string tinlink = tin + imagelink;
        string ugrislink = gris + uimagelink;
        string usnaolink = snao + uimagelink;
        string uiqdblink = iqdb + uimagelink;
        string utinlink = tin + uimagelink;

        string niceresponse = "[Google Reverse Image Search](" + grislink + "), [TinEye](" + tinlink + "), [SauceNAO](" + snaolink + "), [iqdb](" + iqdblink + ").";
        string shortresponse = ugrislink + " | " + utinlink + " | " + usnaolink + " | " + uiqdblink;

        pr.ResponseText = niceresponse.Length < 500 ? niceresponse : shortresponse;


        if (string.IsNullOrEmpty(arg))
            pr.ResponseText = "Which image do you want to identify? Say `" + bot.TriggerSymbol + "id hxxp://example.com/image.jpg` to get the id links.";

        return pr;
    }
Esempio n. 56
0
    IProcessingResult Alias_case_Delete(IProcessingResult pr, IBot bot, IChatMessage msg, string args)
    {
        var wc = Helper.WordCount(args);
        var w2 = Helper.WordNumberN(args, 2);
        var ca = bot.CommandAliases;

        if (wc < 1)
        {
            pr.ResponseText = "Specify which alias you want to remove.";
            return pr;
        }
        if (wc > 1)
            return AliasesDelete(pr, bot, msg, args);
        else
        {
            if (ca.ContainsKey(w2)) /// uhh wut?
                return AliasDelete(pr, bot, msg, w2);
            else
            {
                pr.ResponseText = "There was no such alias defined.";
                return pr;
            }
        }
    }
Esempio n. 57
0
    // end of interface



    // core commands

    public IProcessingResult About(IBot bot, IProcessingResult pr, string arg)
    {
        if (arg.Trim() != "")
            return pr;

        pr.Solved = true;
        pr.Respond = true;
        pr.ResponseOrigin = Helper.GetExecutingMethodName(this);
        pr.ResponseText = "My name is " + bot.Name + " and I'm a chat bot. " +
            "I can't do much right now, but I'm learning new things all the time. If you know something fun I could learn to do, let me know." + Environment.NewLine +
            "You can view the list of all commands by saying `" + bot.TriggerSymbol + "commands`. If anything is unclear, say `" + bot.TriggerSymbol + "help`.";

        return pr;
    }
Esempio n. 58
0
    IProcessingResult AliasesDelete(IProcessingResult pr, IBot bot, IChatMessage msg, string aliases)
    {
        var arr = aliases.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

        var before = bot.CommandAliases.Count;

        foreach (var alias in arr)
            AliasDelete(pr, bot, msg, alias);

        var delta = before - bot.CommandAliases.Count;

        pr.ReplyMessageID = msg.MessageID;
        pr.ResponseText = "Removed " + delta + " aliases out of " + arr.Length + ".";
        return pr;
    }
Esempio n. 59
0
    IProcessingResult AliasAdd(IProcessingResult pr, IBot bot, IChatMessage msg, string command, string alias, bool overwrite)
    {
        var ca = bot.CommandAliases;
        var c = command;
        var a = alias;

        if (!overwrite)
            if (ca.ContainsKey(a))
            {
                var cmdname = ca[a];

                pr.ResponseText = "Command *" + cmdname + "* was already aliased to *" + a + "*. If you want to overwrite it, add \"-overwrite\" or \"-o\" to your request.";
                return pr;
            }

        if (c.Contains("alias") || a.Contains("alias") || c == a || commandsList.Contains(a)) // sanity check
        {
            pr.ResponseText = "You can't do that.";
            return pr;
        }

        // just set
        ca[a] = c;
        Log("[+] Added new alias: \"" + alias + "\" for command \"" + command + "\".");

        pr.ReplyMessageID = msg.MessageID;
        pr.ResponseText = "Command *" + c + "* was aliased to *" + a + "*";
        return pr;
    }
Esempio n. 60
0
    IProcessingResult AliasDelete(IProcessingResult pr, IBot bot, IChatMessage msg, string alias)
    {
        var dic = bot.CommandAliases;

        var alia = alias.TrimEnd(',');
        if (dic.ContainsKey(alia))
        {
            dic.Remove(alia);
            Log("[−] Deleted alias by key \"" + alia + "\".");
        }
        else
            Log("[x] Could not delete alias by key \"" + alia + "\" because it was not present in alias dictionary.");

        pr.ReplyMessageID = msg.MessageID;
        pr.ResponseText = "Removed alias *" + alias + "*.";
        return pr;
    }