Exemplo n.º 1
0
 public static async Task Remove(Tweet I)
 {
     if (I.source == "tweets")
     {
         await AbbysqlClient.RunSQL($"DELETE FROM `twitter`.`{I.source}` WHERE `Id` = '{I.id}';");
     }
 }
Exemplo n.º 2
0
        public static async Task IncreaseStat(ulong abbybotId, ulong guildId, ulong channelId, ulong userId, string stat)
        {
            if (stat.Length == 0)
            {
                return;
            }

            var it = AbbysqlClient.EscapeString(stat);
            //var month = DateTime.Now.ToString("MMMM yyyy");

            var a = await AbbysqlClient.FetchSQL($"select * from `guild`.`userstats` where `Stat`='{stat}' and `AbbybotId` = '{abbybotId}' and `GuildId`='{guildId}' and `ChannelId`='{channelId}' and `UserId`='{userId}'");

            if (a.Count != 0)
            {
                ulong num = (a[0]["Points"] is ulong points) ? points : 0;

                ulong  n = ++num;
                string s = $"UPDATE `guild`.`userstats` SET `Points`= '{n}' WHERE `Stat`='{stat}' and `AbbybotId` = '{abbybotId}' and `GuildId`='{guildId}' and `ChannelId`='{channelId}' and `UserId`='{userId}';";
                await AbbysqlClient.RunSQL(s);
            }
            else
            {
                await AbbysqlClient.RunSQL($"insert into `guild`.`userstats` (`AbbybotId`,`GuildId`, `ChannelId`,`UserId`, `Stat`, `Points`) values ('{abbybotId}', '{guildId}', '{channelId}', '{userId}','{stat}', '1');");
            }
        }
Exemplo n.º 3
0
        public static async Task <string> GetLastTime(ulong userId, ulong guildId, string item)
        {
            var it = AbbysqlClient.EscapeString(item);
            var a  = await AbbysqlClient.FetchSQL($"select * from `user`.`activity` where `UserId`='{userId}' and `GuildId` = '{guildId}' and `Kind` = '{it}'");

            return((a.Count > 0 && a[0]["Time"] is string s) ? s : "");
        }
Exemplo n.º 4
0
        public static async Task <Tweet> Peek()
        {
            Tweet tweet = null;
            var   table = await AbbysqlClient.FetchSQL($"SELECT * FROM `twitter`.`tweets` ORDER BY Priority DESC, Id ASC LIMIT 1;");

            if (table.Count < 1)
            {
                throw new Exception("no tweets in list");
            }

            foreach (AbbyRow row in table)
            {
                tweet = new Tweet()
                {
                    id        = (int)row["Id"],
                    url       = (row["ImgUrl"] is string i) ? i : "",
                    sourceurl = (row["SrcUrl"] is string s) ? s : "",
                    message   = (row["Description"] is string m) ? m : "",
                    priority  = (sbyte)row["Priority"] == 1 ? true : false,
                    GelId     = (row["GelId"] is int gild ? gild : 0),
                    md5       = (row["md5"] is string smd5) ? smd5 : "",
                    source    = "tweets"
                };
            }
            return(tweet);
        }
Exemplo n.º 5
0
        public static async Task <AbbybotGuild> GetGuild(ulong abg)
        {
            var g = new AbbybotGuild()
            {
                Id = abg
            };
            var table = await AbbysqlClient.FetchSQL($"SELECT `GuildId` FROM `abbybot`.`guilds` WHERE `GuildId` = '{g.Id}';");

            bool e = table.Count > 0;

            if (abg == 0)
            {
                return(null);
            }

            var table2 = await AbbysqlClient.FetchSQL($"SELECT * FROM `abbybot`.`guilds` WHERE `GuildId` = '{g.Id}';");

            foreach (AbbyRow row in table2)
            {
                g.NoLoli         = (sbyte)row["NoLoli"] == 1 ? true : false;
                g.NoNSFW         = (sbyte)row["NoNSFW"] == 1 ? true : false;
                g.PrefAbbybot    = row["PrefAbbybot"] is ulong pabi ? pabi : 0;
                g.AutoDeleteTime = row["DeleteAfterSeconds"] is int secs ? secs : -1;
            }
            return(g);
        }
Exemplo n.º 6
0
 public static async Task Add(string message, Image I)
 {
     var url       = AbbysqlClient.EscapeString(I.url);
     var sourceurl = AbbysqlClient.EscapeString(I.sourceurl);
     var msg       = AbbysqlClient.EscapeString(message);
     await AbbysqlClient.RunSQL($"INSERT INTO `twitter`.`tweets` ( `ImgUrl`,`SrcUrl`, `Description`, `Priority`, `md5`, `GelId` ) VALUES('{url}', '{sourceurl}', '{msg}','0', '{I.md5}', '{I.gelId}');");
 }
