Пример #1
0
        public async Task <long> AddReceiptAsync(Receipt receipt)
        {
            _context.Receipts.Add(receipt);
            await _context.SaveChangesAsync();

            return(receipt.Id);
        }
Пример #2
0
        public async Task <DNSAddress> Add(DNSAddress model)
        {
            var result = _myDbContext.DNSAddresses.Add(model);
            await _myDbContext.SaveChangesAsync();

            return(result);
        }
Пример #3
0
        public async Task <Expert> Post(Expert expertData)
        {
            _dbContext.tExpert.Add(expertData);
            int res = await _dbContext.SaveChangesAsync();

            if (res > 0)
            {
                return(expertData);
            }
            throw new Exception();
        }
Пример #4
0
            public async Task Res(IUser user = null)
            {
                //Checks
                if (user == null)
                {
                    await Context.Channel.SendMessageAsync(":x: You need to tell me which user's data you want to reset!");

                    return;
                }

                if (user.IsBot)
                {
                    await Context.Channel.SendMessageAsync(":x: Bots can't be reset!");

                    return;
                }

                //Execution
                await Context.Channel.SendMessageAsync($"{user.Mention}, your message amount has been reset by {Context.User.Username}!");

                //Save the Data
                using (var DbContext = new SqliteDbContext())
                {
                    DbContext.spam.RemoveRange(DbContext.spam.Where(x => x.UserId == user.Id));
                    await DbContext.SaveChangesAsync();
                }
            }
Пример #5
0
        public static async Task CheckIfLastSwing()
        {
            using (var DbContext = new SqliteDbContext())
            {
                foreach (Participant p in DbContext.Participants)
                {
                    if (p.GuessNumber == -1)
                    {
                        return;
                    }
                }

                Game game = DbContext.Games.Where(x => x.StateOfGame != 3).FirstOrDefault();

                if (game.NumberOfPitches >= 5)
                {
                    game.StateOfGame = 3;
                }
                else
                {
                    game.StateOfGame = 1;
                }


                DbContext.Games.Update(game);
                await DbContext.SaveChangesAsync();

                return;
            }
        }
Пример #6
0
            public async Task fileIsActive(int projectID, int fileID, string newStatus)
            {
                stringToBool isValidInput = new stringToBool();

                isValidInput = projectMethod.stringToBool(newStatus);
                if (!isValidInput.isBool)
                {
                    await Context.Channel.SendMessageAsync("T/F Input is invalid try **true** or **false**");

                    return;
                }

                using (var dbContext = new SqliteDbContext())
                {
                    var list = dbContext.Files.Where(x => x.ProjectId == projectID && x.FileId == fileID);
                    if (list.Count() < 1)
                    {
                        await Context.Channel.SendMessageAsync("target file does not exist, please ensure the input is correct");
                    }

                    //input is false/0 change incomplete back to false
                    if (isValidInput.value)
                    {
                        dbContext.Projects.Where(x => x.ProjectId == projectID).FirstOrDefault().isComplete = false;
                    }
                    var item = list.FirstOrDefault();
                    item.isActive    = isValidInput.value;
                    item.LastUpdated = DateTime.Now;
                    await Context.Channel.SendMessageAsync("File status updated");

                    await dbContext.SaveChangesAsync();
                }
            }
        private async Task <bool> Save()
        {
            var appName     = txtAppName.Text.Trim();
            var appPassword = RSAUtil.Encrypt(txtAppPassword.Text.Trim(), _publicKey);

            using (var db = new SqliteDbContext())
            {
                if (_appPwdId > 0)
                {
                    CurrentSelectAppPwd.AppName    = appName;
                    CurrentSelectAppPwd.Password   = appPassword;
                    CurrentSelectAppPwd.ModifyTime = DateTime.UtcNow;
                    db.AppPasswords.Update(CurrentSelectAppPwd);
                }
                else
                {
                    db.AppPasswords.Add(new AppPassword
                    {
                        AppName    = appName,
                        Password   = appPassword,
                        CreateTime = DateTime.UtcNow,
                        ModifyTime = DateTime.UtcNow
                    });
                }

                return(await db.SaveChangesAsync() > 0);
            }
        }
