Exemplo n.º 1
0
        public static async Task AddFlowersAsync(Discord.User u, string reason, int amount, bool silent = false)
        {
            if (amount <= 0)
            {
                return;
            }
            await Task.Run(() =>
            {
                DbHandler.Instance.Connection.Insert(new DataModels.CurrencyTransaction
                {
                    Reason = reason,
                    UserId = (long)u.Id,
                    Value  = amount,
                });
            }).ConfigureAwait(false);

            if (silent)
            {
                return;
            }

            var flows = amount + " " + MidnightBot.Config.CurrencySign;

            await u.SendMessage("Glückwunsch!👑\nDu hast folgendes erhalten: " + flows).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public static async Task <bool> RemoveFlowers(Discord.User u, string reason, int amount, bool silent = false, string message = "👎`Bot Owner hat: {0}{1} von dir entfernt.`")
        {
            if (amount <= 0)
            {
                return(false);
            }
            var uid   = (long)u.Id;
            var state = DbHandler.Instance.FindOne <DataModels.CurrencyState>(cs => cs.UserId == uid);

            if (state.Value < amount)
            {
                return(false);
            }

            DbHandler.Instance.Connection.Insert(new DataModels.CurrencyTransaction
            {
                Reason = reason,
                UserId = (long)u.Id,
                Value  = -amount,
            });
            if (silent)
            {
                return(true);
            }

            await u.SendMessage(string.Format(message, amount, MidnightBot.Config.CurrencySign)).ConfigureAwait(false);

            return(true);
        }
Exemplo n.º 3
0
        public static async Task AddFlowersAsync(Discord.User u, string reason, int amount, bool silent = false)
        {
            if (amount <= 0)
            {
                return;
            }
            await Task.Run(() =>
            {
                DbHandler.Instance.InsertData(new DataModels.CurrencyTransaction
                {
                    Reason = reason,
                    UserId = (long)u.Id,
                    Value  = amount,
                });
            }).ConfigureAwait(false);

            if (silent)
            {
                return;
            }

            var flows = "";

            for (var i = 0; i < amount; i++)
            {
                flows += NadekoBot.Config.CurrencySign;
            }
            await u.SendMessage("👑Congratulations!👑\nYou received: " + flows).ConfigureAwait(false);
        }
Exemplo n.º 4
0
        public static async Task AddFlowersAsync(Discord.User u, string reason, int amount)
        {
            if (amount <= 0)
            {
                return;
            }
            await Task.Run(() => {
                DBHandler.Instance.InsertData(new _DataModels.CurrencyTransaction {
                    Reason = reason,
                    UserId = (long)u.Id,
                    Value  = amount,
                });
            });

            string flows = "";

            for (int i = 0; i < amount; i++)
            {
                flows += "🌸";
            }
            await u.SendMessage("👑Congratulations!👑\nYou got: " + flows);
        }
Exemplo n.º 5
0
    public UnspecificUserInfo ChangeStrikes(Discord.Server Server, ulong UserID, int Change)
    {
        const int NUMSTRIKESFORKICK = 2;
        const int NUMSTRIKESFORBAN  = 3;

        // Setup variables
        UnspecificUserInfo     InitialUserInfo       = Modules.DataModule.GetUserInfo(UserID);
        ServerSpecificUserInfo InitialUserServerInfo = Modules.DataModule.GetUserServerInfo(UserID, Server.Id);

        Discord.User User = Modules.UserModule.GetUserByID(UserID, Server).User;

        // Check if the user was NOT found...
        if (!Modules.UserModule.GetUserByID(UserID, Server).WasFound)
        {
            // and return an empty user info.
            return(InitialUserInfo);
        }

        int NewNumberOfStrikes = InitialUserServerInfo.NumStrikes + Change; // will calculate the new number of strikes CUZ ( +- = -)

        if (Change == 0)
        {
            goto end; // Nothing to change!
        }
        else if (Change > 0)
        {
            User.SendMessage($"Be carefull! You just recieved {Change} strikes (total number of strikes: {NewNumberOfStrikes}). {NUMSTRIKESFORKICK} strikes is a kick and {NUMSTRIKESFORBAN} is a ban!");
        }
        else if (Change < 0)
        {
            if (Modules.DataModule.GetUserServerInfo(UserID, Server.Id).NumStrikes == 0)
            {
                goto end; // Do nothing as the user cannot have sub-zero strikes!
            }
            else
            {
                User.SendMessage($"{Change * -1} strikes just got revoked to give you a total of {NewNumberOfStrikes} strikes. {NUMSTRIKESFORKICK} strikes is a kick and {NUMSTRIKESFORBAN} is a ban!");
            }
        }

        // Create a new ServerSpecificUserInfo struct with the update ammount of strikes.
        ServerSpecificUserInfo NewServerUserInfo = InitialUserServerInfo;

        NewServerUserInfo.NumStrikes = NewNumberOfStrikes;
        // Create a new UserInfo based on the origional user info to house the new ServerUserInfo
        UnspecificUserInfo NewUserInfo = InitialUserInfo;

        // Find the server's list index in the new userinfo.
        int index = NewUserInfo.ServerInfo.FindIndex(d => d.ServerID == NewServerUserInfo.ServerID);

        // And set the above index of the list to the new serveruserinfo.
        NewUserInfo.ServerInfo[index] = NewServerUserInfo;
        // TODO extract above (update UserServer info) into function or something.

        Modules.DataModule.UpdateUserInfo(NewUserInfo);

        // Check if the user has enough strikes to get kicked
        if (Modules.DataModule.GetUserServerInfo(UserID, Server.Id).NumStrikes == NUMSTRIKESFORKICK)
        {
            // TODO make a rejoinmsg.
            User.SendMessage($"You got a total of {NewNumberOfStrikes} strikes, this is more than {NUMSTRIKESFORKICK} so you got kicked!");
            // Now kick the user TODO: be sure that User.Kick(); is actually the right command :D
            User.Kick();
        }
        // Check if the user has enough strikes for a ban.
        else if (Modules.DataModule.GetUserServerInfo(UserID, Server.Id).NumStrikes >= NUMSTRIKESFORBAN)
        {
            // Send the user a message telling them they got banned as they had more than the ban threshhold strikes.
            User.SendMessage($"You got a total of {NewNumberOfStrikes} strikes, this is more than {NUMSTRIKESFORBAN} so you got banned!");
            // And then actually ban them from the server
            Server.Ban(Modules.UserModule.GetUserByID(UserID, Server).User);
        }
        // an end goto for stuff that doesnt need to process the ammount of strikes etc. When strikes are not processed it will automagically fall through to this.
end:
        // Get and return the updated user info
        return(Modules.DataModule.GetUserInfo(UserID));
    }