Beispiel #1
0
        private async Task <(string type, bool cons, StringBuilder Fc, StringBuilder TitleFc)> DoRemove(AbbybotCommandArgs a)
        {
            StringBuilder sb = new StringBuilder();
            var           FavoriteCharacter = a.Replace(Command);
            var           TitleFC           = a.Replace(Command);
            var           charactertag      = a.BreakAbbybooruTag(a.user.FavoriteCharacter);

            FavoriteCharacter.Remove(0, 7);
            TitleFC.Remove(0, 7);
            sb.AppendLine($"you entered {FavoriteCharacter}");
            FavoriteCharacter = a.BreakAbbybooruTag(FavoriteCharacter);
            var           chosenChr = FavoriteCharacter.Split(" or ");
            var           chrt      = charactertag.Split(" or ");
            List <string> strs      = new List <string>();

            if (chrt.Length > 1)
            {
                var awf = chrt.Where(c => !chosenChr.Contains(c));
                foreach (var chr in awf)
                {
                    strs.Add(chr);
                }
            }
            else
            {
                await a.Send($"silly!! You can't remove the last character from your fc!!");

                return("remove", false, FavoriteCharacter, a.BreakAbbybooruTag(TitleFC));
            }
            var ww = new StringBuilder().AppendJoin(" or ", strs);

            await a.Send(sb);

            return("remove", true, a.BuildAbbybooruTag(ww), a.BreakAbbybooruTag(TitleFC));
        }
Beispiel #2
0
        private async Task <(string type, bool cons, StringBuilder Fc, StringBuilder TitleFc)> DoBreakTag(AbbybotCommandArgs a)
        {
            var FavoriteCharacter = a.Replace(Command);

            FavoriteCharacter.Remove(0, 9);
            await a.Send(a.BreakAbbybooruTag(FavoriteCharacter));

            return("breaktag", false, null, null);
        }
Beispiel #3
0
        private static List <StringBuilder> GetMultiFCStringBuilders(AbbybotCommandArgs e)
        {
            var fcs = e.GetFCList().OrderBy(w => w).ToArray();

            List <StringBuilder> sbs       = new();
            StringBuilder        currentSb = new($"You have {fcs.Length} favorite characters set!!!\n");

            foreach (var fc in fcs)
            {
                String fav = e.BreakAbbybooruTag(fc);
                if ((fav.Length + 1 + currentSb.Length) >= 2000)
                {
                    sbs.Add(currentSb);
                    currentSb = new();
                }
                currentSb.Append(fav + '\n');
            }
            if (currentSb.Length > 0)
            {
                sbs.Add(currentSb);
            }

            return(sbs);
        }
Beispiel #4
0
        public override async Task DoWork(AbbybotCommandArgs a)
        {
            var input = a.Replace(Command);

            if (input.Length == 0)
            {
                if (a.hasMultipleFcs)
                {
                    var fclists = GetMultiFCStringBuilders(a);

                    await a.Send(fclists);

                    return;
                }
                else
                {
                    string message = $"Your favorite character is: {a.BreakAbbybooruTag(a.user.FavoriteCharacter)}. Get help with {Command} help";

                    await a.Send(message);

                    return;
                }
            }

            var ofclist = a.GetFCList();

            var subCommand = input.Split(" ")[0];
            var info       = subCommand switch {
                "help" => await DoHelp(a),
                "history" => await DoHistory(a),
                "undo" => await DoUndo(a),
                "revert" => await DoRevert(a),
                "add" => await DoAdd(a),
                "remove" => await DoRemove(a),
                "buildtag" => await DoBuildTag(a),
                "breaktag" => await DoBreakTag(a),
                _ => await DoSet(a)
            };

            if (!info.cons)
            {
                return;
            }

            string[] o = new string[1];
            a.BuildAbbybooruTag(info.TitleFc);
            a.BuildAbbybooruTag(info.Fc);
            o[0] = (info.TitleFc ?? info.Fc).ToString();

            (bool canrun, string pictureurl, string previewurl, string fc)aaa = (false, null, null, "");

            int  failcount = 0;
            bool failed    = false;

            EmbedBuilder eb = new EmbedBuilder();

            bool set = false;

            do
            {
                var sif = o[0];
                try {
                    aaa = await awa(a, o, info.type);

                    if (!aaa.canrun)
                    {
                        throw new Exception("Can't run");
                    }
                } catch {
                    failcount++;
                    continue;
                }
                if (info.type == "set")
                {
                    info.Fc.Clear().Append(aaa.fc);
                    o[0] = aaa.fc;
                }
                Console.WriteLine($"{sif}->{o[0]}");
                string[] uris = new string[] {
                    aaa.pictureurl, aaa.previewurl
                };
                int count = 0;
                foreach (var u in uris)
                {
                    try {
                        eb.ImageUrl = u.ToString();
                        set         = true;
                        break;
                    } catch {
                        count++;
                    }
                }
                if (count >= uris.Length)
                {
                    failcount++;
                    failed = true;
                }

                Console.WriteLine($"set? {set}, fails?{failcount}, image? {eb.ImageUrl != null}");
            } while (!set && failcount < 3);
            if (failed)
            {
                await a.Send("I'm sorry master... I tried really hard to find you a picture you would like... But nothing came up... I tried 3 searches... oh well...");

                return;
            }

            var oioio = a.BreakAbbybooruTag(((info.TitleFc != null) ? info.TitleFc : info.Fc).ToString());

            Console.WriteLine($"{oioio}: {info.TitleFc}, {info.Fc}");
            Console.WriteLine(oioio);
            if (aaa.canrun)
            {
                var u = await FavoriteCharacterHistorySql.GetFavoriteCharacterHistoryAsync(a.user.Id);

                await FavoriteCharacterSql.SetFavoriteCharacterAsync(a.user.Id, info.Fc.ToString());

                var lastId = (u.Count > 0 ? u[0].Id : 0);
                Console.WriteLine(lastId);
                await FavoriteCharacterHistorySql.SetFavoriteCharacterHistoryAsync(a.user.Id, info.Fc.ToString(), info.type, oioio, lastId);

                eb.Color = Color.Green;

                eb.Title = info.type switch {
                    "add" => $"Added {oioio}!!!",
                    "remove" => $"Removed {oioio}!!!",
                    "set" => $"{oioio} Yayy!!",
                    _ => "I'm kinda confused master..."
                };

                eb.Description = info.type switch {
                    "add" => $"I added {oioio} to your fc!!",
                    "remove" => $"I removed {oioio} from your fc!",
                    "set" => $"I know your favorite character now hehehehe cutie {a.user.Preferedname} master!! ",
                    _ => "I... I really don't know what's going on..."
                };
            }
            else
            {
                var foc = a.BreakAbbybooruTag(info.Fc.ToString());
                eb.Title       = $"oof... {foc}...";
                eb.Description = $"sorry {a.user.Preferedname}... i couldn't find {foc} ({info.Fc}) ...";
                eb.Color       = Color.Red;
            }

            await a.Send(eb);

            if (ofclist.Length > 2 && info.type == "set")
            {
                await a.Send("Hey, ps... I think you may have made a mistake... You set that favorite character instead of adding it. \nIf you didn't mean to override your favorite character list, I suggest you to run: ``%fc undo``");
            }
        }