Пример #8
0
            public async Task Reset(IUser User = null)
            {
                if (User == null)
                {
                    await Context.Channel.SendMessageAsync("Please specify who you want to reset");

                    return;
                }
                if (User.IsBot)
                {
                    return;
                }
                SocketGuildUser User1 = Context.User as SocketGuildUser;

                if (!User1.GuildPermissions.Administrator)
                {
                    await Context.Channel.SendMessageAsync("You dont have admin permission to execute this command");

                    return;
                }
                await Context.Channel.SendMessageAsync($":skull: {User.Mention}, you have been reset by {Context.User.Username}! This means you have lost all your clams!");

                using (var DbContext = new SqliteDbContext())
                {
                    DbContext.Clams.RemoveRange(DbContext.Clams.Where(x => x.UserID == User.Id));
                    await DbContext.SaveChangesAsync();
                }
            }
Пример #9
0
        public async Task ResetEXP(IUser User = null)
        {
            if (User == null)
            {
                await Context.Channel.SendMessageAsync($"You need to specify a user to reset (e.g. ?ResetEXP {Context.User.Mention}");

                return;
            }

            if (User.IsBot)
            {
                await Context.Channel.SendMessageAsync("Bots cannot be reset.");

                return;
            }

            SocketGuildUser User1 = Context.User as SocketGuildUser;

            if (!User1.GuildPermissions.Administrator)
            {
                await Context.Channel.SendMessageAsync($"You don't have administrator permissions in this server.");

                return;
            }
            await Context.Channel.SendMessageAsync($"{User.Mention}'s experience points have been reset.");

            using (var DbContext = new SqliteDbContext())
            {
                DbContext.ExperiencePoints.RemoveRange(DbContext.ExperiencePoints.Where(x => x.UserId == User.Id));
                await DbContext.SaveChangesAsync();
            }
        }
Пример #10
0
 public static async Task SetAdminRoles(ulong guildId, ulong[] roleIds)
 {
     try
     {
         using (var DbContext = new SqliteDbContext())
         {
             CreateGuildConfig(guildId).GetAwaiter().GetResult();//guild config not found
             GuildConfigEntity guild = DbContext.GuildConfig.Where(y => y.GuildId == guildId).FirstOrDefault();
             DbContext.AdminRoles.RemoveRange(guild.AdminRoles);
             foreach (ulong role in roleIds)
             {
                 DbContext.AdminRoles.Add(new AdminRoleEntity()
                 {
                     GuildId = guild.GuildId,
                     RoleId  = role
                 });
             }
             await DbContext.SaveChangesAsync();
         }
     }
     catch
     {
         //TODO: Log exception, more specified description
         throw;
     }
 }
Пример #11
0
            public async Task Reset(IUser User = null)
            {
                //checks
                if (User == null)
                {
                    await Context.Channel.SendMessageAsync($":x: You need to tell me which user you want to reset the stones of! For example >>stone reset {Context.User.Username}");

                    return;
                }
                if (User.IsBot)
                {
                    await Context.Channel.SendMessageAsync($":x: Bot can't use this bot, you also can't reset progress of a bot");
                }
                SocketGuildUser User1 = Context.User as SocketGuildUser;

                if (!User1.GuildPermissions.Administrator)
                {
                    await Context.Channel.SendMessageAsync($":x: you don't have the addminisrator permission in this discord server! Ask a moderator ot the owen to execute this command!");

                    return;
                }
                //execution
                await Context.Channel.SendMessageAsync($":skull: {User.Mention}, you have been reset by {Context.User.Username}, This means you have lost all your stones!");

                //save

                using (var DbContext = new SqliteDbContext())
                {
                    //the linq statement is sql, and it return a list.
                    DbContext.Stones.RemoveRange(DbContext.Stones.Where(x => x.UserID == User.Id));
                    await DbContext.SaveChangesAsync();
                }
            }
        public async Task <ConnectionHistory> Add(ConnectionHistory model)
        {
            var result = _myDbContext.ConnectionHistories.Add(model);
            await _myDbContext.SaveChangesAsync();

            return(result);
        }
Пример #13
0
            public async Task Reset(IUser User = null)
            {
                if (User == null) //another admin command, to delete the user from the database entirely.
                {
                    await Context.Channel.SendMessageAsync($":x: You need to specify the user you wish to delete...");

                    return;
                }
                if (User.IsBot)
                {
                    await Context.Channel.SendMessageAsync("I dont have any progress... Tell Aki to let me play too! :robot:");

                    return;
                }
                SocketGuildUser User1 = Context.User as SocketGuildUser;

                if (!User1.GuildPermissions.Administrator)
                {
                    await Context.Channel.SendMessageAsync(":x: You need admin permissions for this command! :x:");

                    return;
                }

                await Context.Channel.SendMessageAsync($":skull: {User.Mention}, you have been terminated by {Context.User.Username}! This means you lost all of your gold! Boo Hoo!");

                using (var DbContext = new SqliteDbContext())
                {
                    DbContext.Golds.RemoveRange(DbContext.Golds.Where(x => x.UserId == User.Id));
                    await DbContext.SaveChangesAsync();
                }
            }
