Example #1
0
        public static async Task SetMain(string _charactername, IUser user, ICommandContext _context)
        {
            UserDataSet userDataSet = UserData.FirstOrDefault(x => x.userID == user.Id);

            if (userDataSet == null)
            {
                await _context.Channel.SendMessageAsync($"An Exception occured. Could not find user: `{user.Id}` in the database."); return;
            }

            UserCharacter userCharacter = userDataSet.characters.FirstOrDefault(x => x.name.ToLower() == _charactername.ToLower());

            if (userCharacter == null)
            {
                await _context.Channel.SendMessageAsync($"An Exception occured. Could not find Character: `{_charactername}` for userd `{user.Id}`"); return;
            }

            if (userCharacter.pending)
            {
                await _context.Channel.SendMessageAsync("That character is still pending confirmation."); return;
            }

            foreach (UserCharacter character in userDataSet.characters)
            {
                character.main = false;
            }
            userCharacter.main = true;

            try { await(user as IGuildUser).ModifyAsync(x => x.Nickname = ""); } catch { }
            try { await(user as IGuildUser).RemoveRolesAsync(ServerRoles); } catch { }

            await user.SendMessageAsync("You have been assigned a new main character. Please run `aq sync` to resynchronise to your new main.");

            SaveUserData();
        }
Example #2
0
        public static async Task <String> GetCharacterName(UserCharacter userCharacter, ICommandContext _context)
        {
            Character character = (await warcraftClient.GetCharacterAsync(userCharacter.realm, userCharacter.name, CharacterFields.All)).Value;

            if (character == null)
            {
                await _context.Channel.SendMessageAsync($"Could not find Character: {userCharacter.name}-{userCharacter.realm} in the World of Warcraft Database. "); return(null);
            }

            return(character.Name);
        }
Example #3
0
 public static async Task InspectUser(ICommandContext _Context, bool isIUser, IGuildUser guildUser, string characterName, string CharacterServer)
 {
     if (isIUser)
     {
         if (guildUser == null)
         {
             return;
         }
         UserDataSet   userToInspect = UserData.FirstOrDefault(x => x.userID == guildUser.Id);
         UserCharacter character     = userToInspect.characters.FirstOrDefault(x => x.main == true);
         await WoWService.InspectCharacter(character.name, character.realm, _Context);
     }
     else
     {
         await WoWService.InspectCharacter(characterName, CharacterServer, _Context);
     }
 }
Example #4
0
        public static async Task SyncChar(ICommandContext _context)
        {
            UserDataSet userDataSet = UserData.FirstOrDefault(x => x.userID == _context.User.Id);

            if (userDataSet == null)
            {
                return;
            }
            UserCharacter mainCharacter = userDataSet.characters.FirstOrDefault(x => x.main == true);

            if (mainCharacter == null)
            {
                return;
            }

            if (mainCharacter.pending)
            {
                await _context.Channel.SendMessageAsync("That character is still pending confirmation."); return;
            }

            string characterName = await WoWService.GetCharacterName(mainCharacter, _context);

            if (characterName == null)
            {
                return;
            }
            try { await(_context.User as IGuildUser).ModifyAsync(x => x.Nickname = characterName); }
            catch { }

            int RoleNumber = await WoWService.GetCharacterGuildRank(mainCharacter.name, mainCharacter.realm, _context, false);

            if (RoleNumber == -12)
            {
                await(_context.User as IGuildUser).AddRoleAsync(Program.guild.Roles.FirstOrDefault(x => x.Name.ToLower() == "temp"));
            }
            else
            {
                try { await(_context.User as IGuildUser).AddRoleAsync(ServerRoles[RoleNumber]); }
                catch {}
            }
            userDataSet.LastSync = DateTime.Now;
            await _context.Channel.SendMessageAsync("Successfully synced.");
        }
Example #5
0
        public static async Task LinkCharacter(string _characterName, string _realmName, ICommandContext _context)
        {
            UserDataSet userDataSet = UserData.FirstOrDefault(x => x.userID == _context.User.Id);

            if (userDataSet == null)
            {
                return;
            }

            if (UserData.Any(x => x.characters.Any(y => y.name == _characterName && y.realm == _realmName)))
            {
                await _context.Channel.SendMessageAsync("That character is already linked to someone. Contact an administrator if this is your character.");

                return;
            }

            UserCharacter charToLink = new UserCharacter();

            charToLink.Initialize(_characterName, _realmName);
            userDataSet.characters.Add(charToLink);
            SaveUserData();

            await _context.Channel.SendMessageAsync("A Commander has to confirm the character have requested to link is yours. The commanders have been notified and will whisper you asap. The bot will notify you with a DM once your pending status has been cleared.");

            IMessageChannel notifyChannel = Program.guild.Channels.FirstOrDefault(x => x.Id == NotifyChannelID) as IMessageChannel;

            int rankNumber = await WoWService.GetCharacterGuildRank(_characterName, _realmName, _context);

            if (rankNumber == -1)
            {
                return;
            }

            string assignedRankString = rankNumber != 12 ? ServerRoles[rankNumber].Name : "UNKNOWN";

            await notifyChannel.SendMessageAsync(
                "__**New pending user:**__ \n" +
                "Name: `" + _context.User.Username + "`\n" +
                "Character: `" + charToLink.name + "`\n" +
                "Realm: `" + charToLink.realm + "`\n" +
                "GuildRank: `" + assignedRankString + "`\n" +
                "DiscordMention: `" + _context.User.Mention + "`");
        }