Exemplo n.º 7
0
        public static async Task <List <(ulong userId, ulong stat)> > GetGuildStat(ulong abbybotId, ulong guildId, string v)
        {
            List <(ulong userId, ulong stat)> stats = new List <(ulong userId, ulong stat)>();
            var ori = AbbysqlClient.EscapeString(v);
            var a   = await AbbysqlClient.FetchSQL($"select * from `guild`.`userstats` where `AbbybotId` = '{abbybotId}' and `GuildId`='{guildId}' and `Stat`='{ori}';");

            foreach (AbbyRow abr in a)
            {
                var point = abr["Points"] is ulong p ? p : 0;
                var user  = abr["UserId"] is ulong u ? u : 0;
                stats.Add((user, point));
            }
            var groupedstats = stats.ToList().GroupBy(x => x.userId);

            stats.Clear();
            foreach (var u in groupedstats)
            {
                ulong o = 0;
                foreach (var s in u)
                {
                    o += s.stat;
                }
                stats.Add((u.Key, o));
            }
            return(stats);
        }
Exemplo n.º 8
0
        public static async Task <Tweet> Peek()
        {
            Tweet tweet = null;
            var   table = await AbbysqlClient.FetchSQL($"SELECT * FROM `twitter`.`archive` ");

            if (table.Count < 1)
            {
                throw new Exception("no tweets in list");
            }
            //Console.WriteLine($"You have {table.Count} items in the tweetarchive");
            AbbyRow row = table[r.Next(0, table.Count)];

            tweet = new Tweet()
            {
                id        = (int)row["Id"],
                url       = (row["ImgUrl"] is string i) ? i : "",
                sourceurl = (row["SrcUrl"] is string s) ? s : "",
                message   = (row["Description"] is string m) ? m : "",
                priority  = (sbyte)row["Priority"] == 1,
                GelId     = (row["GelId"] is int gild ? gild : 0),
                md5       = (row["md5"] is string smd5) ? smd5 : "",
                source    = "tweetarchive"
            };

            return(tweet);
        }