Пример #14
0
        private async Task <SqliteDbContext> GetSqliteDbContextAsync()
        {
            var options = new DbContextOptionsBuilder <SqliteDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var sqliteDbContext = new SqliteDbContext(options);

            sqliteDbContext.SampleEntity.Add(new Infrastructure.Entities.SampleEntity
            {
                Id            = 1,
                BoolValue     = false,
                DateTimeValue = DateTime.Now,
                StringValue   = "sample"
            });

            sqliteDbContext.SampleEntity.Add(new Infrastructure.Entities.SampleEntity
            {
                Id            = 2,
                BoolValue     = false,
                DateTimeValue = DateTime.Now,
                StringValue   = "ping"
            });
            await sqliteDbContext.SaveChangesAsync();

            return(sqliteDbContext);
        }
Пример #15
0
        public async Task Reset(IUser target = null, string reason = "No reason provided.")
        {
            SocketGuildUser User1 = Context.User as SocketGuildUser;

            if (!User1.GuildPermissions.Administrator) //Make sure user issuing command is admin
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you don't have administrator permissions in this discord server! Ask a administrator or the owner to execute this command!");

                return;
            }

            if (target == null) //Make sure a user was pinged
            {
                await Context.Channel.SendMessageAsync($"You need to tell me which user you want to reset the gold of! For example: !gold reset {Context.User.Mention}");

                return;
            }

            if (target.IsBot) //Make sure pinged user isn't a bot
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, bots can't use gold, so you also can't reset the progress of bots! :robot:");

                return;
            }
            await Context.Channel.SendMessageAsync($"{target.Mention}, you have been reset by {Context.User.Mention}! This means you have lost all your gold!");

            await ModLog.PostInModLog(Context.Guild, "Reset Gold", Context.User, target as IGuildUser, reason);

            //Remove the gold
            using (SqliteDbContext DBContext = new SqliteDbContext())
            {
                DBContext.Gold.RemoveRange(DBContext.Gold.Where(x => x.UserId == target.Id && x.Serverid == Context.Guild.Id));
                await DBContext.SaveChangesAsync();
            }
        }
Пример #16
0
        public async Task <ActionResult <UserDto> > Register(UserRegisterDto registerDto)
        {
            if (await UserExists(registerDto.UserName))
            {
                return(BadRequest("Username is taken"));
            }

            using var hmac = new HMACSHA512();

            var user = new User
            {
                UserName     = registerDto.UserName.ToLower(),
                PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(registerDto.Password)),
                PasswordSalt = hmac.Key,
                Age          = registerDto.Age
            };

            _dataContext.Add(user);
            await _dataContext.SaveChangesAsync();

            return(new UserDto
            {
                UserName = user.UserName,
                Age = user.Age,
                Token = _tokenService.CreateToken(user)
            });
        }
Пример #17
0
            public async Task Reset(IUser User = null)
            {
                if (User == null)
                {
                    // No user has been mentioned
                    await Context.Channel.SendMessageAsync($":x: You need to mention which user to reset ounces for! e.g. !ounces reset {Context.User.Mention}");

                    return;
                }

                if (User.IsBot)
                {
                    await Context.Channel.SendMessageAsync(":x: Bots aren't people!");

                    return;
                }

                SocketGuildUser User1 = Context.User as SocketGuildUser;

                if (!User1.GuildPermissions.Administrator)
                {
                    await Context.Channel.SendMessageAsync(":x: You don't have the permissions to use this comand! Please ask a moderator to do so.");

                    return;
                }

                await Context.Channel.SendMessageAsync($":skull: {User.Mention}, you have been reset by {Context.User.Username}. Your ounces are now 0.");

                using (var DbContext = new SqliteDbContext()) {
                    DbContext.ounces.RemoveRange(DbContext.ounces.Where(x => x.UserId == User.Id));
                    await DbContext.SaveChangesAsync();
                }
            }
