示例#1
0
    // Gets the info about specified user.
    public UnspecificUserInfo GetUserInfo(ulong UserID)
    {
        // Declare a default user info to fall back on.
        UnspecificUserInfo Info = new UnspecificUserInfo(UserID);
        bool WasFound           = false;

        // Go through all the users.
        foreach (UnspecificUserInfo UserInfo in UsersInfos)
        {
            // If it finds a matching user ID...
            if (UserInfo.UserID == UserID)
            {
                // Set the info, be sure the system knows the users info was found and exit the loop.
                Info     = UserInfo;
                WasFound = true;
                break;
            }
        }

        // If there wasen't a valid user's info found, that means it needs to create a new user's info.
        if (!WasFound || Info.Equals(null))
        {
            UsersInfos.Add(new UnspecificUserInfo(UserID));
            Info = GetUserInfo(UserID);
        }

        return(Info);
    }
示例#2
0
    public ServerSpecificUserInfo GetUserServerInfo(ulong UserID, ulong ServerID)
    {
        UnspecificUserInfo     UserInfo     = GetUserInfo(UserID);
        ServerSpecificUserInfo SearchResult = new ServerSpecificUserInfo(ServerID);
        bool WasServerFound = false;

        foreach (ServerSpecificUserInfo ServerSpecifics in UserInfo.ServerInfo)
        {
            // TODO be sure that a server gets autoadded to a user on join (AND NOT ONLY THE FIRST SERVER THEY JOIN LIKE NOW!!!!!!)
            if (ServerSpecifics.ServerID == ServerID)
            {
                // The server with a matching ID was found!
                SearchResult   = ServerSpecifics;
                WasServerFound = true;
                break;
            }
        }

        // Search was completed, now if there wheren't any servers found that means it needs to add the server to the users servers!
        if (!WasServerFound)
        {
            UserInfo.ServerInfo.Add(SearchResult);
        }

        return(SearchResult);
    }
示例#3
0
 public void AddXP(int Ammount, ulong UserID)
 {
     if (DateTime.Now >= Modules.DataModule.GetUserInfo(UserID).LastXPGain.Add(TIMEBETWEENXPGAINS))
     {
         UnspecificUserInfo InitialUserInfo = Modules.DataModule.GetUserInfo(UserID);
         UnspecificUserInfo NewUserInfo     = InitialUserInfo;
         NewUserInfo.XP         = InitialUserInfo.XP + Ammount;
         NewUserInfo.LastXPGain = DateTime.Now;
         Modules.DataModule.UpdateUserInfo(NewUserInfo);
     }
 }
示例#4
0
    // Updates the inputter users info. Find the one to update by the user info's id.
    public void UpdateUserInfo(UnspecificUserInfo NewUserInfo)
    {
        // Get the index of the current user's id
        int index = UsersInfos.FindIndex(d => d.UserID == NewUserInfo.UserID);

        // Set's the list element at the above found index to the new (user) info.
        UsersInfos[index] = NewUserInfo;

        // As the data has been updated, save it to a file to be sure data has been saved in case of unexpected crashes. (and onexit plain not working :P)
        Modules.SaveModule.SaveUserData(UsersInfos);

        // TODO double check if this creates a new user if the user doesnt exist!!!
    }
示例#5
0
    // TODO extract this back to the send event?
    public void MessageSent(ulong UserID)
    {
        UnspecificUserInfo InitialUserInfo = Modules.DataModule.GetUserInfo(UserID);
        int NewNumMessagesSent             = InitialUserInfo.NumMessagesSent + 1;
        UnspecificUserInfo NewUserInfo     = InitialUserInfo;

        NewUserInfo.NumMessagesSent = NewNumMessagesSent;

        Modules.DataModule.UpdateUserInfo(NewUserInfo);

        // Add XP (if last message sent was X ago, but that is set by params and in AddXP etc)
        Random RandomNumberGen = new Random();
        int    XPToAdd         = RandomNumberGen.Next(10, 25); // TODO make these params!

        Modules.XPModule.AddXP(XPToAdd, UserID);
    }
    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));
    }