Ejemplo n.º 1
0
        public static async Task DenyCharacterLink(IUser user, string _charactername, ICommandContext _context)
        {
            UserDataSet userDataSet = UserData.FirstOrDefault(x => x.userID == user.Id);

            if (userDataSet == null)
            {
                return;
            }
            userDataSet.characters.Remove(userDataSet.characters.FirstOrDefault(x => x.name == _charactername));
            SaveUserData();
            await _context.Channel.SendMessageAsync($"Successfully denied the charlink for character ´{_charactername}´. User has been notified.");

            await user.SendMessageAsync($"Unfortunetly it has been found that the character you are trying to link to named {_charactername} is not yours. Your characterlink request has been cleared. \n\nIf this truly is you character, please contact an administrator.");
        }
        public static void BuyTickets(ICommandContext context, int id, int amountToBuy)
        {
            GiveAway giveAway = GiveAways[id - 1];

            switch (giveAway.state)
            {
            case GiveAwayState.Cancelled:
                context.Channel.SendMessageAsync("Sorry, That giveaway is cancelled! You cannot buy tickets.");
                return;

            case GiveAwayState.Ended:
                context.Channel.SendMessageAsync("Sorry, That giveaway has aleady ended! You cannot buy tickets.");
                return;

            case GiveAwayState.Pending:
                context.Channel.SendMessageAsync("Sorry, That giveaway has not yet started and is in pending status! You cannot buy tickets yet. Wait untill the status is `open`.");
                return;
            }

            UserDataSet userDataSet = UserDataService.UserData.FirstOrDefault(x => x.userID == context.User.Id);

            if (userDataSet.drak - (amountToBuy * giveAway.ticketEntryCost) < 0)
            {
                context.Channel.SendMessageAsync("Sorry, you don't have enough Draks to complete this purchase."); return;
            }
            if (giveAway.tickets.Exists(x => x.userDataSet.userID == userDataSet.userID))
            {
                userDataSet.drak -= giveAway.ticketEntryCost * amountToBuy;

                TicketData ticketData = giveAway.tickets.FirstOrDefault(x => x.userDataSet.userID == userDataSet.userID);
                ticketData.userDataSet   = userDataSet;
                ticketData.ticketAmount += amountToBuy;
                context.Channel.SendMessageAsync("Tickets have been successfully bought!");
            }
            else
            {
                userDataSet.drak -= giveAway.ticketEntryCost * amountToBuy;

                TicketData ticketData = new TicketData();
                ticketData.userDataSet   = userDataSet;
                ticketData.ticketAmount += amountToBuy;

                giveAway.tickets.Add(ticketData);
                context.Channel.SendMessageAsync("Tickets have been successfully bought!");
            }
            UserDataService.SaveUserData();
            SaveGiveAways();
            UpdateGiveAwayMessage(giveAway);
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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.");
        }
Ejemplo n.º 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 + "`");
        }