Пример #18
0
 /// <summary>
 /// Adds gold to the amount the user currently has.
 /// </summary>
 /// <param name="userId">The user ID to look for</param>
 /// <param name="amount">The amount to add</param>
 /// <param name="serverId">The guild ID to look for</param>
 /// <param name="username">The user's username</param>
 public static async Task SaveGold(ulong userId, int amount, ulong serverId, string username = "")
 {
     using (SqliteDbContext DbContext = new SqliteDbContext())
     {
         //Check if the guild has a spot
         if (DbContext.Gold.Where(x => x.UserId == userId && x.Serverid == serverId).Count() < 1)
         {
             try
             {
                 DbContext.Gold.Add(new Gold
                 {   //Create an entry for this user in this guild if it doesn't exist
                     Serverid = serverId,
                     UserId   = userId,
                     Amount   = amount,
                     Username = username
                 });
             }
             catch (Exception e)
             {
                 Console.WriteLine(e.Message);
             }
         }
         else
         {   //Add the amount of gold to the current and update the database
             Gold Current = DbContext.Gold.Where(x => x.UserId == userId && x.Serverid == serverId).FirstOrDefault();
             Current.Amount += amount;
             DbContext.Gold.Update(Current);
         }
         await DbContext.SaveChangesAsync();
     }
 }
Пример #19
0
 private static async Task CreateGuildConfig(ulong guildId)//creates default guild config
 {
     try
     {
         using (var DbContext = new SqliteDbContext())
         {
             if (DbContext.GuildConfig.Where(x => x.GuildId == guildId).Count() >= 1)
             {
                 return;
             }
             else
             {
                 DbContext.GuildConfig.Add(new GuildConfigEntity
                 {
                     GuildId          = guildId,
                     CommandChannelId = 0,
                     AlertChannelId   = 0,
                     AdminRoles       = new List <AdminRoleEntity>(),
                     Tasks            = new List <Resources.Database.TaskEntity>(),
                     //DeleteAlertMessageTimespan = 604800,
                     DateFormat = 0,
                     Language   = 0
                 });
             }
             await DbContext.SaveChangesAsync();
         }
     }
     catch
     {
         //TODO: Log exception, more specified description
         throw;
     }
 }
Пример #20
0
 //Everything in here uses Sqlite to access the database
 /// <summary>
 /// Set the interest rate on giving gold in the server in whole number form.
 /// Converts to a percentage. Defaults at 5.
 /// </summary>
 /// <param name="serverId">The guild id</param>
 /// <param name="serverName">The guild name</param>
 /// <param name="percentage">The number to change the percentage to. 5 would be 0.05%</param>
 public static async Task SetInterest(ulong serverId, string serverName, int percentage)
 {
     using (SqliteDbContext DbContext = new SqliteDbContext())
     {
         try
         {   //Check if the guild already has a spot
             if (DbContext.GuildLocationSettings.Where(x => x.Serverid == serverId).Count() < 1)
             {
                 DbContext.GuildLocationSettings.Add(new GuildLocationSettings
                 {   //Default the other settings.
                     Serverid       = serverId,
                     WelcomeChannel = 0,
                     ServerName     = serverName,
                     WelcomeMessage = "",
                     BotSpamChannel = 0,
                     GoldInterest   = percentage
                 });
             }
             else
             {   //Override the percentage value
                 GuildLocationSettings Current = DbContext.GuildLocationSettings.Where(x => x.Serverid == serverId).FirstOrDefault();
                 Current.GoldInterest = percentage;
                 DbContext.GuildLocationSettings.Update(Current);
             } //Update the database
             await DbContext.SaveChangesAsync();
         }
         catch (Exception)
         { }
     }
 }
        public async Task <int> Update(AppConfiguration model)
        {
            var appConf = await _myDbContext.AppConfigurations.FindAsync(model.Id);

            appConf = model;
            return(await _myDbContext.SaveChangesAsync());
        }