Exemplo n.º 9
0
        internal static async Task <bool> UnbadtaglistTag(ulong id, string item)
        {
            item = AbbysqlClient.EscapeString(item);
            var e = await AbbysqlClient.RunSQL($"DELETE FROM `user`.`gelbadtaglist` WHERE `UserId` = '{id}' and `Tag` = '{item}';");

            return(e switch
            {
Exemplo n.º 10
0
        public static async Task <int> GetGuild(SocketGuild abg, RestInviteMetadata rim)
        {
            var table = await AbbysqlClient.FetchSQL($"SELECT `Joins` FROM `invites` WHERE `GuildId` = '{abg.Id}' AND `InviteId` = '{rim.Code}';");

            bool e = table.Count > 0;

            return(e ? (int)table[0]["Joins"] : 0);
        }
Exemplo n.º 11
0
 public static async Task Add(Tweet I, bool v)
 {
     int priority  = v ? 1 : 0;
     var url       = AbbysqlClient.EscapeString(I.url);
     var sourceurl = AbbysqlClient.EscapeString(I.sourceurl);
     var message   = AbbysqlClient.EscapeString(I.message);
     await AbbysqlClient.RunSQL($"INSERT INTO `twitter`.`tweets` ( `ImgUrl`,`SrcUrl`, `Description`, `Priority`, `GelId`, `md5` ) VALUES('{url}', '{sourceurl}', '{message}', '{priority}','{I.GelId}','{I.md5}' );");
 }
Exemplo n.º 12
0
        public static async Task <bool> AddRole(ulong guildId, ulong roleId)
        {
            var t = await AbbysqlClient.FetchSQL($"select *  from `guild`.`mostactiveroles` where `GuildId`='{guildId}' and `RoleId` = '{roleId}';");

            return(t.Count < 1
                                ? await AbbysqlClient.RunSQL($"insert into `guild`.`mostactiveroles`(`GuildId`, `RoleId`) values ('{guildId}', '{roleId}');") > 0
                                : false);
        }
Exemplo n.º 13
0
 public static async Task SetFavoriteCharacterHistoryAsync(ulong userId, string favoriteCharacter, string type, string info, ulong lastId)
 {
     var t   = DateTime.Now.ToString("G");
     var fc  = AbbysqlClient.EscapeString(favoriteCharacter);
     var ty  = AbbysqlClient.EscapeString(type);
     var inf = AbbysqlClient.EscapeString(info);
     await AbbysqlClient.RunSQL($"insert into `abbybooru`.`userfchistory` (`UserId`, `Time`, `FavoriteCharacter`, `Type`, `Info`, `UndoId`) values ('{userId}','{t}','{fc}', '{ty}', '{inf}', '{lastId}');");
 }
Exemplo n.º 14
0
        public static async Task <List <ulong> > GetLatestMentionIdsAsync(ulong id)
        {
            List <ulong> ids = new List <ulong>();

            AbbyTable table = await AbbysqlClient.FetchSQL($"SELECT * FROM heardtweets WHERE Id = {id};");

            foreach (AbbyRow row in table)
            {
                ids.Add((ulong)row["Id"]);
            }
            return(ids);
        }
Exemplo n.º 15
0
        public static async Task <List <string> > GetbadtaglistTags()
        {
            List <string> tags = new List <string>();

            var table = await AbbysqlClient.FetchSQL("SELECT * FROM `saybadtaglist`");

            foreach (AbbyRow row in table)
            {
                tags.Add((row["Word"] is string favchan) ? favchan : "");
            }
            return(tags);
        }
Exemplo n.º 16
0
        public static async Task <int> Count()
        {
            var table = await AbbysqlClient.FetchSQL("SELECT COUNT(*) as 'rows' FROM twitter.archive;");

            int rows = 0;

            foreach (AbbyRow row in table)
            {
                rows = int.Parse(row["rows"].ToString());
            }
            return(rows);
        }
Exemplo n.º 17
0
        public static async Task <(string fc, bool nsfw)> GetFCMAsync(ulong guildId, ulong channelId)
        {
            AbbyTable table = await AbbysqlClient.FetchSQL($"select * from `channel`.`fcsettings` where `GuildId`= {guildId} and `ChannelId` = {channelId};");

            if (table.Count >= 1)
            {
                var fc   = (table[0]["FavoriteCharacter"] is string s && s.Length > 1) ? s : "NO";
                var nsfw = table[0]["IsNSFW"] is int nsf && nsf == 1;
                return(fc, nsfw);
            }
            return("NO", false);
        }
Exemplo n.º 18
0
        public static async Task <List <string> > GetbadtaglistTags(ulong id)
        {
            List <string> tags = new List <string>();

            var table = await AbbysqlClient.FetchSQL($"SELECT `Tag` FROM `user`.`gelbadtaglist` WHERE `UserId` = '{id}';");

            foreach (AbbyRow row in table)
            {
                tags.Add((row["Tag"] is string favchan) ? favchan : "");
            }
            return(tags);
        }
Exemplo n.º 19
0
        public static async Task <List <ulong> > GetAbbybotIdAsync()
        {
            List <ulong> abbybots = new List <ulong>();

            AbbyTable table = await AbbysqlClient.FetchSQL($"select * from `abbybot`.`discordbots`");

            foreach (AbbyRow row in table)
            {
                abbybots.Add(table.Count >= 1 && (row["Id"] is ulong u) ? u : 0);
            }
            abbybots.Remove(Apis.Discord.__client.CurrentUser.Id);
            return(abbybots);
        }
Exemplo n.º 20
0
        public static async Task <List <AbbybotRole> > GetRolesFromUser(AbbybotUser u)
        {
            List <AbbybotRole> roles = new List <AbbybotRole>();

            var table = await AbbysqlClient.FetchSQL($"SELECT * FROM `user`.`roles` WHERE `UserId` = '{u.Id}' && `GuildId` = '{u.GuildId}';");

            foreach (AbbyRow row in table)
            {
                long Roleid = (long)(row["RoleId"]);
                roles.AddRange(RoleManager.roles.Where(rx => rx.role == (ulong)Roleid).Select(rx => rx));
            }
            return(roles);
        }
Exemplo n.º 21
0
        public static async Task RemoveCharacterAsync(ISocketMessageChannel channel, string v)
        {
            var tag = AbbysqlClient.EscapeString(v);

            var tbl = await AbbysqlClient.FetchSQL($"SELECT * FROM `abbybooru`.`characters` WHERE `Tag` = '{tag}' AND `ChannelId` = '{channel.Id}';");

            if (tbl.Count < 1)
            {
                throw new Exception("nocharacter");
            }

            await AbbysqlClient.RunSQL($"DELETE FROM `abbybooru`.`characters` WHERE `Tag` = '{tag}' AND `ChannelId` = '{channel.Id}';");
        }
Exemplo n.º 22
0
        public static async Task SetUsernameSql(ulong userId, string username, string nickname = "")
        {
            nickname ??= "";
            string u  = (username.Length > 1) ? AbbysqlClient.EscapeString(username) : "";
            string n  = (nickname.Length > 1) ? AbbysqlClient.EscapeString(nickname) : "";
            string ss = $"UPDATE `user`.`names` SET `Username`='{u}'";

            if (n.Length > 1)
            {
                ss += $", `Nickname`= '{n}'";
            }
            ss += $" WHERE  `UserId`= {userId}; ";
            await AbbysqlClient.RunSQL(ss);
        }
Exemplo n.º 23
0
        public static async Task <List <(ulong guildId, ulong channelId)> > GetAbbybotChannelIdAsync()
        {
            List <(ulong guildId, ulong channelId)> abbybots = new List <(ulong guildId, ulong channelId)>();

            AbbyTable table = await AbbysqlClient.FetchSQL($"select * from `abbybot`.`channels`");

            foreach (AbbyRow row in table)
            {
                var guild   = table.Count >= 1 && (row["GuildId"] is ulong g) ? g : 0;
                var channel = table.Count >= 1 && (row["ChannelId"] is ulong c) ? c : 0;
                abbybots.Add((guild, channel));
            }
            return(abbybots);
        }
Exemplo n.º 24
0
        public static async Task <List <AbbybotRole> > GetRoles(SocketGuild g)
        {
            List <AbbybotRole> roles = new List <AbbybotRole>();

            var table = await AbbysqlClient.FetchSQL($"SELECT * FROM `guild`.`roles` WHERE `GuildId` = '{g.Id}';");

            foreach (AbbyRow row in table)
            {
                ulong Roleid  = (ulong)(row["RoleId"]);
                int   Ranking = (int)row["Ranking"];
                roles.Add(new AbbybotRole((ulong)Roleid, new CommandRatings[] { (CommandRatings)Ranking }));
            }
            return(roles);
        }
Exemplo n.º 25
0
        internal static async Task <List <ulong> > GetLatestPostIdsAsync(Character character)
        {
            List <ulong> ulongs = new List <ulong>();
            var          table  = await AbbysqlClient.FetchSQL($"SELECT * FROM `abbybooru`.`characterpostids` WHERE `CharId`='{character.Id}';");

            foreach (AbbyRow row in table)
            {
                if (row["Id"] is ulong id)
                {
                    ulongs.Add(id);
                }
            }
            return(ulongs);
        }
Exemplo n.º 26
0
        public static async Task AddCharacterAsync(ISocketMessageChannel channel, AbbybotGuild abbybotGuild, string v)
        {
            var tag = AbbysqlClient.EscapeString(v);
            var nsf = (channel as ITextChannel).IsNsfw ? 0 : 1;

            var tbl = await AbbysqlClient.FetchSQL($"SELECT * FROM `abbybooru`.`characters` WHERE `Tag` = '{tag}' AND `ChannelId` = '{channel.Id}';");

            if (tbl.Count > 0)
            {
                throw new Exception("CharacterAlreadyAdded");
            }

            await AbbysqlClient.RunSQL($"INSERT INTO `abbybooru`.`characters` ( `Tag`,`ChannelId`, `GuildId`, `IsLewd` ) VALUES ('{tag}','{channel.Id}','{abbybotGuild.Id}', '{nsf}'); ");
        }
Exemplo n.º 27
0
        public static async Task SetCFCAsync(ulong guildId, ulong channelId, bool nsfw, string fc)
        {
            string    fcm   = AbbysqlClient.EscapeString(fc);
            int       insfw = nsfw ? 1 : 0;
            AbbyTable table = await AbbysqlClient.FetchSQL($"select * from `channel`.`fcsettings` where `GuildId` = {guildId} and `ChannelId`= {channelId}");

            if (table.Count < 1)
            {
                await AbbysqlClient.RunSQL($"insert into `channel`.`fcsettings` (`GuildId`, `ChannelId`, `FavoriteCharacter`,`IsNSFW` ) values ('{guildId}', '{channelId}', '{fcm}', {insfw});");
            }
            else
            {
                await AbbysqlClient.RunSQL($"UPDATE `channel`.`fcsettings` SET `FavoriteCharacter`= '{fcm}' WHERE  `GuildId`= {guildId} and `ChannelId` = {channelId};");
            }
        }
Exemplo n.º 28
0
        public static async Task <LuaData> GetLuaData(ulong UserId)
        {
            LuaData lua   = new() { UserId = UserId };
            var     table = await AbbysqlClient.FetchSQL($"SELECT * FROM user.lua where UserId = {UserId} ORDER BY Id ASC");

            table.ToList().
            ForEach(r =>
            {
                if (r["lua"] is string s)
                {
                    lua.LuaPieces.Add(s);
                }
            });
            return(lua);
        }