Ejemplo n.º 6
0
        public static void GrantDrak(float amount, IUser user, bool isVoiceTimerElapsed = false)
        {
            UserDataSet userDataSet = UserData.FirstOrDefault(x => x.userID == user.Id);

            if (userDataSet == null)
            {
                Program.LogConsole("USERDATASERVICE", ConsoleColor.Red, $"GrantEXP error - userdata == null for user {user.Username} ({user.Id})"); return;
            }
            ;
            if (isVoiceTimerElapsed)
            {
                if (userDataSet.drakGainedThroughVoicechatTimer >= 200)
                {
                    return;
                }
                userDataSet.drakGainedThroughVoicechatTimer += amount;
            }
            userDataSet.drak += amount;
            SaveUserData();
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
        public static void GrantExp(float amount, IUser user, bool isFirstMessageOfDay = false, bool isFirstVoiceConnectionOfDay = false)
        {
            UserDataSet userDataSet = UserData.FirstOrDefault(x => x.userID == user.Id);

            if (userDataSet == null)
            {
                Program.LogConsole("USERDATASERVICE", ConsoleColor.Red, $"GrantEXP error - userdata == null for user {user.Username} ({user.Id})"); return;
            }
            ;

            while (amount > 0)
            {
                if ((userDataSet.experience + amount) > CalculateRequiredExp(userDataSet.level))
                {
                    float xpToNextLevel = CalculateRequiredExp(userDataSet.level) - userDataSet.experience;
                    userDataSet.level++;
                    userDataSet.experience += xpToNextLevel;
                    amount -= xpToNextLevel;
                    On_LevelUp(userDataSet);
                }
                else
                {
                    userDataSet.experience += amount;
                    amount = 0;
                }
            }
            if (isFirstMessageOfDay)
            {
                userDataSet.FirstMessageOfDay = true;
            }
            if (isFirstVoiceConnectionOfDay)
            {
                userDataSet.FirstConnectionToVoiceOfDay = true;
            }
            SaveUserData();
        }
Ejemplo n.º 9
0
        public static async Task ViewProfile(IGuildUser user, ICommandContext _context) //TODO: Make embedd.
        {
            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;
            }

            Color color;

            switch (user.Status)
            {
            case UserStatus.Offline:
                color = Color.LightGrey;
                break;

            case UserStatus.Online:
                color = Color.Green;
                break;

            case UserStatus.Idle:
                color = Color.LightOrange;
                break;

            case UserStatus.AFK:
                color = Color.LightOrange;
                break;

            case UserStatus.DoNotDisturb:
                color = Color.Red;
                break;

            case UserStatus.Invisible:
                color = Color.LightGrey;
                break;

            default:
                color = Color.LightGrey;
                break;
            }

            EmbedBuilder embed = new EmbedBuilder()
            {
                Title        = (user.Nickname == "" ? user.Username : user.Nickname),
                Description  = $"ID: <{user.Id}>\n\u200B",
                ThumbnailUrl = user.GetAvatarUrl(),
                Color        = color,
                Footer       = new EmbedFooterBuilder()
                {
                    Text = $"User Joined on {user.JoinedAt.Value.Date.ToString("dd/MM/yy")}"
                }
            };

            embed.AddField(new EmbedFieldBuilder()
            {
                Value = $"**Level:** `{userDataSet.level}`\n**Experience:** `{Math.Truncate(100 * userDataSet.experience) / 100}/{Math.Truncate(100 * CalculateRequiredExp(userDataSet.level))/100}` (Total for level: `{CalculateRequiredExp(userDataSet.level) - CalculateRequiredExp(userDataSet.level - 1)}`)\n**Draks:** `{userDataSet.drak}` Ξ\n\u200B", Name = "Profile:"
            });

            string valueString = "";

            // 21 - NameLength= spacing

            foreach (UserCharacter character in userDataSet.characters)
            {
                string pendingstring = character.pending ? "pending" : "confirmed";
                string mainString    = character.main ? "[MAIN]" : "[ALT]";
                valueString += $"• {character.name.First().ToString().ToUpper() + character.name.Substring(1)}-{character.realm.First().ToString().ToUpper() + character.realm.Substring(1)} | Status: {pendingstring} | {mainString}\n";
            }
            valueString += "\n\u200B";
            embed.AddField(new EmbedFieldBuilder()
            {
                Name  = "Characters:",
                Value = valueString
            });

            await _context.Channel.SendMessageAsync(null, false, embed.Build());
        }
Ejemplo n.º 10
0
 //TODO: make Embedd.
 public static void On_LevelUp(UserDataSet userDataSet)
 {
     (Program.guild.GetChannel(600380855537500202) as IMessageChannel).SendMessageAsync($"{Program.guild.GetUser(userDataSet.userID).Mention} has reached level {userDataSet.level}"); userDataSet.drak += 10; Program.guild.GetUser(userDataSet.userID).SendMessageAsync("You've gained 10 Ξ for leveling up!");
 }
Ejemplo n.º 11
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();
        }