Пример #22
0
        /// <summary>
        /// Remove warnings from the user's amountr
        /// </summary>
        /// <param name="userId">The user ID to look for</param>
        /// <param name="serverId">The guild ID to look for</param>
        /// <param name="username">The username of the user</param>
        /// <param name="amount">The amount of warnings to remove, defaulted at 1</param>
        /// <returns></returns>
        public static async Task RemoveWarnings(ulong userId, ulong serverId, string username, int amount = 1)
        {
            using (SqliteDbContext DbContext = new SqliteDbContext())
            {
                //Check if the guild has a spot
                if (DbContext.Warnings.Where(x => x.UserId == userId && x.Serverid == serverId).Count() > 0)
                {
                    //Check if the spot has an amount
                    if (DbContext.Warnings.Where(x => x.UserId == userId && x.Serverid == serverId).Select(x => x.AmountOfWarnings).FirstOrDefault() > 0)
                    {
                        Warning Current = DbContext.Warnings.Where(x => x.UserId == userId && x.Serverid == serverId).FirstOrDefault();
                        Current.AmountOfWarnings -= amount;
                        if (Current.AmountOfWarnings < 0)
                        {
                            Current.AmountOfWarnings = 0;
                        }
                        DbContext.Warnings.Update(Current);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }

                await DbContext.SaveChangesAsync();
            }
        }
Пример #23
0
 public static async Task SaveExperience(ulong UserId, int Experience = 10)
 {
     using (var DbContext = new SqliteDbContext()) {
         if (DbContext.Users.Where(x => x.UserID == UserId).Count() < 1)
         {
             DbContext.Users.Add(new User
             {
                 UserID     = UserId,
                 Stones     = 0,
                 Level      = 1,
                 Experience = 0,
             });
         }
         else
         {
             User Current = DbContext.Users.Where(x => x.UserID == UserId).FirstOrDefault();
             Current.Experience += Experience;
             int Level = (int)(MathF.Floor(25 + MathF.Sqrt(625 + 100 * Current.Experience)) / 50);
             if (Level != Current.Level)
             {
                 Current.Level += 1;
             }
             DbContext.Users.Update(Current);
         }
         await DbContext.SaveChangesAsync();
     }
 }
Пример #24
0
 /// <summary>
 /// Sets a channel to send all moderator activites the bot is used for into.
 /// </summary>
 /// <param name="serverId">The guild ID to look for.</param>
 /// <param name="channelId">The channel ID to set.</param>
 /// <param name="serverName">The name of the guild.</param>
 public async static Task SetModLogChannel(ulong serverId, ulong channelId, string serverName)
 {
     using (SqliteDbContext DbContext = new SqliteDbContext())
     {
         try
         {   //Check if the guild has a spot
             if (DbContext.GuildLocationSettings.Where(x => x.Serverid == serverId).Count() < 1)
             {
                 DbContext.GuildLocationSettings.Add(new GuildLocationSettings
                 {
                     Serverid       = serverId,
                     WelcomeChannel = 0,
                     ServerName     = serverName,
                     WelcomeMessage = "",
                     BotSpamChannel = channelId,
                     GoldInterest   = 5,
                     ChatLogChannel = 0,
                     ModLogChannel  = 0
                 });
             }
             else
             {
                 GuildLocationSettings Current = DbContext.GuildLocationSettings.Where(x => x.Serverid == serverId).FirstOrDefault();
                 Current.ModLogChannel = channelId;
                 Current.ServerName    = serverName;
                 DbContext.GuildLocationSettings.Update(Current);
             }
             await DbContext.SaveChangesAsync();
         }
         catch (Exception)
         { }
     }
 }
Пример #25
0
        public static int removeCoins(ulong userID, int coins, int itemID)
        {
            int ret = 0;

            using (var DBContext = new SqliteDbContext())
            {
                if (DBContext.myUser.Where(x => x.UserID == userID).Count() < 1)
                {
                    DBContext.myUser.Add(new MyUser
                    {
                        UserID = userID,
                        Coins  = 0
                    });
                    ret = 1;
                }
                else
                {
                    MyUser current = DBContext.myUser.Where(x => x.UserID == userID).FirstOrDefault();
                    if (current.Coins >= coins)
                    {
                        current.Coins -= coins;
                        addItem(userID, itemID);
                        DBContext.myUser.Update(current);
                        ret = 0;
                    }
                    else
                    {
                        ret = 1;
                    }
                }
                DBContext.SaveChangesAsync();
                return(ret);
            }
        }
Пример #26
0
        /// <summary>
        /// Saves a custom command created in a guild.
        /// </summary>
        /// <param name="serverId">The guild ID to look for</param>
        /// <param name="destination">Where the custom command gets sent to. Either a message in a channel or a DM.</param>
        /// <param name="commandName">The name of the command</param>
        /// <param name="command">What the command does.</param>
        /// <param name="descrption">The description of the command shown in the "CustomCommands" command.</param>
        public async static Task AddCustomCommand(ulong serverId, string destination, string commandName, string command, string descrption = "")
        {
            using (SqliteDbContext DbContext = new SqliteDbContext())
            {
                try
                {   //Check if the guild has a spot
                    if (DbContext.CustomCommands.Where(x => x.Serverid == serverId && x.CommandName == commandName).Count() < 1)
                    {
                        CustomCommands Current = new CustomCommands
                        {
                            Serverid           = serverId,
                            Destination        = destination,
                            CommandName        = commandName,
                            Command            = command,
                            CommandDescription = descrption
                        };
                        DbContext.CustomCommands.Add(Current);
                    }
                    else
                    {
                        CustomCommands Current = DbContext.CustomCommands.Where(x => x.Serverid == serverId && x.CommandName == commandName).FirstOrDefault();
                        Current.Destination = destination;
                        Current.Command     = command;
                    }

                    await DbContext.SaveChangesAsync();
                }
                catch (Exception)
                { }
            }
        }
Пример #27
0
            public async Task removeFile(int projectID, int fileID)
            {
                //check if user is project owner
                using (var dbContext = new SqliteDbContext())
                {
                    if (dbContext.Projects.Where(x => x.ProjectId == projectID).Count() < 1)
                    {
                        await Context.Channel.SendMessageAsync($"project with id {projectID} do not exists, pleaese try another ID!");

                        return;
                    }
                    else if (dbContext.Files.Where(x => x.ProjectId == projectID && x.FileId == fileID).Count() < 1)
                    {
                        await Context.Channel.SendMessageAsync($"There is no file {fileID} in project {projectID}");

                        return;
                    }
                    else if (dbContext.Projects.Where(x => x.ProjectId == projectID).FirstOrDefault().UserId != Context.User.Id)
                    {
                        await Context.Channel.SendMessageAsync("You are not the owner of the project, please contact the owner");
                    }

                    dbContext.Files.Remove(dbContext.Files.Where(x => x.ProjectId == projectID && x.FileId == fileID).FirstOrDefault());
                    await Context.Channel.SendMessageAsync($"File {fileID} removed from project {projectID}!");

                    await dbContext.SaveChangesAsync();
                }
            }
Пример #28
0
        public async Task <Network2DNS> Add(Network2DNS model)
        {
            var result = _myDbContext.Network2DNSes.Add(model);
            await _myDbContext.SaveChangesAsync();

            return(result);
        }
Пример #29
0
            public async Task Reset(IUser User = null)
            {
                //checks
                if (User == null)
                {
                    await Context.Channel.SendMessageAsync($":x: You need to tell me which user you want to reset the flowers of! !flowers reset {Context.User.Mention}");

                    return;
                }

                if (User.IsBot)
                {
                    await Context.Channel.SendMessageAsync(":x: Bots can't use this bot, so you also can't reset the progress of bots! :robot:");
                }

                SocketGuildUser User1 = Context.User as SocketGuildUser;

                if (!User1.GuildPermissions.Administrator)
                {
                    await Context.Channel.SendMessageAsync($":x: You don't have administrator permissions in this discord server! Ask a moderator or the owner to execute this command!");

                    return;
                }

                //Execution
                await Context.Channel.SendMessageAsync($":skull: {User.Mention}, you have been reset by {Context.User.Username}! This means you lost all of your flowers!");

                //Saving the database
                using (var DbContext = new SqliteDbContext())
                {
                    DbContext.Flowers.RemoveRange(DbContext.Flowers.Where(x => x.UserId == User.Id));
                    await DbContext.SaveChangesAsync();
                }
            }
Пример #30
0
        //Saves the messages amount
        public static async Task SaveMessagesAmount(ulong UserId, uint Amount, string name)
        {
            //uses the Database
            using (var DbContext = new SqliteDbContext())
            {
                //sees if there isnt a record for that user and makes one
                if (DbContext.spam.Where(x => x.UserId == UserId).Count() < 1)
                {
                    DbContext.spam.Add(new Spam
                    {
                        UserId       = UserId,
                        MessagesSend = Amount,
                        Name         = name
                    });
                }
                //if there is a record updates the curent Amount
                else
                {
                    Spam Curent = DbContext.spam.Where(x => x.UserId == UserId).FirstOrDefault();
                    Curent.MessagesSend += Amount;
                    DbContext.spam.Update(Curent);
                }

                //restores the real time message amount to 0
                MessageAmmount = 0;

                //Syncs the Database
                await DbContext.SaveChangesAsync();
            }
        }