Example #6
0
        public static async Task RemoveCharlink(IUser user, string _charactername, ICommandContext _context)
        {
            UserDataSet userDataSet = UserData.FirstOrDefault(x => x.userID == user.Id);

            if (userDataSet == null)
            {
                await _context.Channel.SendMessageAsync($"An Exception occured. Could not find user: `{user.Id}` in the database."); return;
            }

            UserCharacter userCharacter = userDataSet.characters.FirstOrDefault(x => x.name.ToLower() == _charactername.ToLower());

            if (userCharacter == null)
            {
                await _context.Channel.SendMessageAsync($"An Exception occured. Could not find Character: `{_charactername}` for userd `{user.Id}`"); return;
            }
            if (userCharacter.main)
            {
                try { await(user as IGuildUser).ModifyAsync(x => x.Nickname = ""); } catch { }
                try { await(user as IGuildUser).RemoveRolesAsync(ServerRoles); } catch { }
                if (userDataSet.characters.Any(x => x.pending = false))
                {
                    await SetMain(userDataSet.characters.FirstOrDefault(x => x.pending == false).name, user, _context);
                }
                else
                {
                    await user.SendMessageAsync("You have no other confirmed characterlinks available. Please link a new character or ask to be confirmed.");
                }
            }
            else
            {
                await user.SendMessageAsync($"Your characterlink for your alt `{userCharacter.name}` has been reset by an administrator.");
            }
            userDataSet.characters.Remove(userCharacter);
            await _context.Channel.SendMessageAsync("User has been reset.");

            SaveUserData();
        }
Example #7
0
        public static async Task ConfirmCharacterLink(IUser user, string _charactername, ICommandContext _context)
        {
            bool   setToMain       = false;
            bool   notFoundInGuild = false;
            string messageString   = "**Exceptions:**";

            UserDataSet userDataSet = UserData.FirstOrDefault(x => x.userID == user.Id);

            if (userDataSet == null)
            {
                await _context.Channel.SendMessageAsync($"An Exception occured. Could not find user: `{user.Id}` in the database."); return;
            }

            UserCharacter userCharacter = userDataSet.characters.FirstOrDefault(x => x.name.ToLower() == _charactername.ToLower());

            if (userCharacter == null)
            {
                await _context.Channel.SendMessageAsync($"An Exception occured. Could not find Character: `{_charactername}` for userd `{user.Id}`"); return;
            }
            userCharacter.pending = false;

            if (!userDataSet.characters.Any(x => x.main == true))
            {
                userCharacter.main = true;
                setToMain          = true;

                string characterName = await WoWService.GetCharacterName(userCharacter, _context);

                if (characterName == null)
                {
                    return;
                }
                try { await(user as IGuildUser).ModifyAsync(x => x.Nickname = characterName); }
                catch { messageString += "\n - A problem occured while changing the nickname."; }

                int RoleNumber = await WoWService.GetCharacterGuildRank(userCharacter.name, userCharacter.realm, _context, false);

                if (RoleNumber == -12)
                {
                    await(user as IGuildUser).AddRoleAsync(Program.guild.Roles.FirstOrDefault(x => x.Name.ToLower() == "temp"));
                    notFoundInGuild = true;
                }
                else
                {
                    try { await(user as IGuildUser).AddRoleAsync(ServerRoles[RoleNumber]); }
                    catch { messageString += "\n- Could not synchronise ranks."; }
                }
            }

            if (messageString == "**Exceptions:**")
            {
                messageString = "";
            }
            await _context.Channel.SendMessageAsync("Successfully confirmed the charlink. User has been notified.\n" + messageString);

            string DmString = $"The pending status of your character `{userCharacter.name}` has been cleared and you are now linked to your WoW Character!\n\n";

            if (setToMain)
            {
                DmString += "Since this is your first character you have linked it has been automatically set as your main. \nIf you wish to resynchronise your discord rank with your in-game WoW Rank then use the command `aq sync`! \n\n";
            }
            if (!setToMain)
            {
                DmString += $"Since this is not your first character you have linked it will not be set to your main. If you do want this character to be your main you can use the command `aq setMain {userCharacter.name}`\n\n";
            }
            if (notFoundInGuild)
            {
                DmString += "Your character was not found in the guild. This could mean that the World of Warcraft API is lagging behind a bit (or you have just joined the guild), You've been granted a temporary rank. **You should use the command `aq sync` every hour untill your rank has been succesfully synchronised.**\n\n";
            }
            DmString += "**Thank you for your patience and enjoy your stay!**";
            await user.SendMessageAsync(DmString);

            SaveUserData();
        }