예제 #1
0
        public override async Task <string> toHelpString(AbbybotCommandArgs aca)
        {
            var facts = await FunAbbybotFactsSql.GetFactsList(await aca.IsNSFW());

            if (facts.Count == 0)
            {
                return("I... I don't understand... My facts list is empty... %fact won't do anything...");
            }
            var ra = r.Next(0, facts.Count);

            return($"{facts[ra].fact}, get another abbybot fact with this command!!");
        }
예제 #2
0
        public override async Task DoWork(AbbybotCommandArgs a)
        {
            var facts = await FunAbbybotFactsSql.GetFactsList(await a.IsNSFW());

            var ra = r.Next(0, facts.Count);

            if (facts.Count > 0)
            {
                await a.Send(facts[ra].fact.ReplaceA("ab!", "%"));
            }
            else
            {
                await a.Send("I'm sorry master... My facts list is empty... I... I can't send you a fact :(");
            }
        }
예제 #3
0
        public static async Task Add(Tweet I, bool v)
        {
            var facts = await FunAbbybotFactsSql.GetFactsList(true);

            Random r         = new();
            int    priority  = v ? 1 : 0;
            var    url       = AbbysqlClient.EscapeString(I.url);
            var    sourceurl = AbbysqlClient.EscapeString(I.sourceurl);

            var message = AbbysqlClient.EscapeString(I.message);

            if (message.Contains("new tweet just came in") && facts.Count > 0)
            {
                message = facts[r.Next(0, facts.Count)].fact;
            }
            message = AbbysqlClient.EscapeString(message);


            await AbbysqlClient.RunSQL($"INSERT INTO `twitter`.`archive` ( `ImgUrl`,`SrcUrl`, `Description`, `Priority`, `md5`, `GelId` ) VALUES('{url}', '{sourceurl}', '{message}','0', '{I.md5}', '{I.GelId}');");
        }
예제 #4
0
        static async Task RequestBeat(DateTime time)
        {
            if (time > CheckTime)
            {
                //Abbybot.print("running abc!!");
                CheckTime = CheckTime.AddMinutes(1);
                SocketTextChannel channel    = null;
                List <Character>  characters = await AbbyBooruCharacterSql.GetListFromSqlAsync();

                foreach (var character in characters)
                {
                    //Abbybot.print("{}");
                    //AbbybotGuild
                    bool          safe = true;
                    List <string> tags = new List <string>();
                    try
                    {
                        var Gl = Apis.Discord.__client.Guilds.ToList().Any(x => x.Id == character.guildId);

                        if (!Gl)
                        {
                            continue;
                        }
                        //Console.WriteLine($"{character.tag}, guild found!");
                        var G = Apis.Discord.__client.GetGuild(character.guildId);

                        var pref = await GuildSql.GetGuild(character.guildId);

                        if (pref.PrefAbbybot != Apis.Discord.__client.CurrentUser.Id)
                        {
                            continue;
                        }
                        channel = G.GetTextChannel(character.channelId);

                        tags.Add(character.tag);
                        //Console.WriteLine($"channel nsfw? {channel.IsNsfw}, character lewd? {character.IsLewd}");
                        safe = !channel.IsNsfw;
                    }
                    catch (Exception e)
                    {
                        //Console.WriteLine(e.ToString());
                        continue;
                    }
                    if (safe)
                    {
                        tags.Add("rating:safe");
                    }


                    Post[] charpicx = new Post[0];
                    try
                    {
                        charpicx = (await Apis.AbbyBooru.GetLatest(tags.ToArray())).ToArray();
                        if (charpicx == null)
                        {
                            continue;
                        }
                        if (charpicx.Length > 5)
                        {
                            charpicx = charpicx.Take(5).ToArray();
                        }
                        else
                        {
                            continue;
                        }
                    } catch {
                        //Console.WriteLine("aaaa");
                    }
                    List <img> nngs    = new List <img>();
                    var        postIds = (await AbbyBooruCharacterSql.GetLatestPostIdsAsync(character));

                    Post[] eeee = charpicx.Where(x => !postIds.Contains((ulong)x.id)).Take(5).ToArray();

                    foreach (var ex in eeee)
                    {
                        img nng = new img()
                        {
                            Id     = (ulong)ex.id,
                            imgurl = ex.fileUrl,
                            source = ex.source,
                            safe   = (ex.rating.Contains($"safe")),
                            GelId  = ex.id,
                            md5    = ex.md5
                        };
                        nngs.Add(nng);
                    }

                    for (int i = 0; i < nngs.Count; i++)
                    {
                        img sr = nngs[i];

                        EmbedBuilder embededodizer = new EmbedBuilder
                        {
                            ImageUrl = sr.imgurl
                        };

                        string fixedsource = "no source found";
                        try
                        {
                            if (sr.source != null)
                            {
                                fixedsource = sr.source.Replace("/member_illust.php?mode=medium&amp;illust_id=", "/en/artworks/");
                            }

                            embededodizer.AddField($"New picture of {character.tag.Replace("_", " ")} :)", $"[Source]({fixedsource})");
                            embededodizer.Color = Color.LightOrange;

                            await channel.SendMessageAsync("", false, embededodizer.Build());
                        }
                        catch { }

                        await AbbyBooruCharacterSql.AddLatestPostIdAsync(character.Id, sr.Id, sr.GelId);

                        if (character.Id == 3)
                        {
                            var dl = await FunAbbybotFactsSql.GetFactsList(true, "twitter");

                            Random r      = new Random();
                            var    ranfac = dl.Count > 0? dl[r.Next(0, dl.Count)].fact:"";

                            Tweet tweet = new()
                            {
                                message   = $"A new tweet just came in from gelbooru!!\n{ranfac}",
                                url       = sr.imgurl,
                                sourceurl = fixedsource,
                                GelId     = sr.GelId
                            };

                            await TweetQueueSql.Add(tweet, true);
                        }
                    }
                }
            }
        }
    }