Ejemplo n.º 1
0
 public void InviteLink()
 {
     commands.CreateCommand("InviteLink")
     .Parameter("InviteLink", ParameterType.Required)
     .Do(async(e) =>
     {
         if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
         {
             if (e.GetArg("InviteLink").Contains("discord.gg/"))
             {
                 new ServerRepo(new ServerContext()).AddInviteLink(e.User.Id, e.Server.Id,
                                                                   e.GetArg("InviteLink"));
                 await e.Channel.SendMessage(Eng_Default.InviteLinkSet(e.GetArg("InviteLink")));
             }
             else
             {
                 await e.Channel.SendMessage("Invalid invite link");
             }
         }
         else
         {
             await e.Channel.SendMessage(Eng_Default.ServerIsNotVerified());
         }
     });
 }
Ejemplo n.º 2
0
 public void ChannelSettings()
 {
     commands.CreateCommand("LFGChannel")
     .Parameter("CommandType")
     .Parameter("Channel", ParameterType.Optional)
     .Do(async(e) =>
     {
         string returnstring       = "";
         SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
         ServerRepo serverRepo     = new ServerRepo(new ServerContext());
         if (serverRepo.IsServerVerified(e.Server.Id) && serverRepo.IsAdmin(e.User.Id, e.Server.Id))
         {
             if (e.GetArg("CommandType").ToLower() == "set")
             {
                 try
                 {
                     settingsRepo.SetLfgChannel(e.Message.MentionedChannels.First().Id, e.Server.Id);
                     returnstring = "Looking for group channel has been set.";
                 }
                 catch
                 {
                     returnstring = "Failed to set a channel, have you tagged a channel?";
                 }
             }
             else if (e.GetArg("CommandType").ToLower() == "disable")
             {
                 settingsRepo.DisableLfg(e.Server.Id);
                 returnstring = "Looking for group has been disabled.";
             }
         }
         else
         {
             returnstring = Eng_Default.ServerIsNotVerified();
         }
         await e.Channel.SendMessage(returnstring);
     });
 }
Ejemplo n.º 3
0
 public void UniversalRole()
 {
     commands.CreateCommand("Roles")
     .Parameter("Parameter", ParameterType.Unparsed)
     .Do(async(e) =>
     {
         string returnstring;
         ServerRepo serverRepo     = new ServerRepo(new ServerContext());
         SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
         if (serverRepo.IsServerVerified(e.Server.Id))
         {
             try
             {
                 Discord.Role r = RoleSearch(e.Server, e.GetArg("Parameter").ToLower());
                 if (!settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id))
                 {
                     await e.User.AddRoles(r);
                     returnstring = Eng_Default.RoleHasBeenGiven(r.Name);
                 }
                 else
                 {
                     returnstring = Eng_Default.RoleHasBeenDisabled();
                 }
             }
             catch
             {
                 returnstring = Eng_Default.RoleNotFound(e.GetArg("Parameter"));
             }
         }
         else
         {
             returnstring = Eng_Default.ServerIsNotVerified();
         }
         await e.Channel.SendMessage(returnstring);
     });
 }
Ejemplo n.º 4
0
        public void GetRank()
        {
            commands.CreateCommand("Rank")
            .Parameter("rank", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string returnstring = "error";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    try
                    {
                        new RoleManagementTrigger(BotUser, commands).OverrideDeletion(e.Server);
                    }
                    catch
                    {
                    }
                    SettingsRepo settingsRepo = (new SettingsRepo(new SettingsContext()));
                    if (e.GetArg("rank").Split(' ').First() == "delete" ||
                        e.GetArg("rank").Split(' ').First() == "remove")
                    {
                        foreach (string region in Ranks.BasicRanks())
                        {
                            if (region.ToLower() ==
                                e.GetArg("rank")
                                .Substring(e.GetArg("rank").IndexOf(" ") + 1,
                                           e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1)
                                .ToLower())
                            {
                                try
                                {
                                    ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id);
                                    await e.User.RemoveRoles(e.Server.GetRole(id),
                                                             e.Server.FindRoles(region.ToLower(), false).First());
                                    returnstring = Eng_Default.RoleHasBeenRemoved(region);
                                }
                                catch
                                {
                                }
                            }
                        }
                        foreach (string region in Ranks.QueueRanks())
                        {
                            if (region.ToLower() ==
                                e.GetArg("rank")
                                .Substring(e.GetArg("rank").IndexOf(" ") + 1,
                                           e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1)
                                .ToLower())
                            {
                                try
                                {
                                    ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id);
                                    await e.User.RemoveRoles(e.Server.GetRole(id),
                                                             e.Server.FindRoles(region.ToLower(), false).First());
                                    returnstring = Eng_Default.RoleHasBeenRemoved(region);
                                }
                                catch
                                {
                                }
                            }
                        }
                        foreach (string region in Ranks.DivisionRanks())
                        {
                            if (region.ToLower() ==
                                e.GetArg("rank")
                                .Substring(e.GetArg("rank").IndexOf(" ") + 1,
                                           e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1)
                                .ToLower())
                            {
                                try
                                {
                                    ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id);
                                    await e.User.RemoveRoles(e.Server.GetRole(id),
                                                             e.Server.FindRoles(region.ToLower(), false).First());
                                    returnstring = Eng_Default.RoleHasBeenRemoved(region);
                                }
                                catch
                                {
                                }
                            }
                        }
                        try
                        {
                            foreach (string role in settingsRepo.GetAllOverrides(e.Server.Id))
                            {
                                var replacement = e.Server.GetRole(Convert.ToUInt64(role.Split(':').Last()));
                                if (
                                    e.GetArg("rank")
                                    .Substring(e.GetArg("rank").IndexOf(" ") + 1,
                                               e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1)
                                    .ToLower() == replacement.Name.ToLower())
                                {
                                    await e.User.RemoveRoles(replacement);
                                    returnstring = Eng_Default.RoleHasBeenRemoved(role);
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                    else if (e.GetArg("rank").ToLower() == "list")
                    {
                        if (settingsRepo.RankByAccount(e.Server.Id) == true ||
                            settingsRepo.RankByParameter(e.Server.Id) == true)
                        {
                            returnstring = "Assignable roles on this server:";
                            if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic)
                            {
                                foreach (string r in Ranks.BasicRanks())
                                {
                                    returnstring += "\n- " + r;
                                }
                            }
                            else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue)
                            {
                                foreach (string r in Ranks.QueueRanks())
                                {
                                    returnstring += "\n- " + r;
                                }
                            }
                            else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Division)
                            {
                                foreach (string r in Ranks.BasicRanks())
                                {
                                    returnstring += "\n- " + r + " V to I";
                                }
                            }
                        }
                        else
                        {
                            returnstring = Eng_Default.ServerDoesNotAllow();
                        }
                    }
                    else if (e.GetArg("rank") == "?" || e.GetArg("rank").ToLower() == "help")
                    {
                        returnstring = "Use the base command -rank to get a rank assigned as your role.";
                        if (settingsRepo.RankByAccount(e.Server.Id) == true)
                        {
                            returnstring +=
                                "\nYou can use *-Rank* to get your ranks based on bound league of legends account.";
                        }
                        if (settingsRepo.RankByParameter(e.Server.Id) == true)
                        {
                            returnstring +=
                                "\nYou can use *-Rank <League rank>* to get a role based on your input";
                            returnstring += "\nRoles you can get on this server are:";
                            if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic)
                            {
                                foreach (string r in Ranks.BasicRanks())
                                {
                                    returnstring += "\n- " + r;
                                }
                            }
                            else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue)
                            {
                                foreach (string r in Ranks.QueueRanks())
                                {
                                    returnstring += "\n- " + r;
                                }
                            }
                            else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Division)
                            {
                                foreach (string r in Ranks.BasicRanks())
                                {
                                    returnstring += "\n- " + r + " V to I";
                                }
                            }
                        }
                    }
                    else
                    {
                        if (e.GetArg("rank") == "")
                        {
                            //Checks if gettings ranks by account is disabled (Unsure why someone would disable this but hey ¯\_(ツ)_/¯ someone might want so)
                            if (settingsRepo.RankByAccount(e.Server.Id) == true)
                            {
                                Summoner summoner = null;
                                try
                                {
                                    DataLibary.Models.User user =
                                        new UserRepo(new UserContext()).GetUserByDiscord(e.User.Id);
                                    summoner =
                                        new SummonerAPI().GetSummoner(
                                            new SummonerRepo(new SummonerContext()).GetSummonerByUserId(user),
                                            ToolKit.LeagueAndDatabase.GetRegionFromDatabaseId(
                                                new RegionRepo(new RegionContext()).GetRegionId(user)
                                                ));
                                }
                                catch
                                {
                                    returnstring =
                                        Eng_Default.RegisterAccount();
                                }
                                //summoner will be null when the item does not excist within the database.
                                //This is only done so there will be a proper returnmessage send to the user.
                                if (summoner != null)
                                {
                                    if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic)
                                    {
                                        string rank = new RankAPI().GetRankingSimple(summoner,
                                                                                     Queue.RankedSolo5x5);
                                        try
                                        {
                                            await e.User.AddRoles(
                                                e.Server.GetRole(settingsRepo.GetOverride(rank.ToLower(),
                                                                                          e.Server.Id)));
                                        }
                                        catch
                                        {
                                            await e.User.AddRoles(e.Server.FindRoles(rank, false).First());
                                        }
                                        returnstring = Eng_Default.RoleHasBeenGiven(rank);
                                    }
                                    else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Division)
                                    {
                                        string rank =
                                            new RankAPI().GetRankingHarder(summoner, Queue.RankedSolo5x5)
                                            .ToLower();
                                        try
                                        {
                                            await e.User.AddRoles(
                                                e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id)));
                                        }
                                        catch
                                        {
                                            await e.User.AddRoles(e.Server.FindRoles(rank, false).First());
                                        }

                                        returnstring = Eng_Default.RoleHasBeenGiven(rank);
                                    }
                                    else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue)
                                    {
                                        //Each of these can fail when someone does not have this rank, therefore this isn't in one big Try because it could fail halfway.
                                        try
                                        {
                                            string rank = "Solo " +
                                                          new RankAPI().GetRankingSimple(summoner,
                                                                                         Queue.RankedSolo5x5);
                                            try
                                            {
                                                await e.User.AddRoles(
                                                    e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id)));
                                            }
                                            catch
                                            {
                                                await e.User.AddRoles(e.Server.FindRoles(rank, false).First());
                                            }
                                        }
                                        catch
                                        {
                                            Console.WriteLine(e.User.Name + "doesn't have a soloq rank");
                                        }
                                        try
                                        {
                                            string rank = "Flex " +
                                                          new RankAPI().GetRankingSimple(summoner,
                                                                                         Queue.RankedFlexSR);
                                            try
                                            {
                                                await e.User.AddRoles(
                                                    e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id)));
                                            }
                                            catch
                                            {
                                                await e.User.AddRoles(e.Server.FindRoles(rank, false).First());
                                            }
                                        }
                                        catch
                                        {
                                            Console.WriteLine(e.User.Name + "doesn't have a flex rank");
                                        }
                                        try
                                        {
                                            string rank = "3v3 " +
                                                          new RankAPI().GetRankingSimple(summoner,
                                                                                         Queue.RankedFlexTT);
                                            try
                                            {
                                                await e.User.AddRoles(
                                                    e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id)));
                                            }
                                            catch
                                            {
                                                await e.User.AddRoles(e.Server.FindRoles(rank, false).First());
                                            }
                                        }
                                        catch
                                        {
                                            Console.WriteLine(e.User.Name + "doesn't have a 3v3 rank");
                                        }
                                        returnstring = Eng_Default.RolesHaveBeenGiven();
                                    }
                                }
                            }
                            else
                            {
                                returnstring = Eng_Default.ServerDoesNotAllow();
                            }
                        }
                        else
                        {
                            //Check settings and give ranks according to the parameter
                            if (settingsRepo.RankByParameter(e.Server.Id) == true)
                            {
                                bool found           = false;
                                List <string> filter = new List <string>();
                                if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic)
                                {
                                    filter = Ranks.BasicRanks();
                                }

                                else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue)
                                {
                                    filter = Ranks.QueueRanks();
                                }
                                foreach (string rank in filter)
                                {
                                    if (e.GetArg("rank").ToLower() == rank.ToLower())
                                    {
                                        try
                                        {
                                            Discord.Role r =
                                                e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id));
                                            if (!settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id))
                                            {
                                                await e.User.AddRoles(r);
                                                returnstring = Eng_Default.RoleHasBeenGiven(r.Name);
                                            }
                                            else
                                            {
                                                returnstring = Eng_Default.RoleHasBeenDisabled();
                                            }
                                        }
                                        catch
                                        {
                                            Discord.Role r = e.Server.FindRoles(rank, false).First();
                                            if (!settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id))
                                            {
                                                await e.User.AddRoles(r);
                                                returnstring = Eng_Default.RoleHasBeenGiven(r.Name);
                                            }
                                            else
                                            {
                                                returnstring = Eng_Default.RoleHasBeenDisabled();
                                            }
                                        }

                                        found = true;
                                    }
                                }
                                if (found == false)
                                {
                                    returnstring = Eng_Default.RoleNotFound(e.GetArg("rank"));
                                }
                            }
                            else
                            {
                                returnstring = Eng_Default.ServerDoesNotAllow();
                            }
                        }
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }


                await e.Channel.SendMessage(returnstring);
            });
        }
Ejemplo n.º 5
0
        public void OverrideSystem()
        {
            //Temporary name Override, needs a better name like CustomRole, just programming it now for the functionallity
            commands.CreateCommand("Override")
            .Parameter("CommandType", ParameterType.Optional)
            .Parameter("Role", ParameterType.Optional)
            .Parameter("Parameter", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string returnstring = "";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
                    if (new ServerRepo(new ServerContext()).IsAdmin(e.User.Id, e.Server.Id) == true)
                    {
                        if (e.GetArg("CommandType").ToLower() == "help" || e.GetArg("CommandType") == "?")
                        {
                            //Gives all of the information about -Override and its overloads
                            returnstring += "**With this command you can add custom ranks to your server.**" +
                                            "\nUse the format: *-Override Add \"RoleName\" Parameter*" +
                                            "\nYou can find out what parameters you can use by using one of the following commands:" +
                                            "\n*-Rank List, -Region List, -Role List, -Mastery List.*" +
                                            "\n\nYou can also find out what overrides you have with -Override List." +
                                            "\nThese overrides can be removed using *-Override remove <id>*." +
                                            "\n\nYou can also disable roles, these will not be getable by parameter (-rank master)" +
                                            "\nUse *-Override add disable <Role>* to disable a role." +
                                            "\nYou can see disables in the override list using *-Override list*." +
                                            "\nYou can remove disables by using *-Override remove disable <id>*.";
                        }
                        else if (e.GetArg("CommandType").ToLower() == "remove" &&
                                 e.GetArg("Role").ToLower() != "disable")
                        {
                            try
                            {
                                settingsRepo.RemoveOverride(Convert.ToInt32(e.GetArg("Role")), e.Server.Id);
                                returnstring = Eng_Default.OverrideRemoved();
                            }
                            catch
                            {
                                returnstring = Eng_Default.OverrideFailedToRemoved(e.GetArg("Role"));
                            }
                        }
                        else if ((e.GetArg("CommandType").ToLower() == "remove" ||
                                  e.GetArg("CommandType").ToLower() == "delete") &&
                                 e.GetArg("Role").ToLower() == "disable")
                        {
                            try
                            {
                                settingsRepo.RemoveRoleDisable(Convert.ToInt32(e.GetArg("Parameter")), e.Server.Id);
                                returnstring = "Disable has been removed.";
                            }
                            catch
                            {
                                returnstring = "Failed to remove disable.";
                            }
                        }
                        else if (e.GetArg("CommandType").ToLower() == "add")
                        {
                            //Adds an override to the system
                            if (e.GetArg("Role").ToLower() == "disable")
                            {
                                try
                                {
                                    settingsRepo.AddRoleDisable(e.GetArg("Parameter"), e.Server.Id);
                                    returnstring = "Successfully added disable.";
                                }
                                catch
                                {
                                    returnstring = "Failed to add disable.";
                                }
                            }
                            else
                            {
                                try
                                {
                                    ulong id = 0;
                                    try
                                    {
                                        id = e.Server.FindRoles(e.GetArg("Role"), false).First().Id;
                                    }
                                    catch
                                    {
                                        throw new Exception("Role not found");
                                    }
                                    if (id != 0)
                                    {
                                        if (e.GetArg("Parameter").IndexOf(" ") == 0)
                                        {
                                            settingsRepo.AddOverride(
                                                e.GetArg("Parameter").ToString().ToLower().Remove(0, 1), id
                                                , e.Server.Id);
                                        }
                                        else if (e.GetArg("Parameter").IndexOf(" ") == (e.GetArg("Parameter").Length))
                                        {
                                            settingsRepo.AddOverride(
                                                e.GetArg("Parameter")
                                                .ToString()
                                                .ToLower()
                                                .Remove(e.GetArg("Parameter").Length, 1), id
                                                , e.Server.Id);
                                        }
                                        else
                                        {
                                            settingsRepo.AddOverride(
                                                e.GetArg("Parameter").ToString().ToLower(), id,
                                                e.Server.Id);
                                        }

                                        returnstring = Eng_Default.OverrideAdded();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    returnstring = ex.Message;
                                }
                                catch
                                {
                                    returnstring = Eng_Default.OverrideFailedToAdd();
                                }
                            }
                        }
                        else if (e.GetArg("CommandType").ToLower() == "list")
                        {
                            int entries  = 0;
                            returnstring = "```\nOverrides:";
                            //Gives a list of all the overrides made by this server.
                            foreach (string line in settingsRepo.GetAllOverridesInformation(e.Server.Id))
                            {
                                //await e.Channel.SendMessage(line.Substring(line.IndexOf("role:") + 5, line.Length - line.IndexOf("role:") - 6));
                                ulong id =
                                    Convert.ToUInt64(line.Substring(line.IndexOf("role:") + 5,
                                                                    line.Length - line.IndexOf("role:") - 5));
                                var role = e.Server.GetRole(id);
                                try
                                {
                                    returnstring += "\n" + line.Substring(0, line.IndexOf("role:") + 5) + " " +
                                                    role.Name;
                                }
                                catch
                                {
                                    new SettingsRepo(new SettingsContext()).RemoveOverride(
                                        Convert.ToInt32(line.Split(' ')[1]), e.Server.Id);
                                }
                                entries++;
                            }
                            returnstring += "\nDisables:";
                            foreach (string line in settingsRepo.GetDisabledRoles(e.Server.Id))
                            {
                                returnstring += "\n" + line;
                                entries++;
                            }
                            returnstring += "\n```";
                            if (entries == 0)
                            {
                                returnstring = Eng_Default.NoOverrides();
                            }
                        }
                    }
                    else
                    {
                        returnstring = Eng_Default.NotAllowed();
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }

                await e.Channel.SendMessage(returnstring);
            });
        }
Ejemplo n.º 6
0
        public void ChangeCommandAllowed()
        {
            commands.CreateCommand("Command")
            .Parameter("Command", ParameterType.Required)
            .Parameter("Value", ParameterType.Optional)
            .Do(async(e) =>
            {
                string returnstring = "error";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    if (e.GetArg("Command").ToLower() == "help" || e.GetArg("Command").ToLower() == "?")
                    {
                        returnstring =
                            "Use this command to change the behavior of your server. You can allow and deny the following features:" +
                            "\n- Regionaccount: Allows the user to type -region to get a region role assigned." +
                            "\n- Regionparameter: Allow the user to type -region <region> to get a region role assinged." +
                            "\n- Rankaccount: Allow the user to type -rank to get a rank role assinged." +
                            "\n- Rankparameter: Allow the user to type -rank <rank> to get a rank role assinged." +
                            "\n- Roleaccount: Allow the user to type -role and get a role assigned that fits their main role in League of Legends." +
                            "\n- Roleparameter: Allow the user to type -role <role> to get that role assigned." +
                            "\n- MasteryAccount: Allow the user to type -mastery and get their amount of points assigned." +
                            "\n\nPlease use the format -Command <Command> <Value>, example: *-Command rankaccount true*.";
                    }
                    else
                    {
                        bool value = false;
                        if (bool.TryParse(e.GetArg("Value"), out value))
                        {
                            if (new ServerRepo(new ServerContext()).IsAdmin(e.User.Id, e.Server.Id))
                            {
                                if (e.GetArg("Command").ToLower() == "rankaccount")
                                {
                                    new SettingsRepo(new SettingsContext()).ToggleAccountRank(value, e.Server.Id);
                                    returnstring = Eng_Default.CommandPermsChanged("Rank by account",
                                                                                   value.ToString());
                                }
                                else if (e.GetArg("Command").ToLower() == "rankparameter")
                                {
                                    new SettingsRepo(new SettingsContext()).ToggleRankParameter(value, e.Server.Id);
                                    returnstring = Eng_Default.CommandPermsChanged("Rank by parameter",
                                                                                   value.ToString());
                                }
                                else if (e.GetArg("Command").ToLower() == "regionaccount")
                                {
                                    new SettingsRepo(new SettingsContext()).ToggleRegionAccount(value, e.Server.Id);
                                    returnstring = Eng_Default.CommandPermsChanged("Region by account",
                                                                                   value.ToString());
                                }
                                else if (e.GetArg("Command").ToLower() == "regionparameter")
                                {
                                    new SettingsRepo(new SettingsContext()).ToggleRegionParameter(value, e.Server.Id);
                                    returnstring = Eng_Default.CommandPermsChanged("Region by parameter",
                                                                                   value.ToString());
                                }
                                else if (e.GetArg("Command").ToLower() == "roleaccount")
                                {
                                    new SettingsRepo(new SettingsContext()).ChangeRoleAccount(value, e.Server.Id);
                                    returnstring = Eng_Default.CommandPermsChanged("Role by account",
                                                                                   value.ToString());
                                }
                                else if (e.GetArg("Command").ToLower() == "roleparameter")
                                {
                                    new SettingsRepo(new SettingsContext()).ChangeRoleParameter(value, e.Server.Id);
                                    returnstring = Eng_Default.CommandPermsChanged("Role by parameter",
                                                                                   value.ToString());
                                }
                                else if (e.GetArg("Command").ToLower() == "masteryaccount")
                                {
                                    new SettingsRepo(new SettingsContext()).ChangeMasteryAccount(value, e.Server.Id);
                                    returnstring =
                                        Eng_Default.CommandPermsChanged("Mastery by account", value.ToString()) +
                                        "\nDon't forget to configure this by using -ConfigMastery!";
                                }
                                else
                                {
                                    returnstring = Eng_Default.PermsCommandNotFound();
                                }
                            }
                            else
                            {
                                returnstring = Eng_Default.NotAllowed();
                            }
                        }
                        else
                        {
                            returnstring = Eng_Default.InvalidBoolValue();
                        }
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }

                await e.Channel.SendMessage(returnstring);
            });
        }
        public void ClaimAccount()
        {
            commands.CreateCommand("ClaimAccount")
            .Parameter("Region", ParameterType.Required)
            .Parameter("Summoner", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string returnmessage = "An error happened.";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    RiotSharp.Region region = LeagueAndDatabase.GetRegionFromString(e.GetArg("Region"));
                    string summonername     = e.GetArg("Summoner");
                    SummonerRepo sumRepo    = new SummonerRepo(new SummonerContext());
                    UserRepo userRepo       = new UserRepo(new UserContext());
                    long riotid             = Convert.ToInt32(new SummonerAPI().GetSummonerId(summonername, region));
                    string token            = new StringBuilder().CreateToken();
                    if (
                        sumRepo.IsSummonerInSystem(riotid
                                                   ) == false
                        )
                    {
                        try
                        {
                            userRepo.GetUserIdByDiscord((e.User.Id));
                        }
                        catch
                        {
                            userRepo.AddUser(Convert.ToInt64(e.User.Id));
                        }
                        sumRepo.AddSummoner(userRepo.GetUserIdByDiscord((e.User.Id)), riotid,
                                            new RegionContext().GetRegionId(region), token);
                        returnmessage =
                            Eng_Default.RenameMasteryPage(
                                sumRepo.GetToken(userRepo.GetUserByDiscord((e.User.Id)), riotid).ToString());
                    }
                    else
                    {
                        returnmessage =
                            Eng_Default.RenameMasteryPageLong(
                                sumRepo.GetToken(userRepo.GetUserByDiscord((e.User.Id)), riotid));
                        string token2 = sumRepo.GetToken(userRepo.GetUserByDiscord((e.User.Id)), riotid);
                        foreach (var page in new SummonerAPI().GetSummonerMasteryPages(summonername, region))
                        {
                            if (page.Name.ToLower() == token2.ToLower())
                            {
                                sumRepo.VerifySummoner(userRepo.GetUserByDiscord((e.User.Id)), riotid);
                                returnmessage = Eng_Default.AccountVerified();
                                new RoleManagementCommands(BotUser, commands).GetRoles(e.Server, e.User);
                                new FlairTrigger(BotUser, commands).CreateFlair(new SummonerAPI().GetSummoner(riotid, region));
                            }
                        }
                        foreach (var page in new SummonerAPI().GetRunePages(summonername, region))
                        {
                            if (page.Name.ToLower() == token2.ToLower())
                            {
                                sumRepo.VerifySummoner(userRepo.GetUserByDiscord((e.User.Id)), riotid);
                                returnmessage = Eng_Default.AccountVerified();
                                new RoleManagementCommands(BotUser, commands).GetRoles(e.Server, e.User);
                                new FlairTrigger(BotUser, commands).CreateFlair(new SummonerAPI().GetSummoner(riotid, region));
                            }
                        }
                    }
                }
                else
                {
                    returnmessage = Eng_Default.ServerIsNotVerified();
                }

                await e.Channel.SendMessage(returnmessage);
            });
        }
Ejemplo n.º 8
0
        public void GetRole()
        {
            commands.CreateCommand("Role")
            .Do(async(e) =>
            {
                string returnstring       = "";
                SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    if (settingsRepo.RoleByAccount(e.Server.Id))
                    {
                        List <string> filter = new List <string>();
                        if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Basic)
                        {
                            filter = DataLibary.Models.Roles.NormalRoles();
                        }
                        else if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Main)
                        {
                            filter = DataLibary.Models.Roles.MainRoles();
                        }
                        else if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Mains)
                        {
                            filter = DataLibary.Models.Roles.MainsRoles();
                        }

                        Summoner summoner = null;
                        try
                        {
                            DataLibary.Models.User user =
                                new UserRepo(new UserContext()).GetUserByDiscord(e.User.Id);
                            summoner =
                                new SummonerAPI().GetSummoner(
                                    new SummonerRepo(new SummonerContext()).GetSummonerByUserId(user),
                                    ToolKit.LeagueAndDatabase.GetRegionFromDatabaseId(
                                        new RegionRepo(new RegionContext()).GetRegionId(user)
                                        ));
                        }
                        catch
                        {
                            returnstring = Eng_Default.RegisterAccount();
                        }
                        //summoner will be null when the item does not excist within the database.
                        //This is only done so there will be a proper returnmessage send to the user.
                        if (summoner != null)
                        {
                            string mainrole = new RoleAPI().GetRole(summoner);
                            foreach (string role in filter)
                            {
                                if (role.Contains(mainrole))
                                {
                                    try
                                    {
                                        ulong id = settingsRepo.GetOverride(role.ToLower(), e.Server.Id);
                                        await e.User.AddRoles(e.Server.GetRole(id));
                                        returnstring = Eng_Default.RoleHasBeenGiven(role);
                                    }
                                    catch
                                    {
                                        await e.User.AddRoles(e.Server.FindRoles(role, false).First());
                                        returnstring = Eng_Default.RoleHasBeenGiven(role);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }
                await e.Channel.SendMessage(returnstring);
            });
        }
Ejemplo n.º 9
0
        public void GetRoleParameter()
        {
            commands.CreateCommand("Role")
            .Parameter("Role", ParameterType.Required)
            .Parameter("Optional", ParameterType.Optional)
            .Do(async(e) =>
            {
                string returnstring = "";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
                    List <string> filter      = new List <string>();
                    if (e.GetArg("Role").ToLower() == "?" || e.GetArg("Role").ToLower() == "help")
                    {
                        if (settingsRepo.RoleByParameter(e.Server.Id) || settingsRepo.RoleByAccount(e.Server.Id))
                        {
                            returnstring = "You can use -Role to assign a role based on a League of Legends role.";
                            if (settingsRepo.RoleByAccount(e.Server.Id))
                            {
                                returnstring +=
                                    "\nYou can use *-Role* to get your role automatically assigned based on your linked League of Legends account.";
                            }
                            if (settingsRepo.RoleByParameter(e.Server.Id))
                            {
                                returnstring += "\nYou can use *-Role <Role>* to assgined yourself a role." +
                                                "\nFor all assignable roles use -Role list.";
                            }
                        }
                    }

                    if (settingsRepo.RoleByParameter(e.Server.Id))
                    {
                        if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Basic)
                        {
                            filter = DataLibary.Models.Roles.NormalRoles();
                        }
                        else if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Main)
                        {
                            filter = DataLibary.Models.Roles.MainRoles();
                        }
                        else if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Mains)
                        {
                            filter = DataLibary.Models.Roles.MainsRoles();
                        }


                        if (e.GetArg("Role").ToLower() == "list")
                        {
                            returnstring = "These roles are getable on the server:```";
                            foreach (string role in filter)
                            {
                                returnstring += "\n- " + role;
                            }
                            returnstring += "```";
                        }
                        else if (e.GetArg("Role").ToLower() == "remove")
                        {
                            foreach (string role in filter)
                            {
                                if (role.ToLower().Contains(e.GetArg("Optional").ToLower()))
                                {
                                    try
                                    {
                                        await e.User.RemoveRoles(
                                            e.Server.GetRole(settingsRepo.GetOverride(role.ToLower(),
                                                                                      e.Server.Id)));
                                        await e.User.RemoveRoles(e.Server.FindRoles(role, false).First());
                                        returnstring = Eng_Default.RoleHasBeenRemoved(role);
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (string role in filter)
                            {
                                if (role.ToLower().Contains(e.GetArg("Role").ToLower()))
                                {
                                    try
                                    {
                                        ulong id = settingsRepo.GetOverride(role.ToLower(), e.Server.Id);
                                        await e.User.AddRoles(e.Server.GetRole(id));
                                        returnstring = Eng_Default.RoleHasBeenGiven(role);
                                    }
                                    catch
                                    {
                                        await e.User.AddRoles(e.Server.FindRoles(role, false).First());
                                        returnstring = Eng_Default.RoleHasBeenGiven(role);
                                    }
                                }
                            }
                        }
                    }
                    else if (e.GetArg("Role").ToLower() != "?" && e.GetArg("Role").ToLower() != "help")
                    {
                        returnstring = Eng_Default.ServerDoesNotAllow();
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }

                await e.Channel.SendMessage(returnstring);
            });
        }
Ejemplo n.º 10
0
        public void GetRegion()
        {
            commands.CreateCommand("region")
            .Parameter("region", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                try { new RoleManagementTrigger(BotUser, commands).OverrideDeletion(e.Server); } catch { }
                string returnstring = "error";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    string command = "";
                    try
                    {
                        command = e.GetArg("region").Substring(0, e.GetArg("region").IndexOf(" ")).ToLower();
                    }
                    catch { }

                    SettingsRepo settingsRepo = (new SettingsRepo(new SettingsContext()));
                    if (e.GetArg("region").ToLower() == "help" || e.GetArg("region") == "?")
                    {
                        if (settingsRepo.RegionByAccount(e.Server.Id) == true ||
                            settingsRepo.RegionByParameter(e.Server.Id) == true)
                        {
                            returnstring = "You can use the -Region command to assign a region role to yourself.";
                            if (settingsRepo.RegionByAccount(e.Server.Id) == true)
                            {
                                returnstring +=
                                    "\nYou can use *-Region* to get your region based on your bound League of Legends account.";
                            }
                            if (settingsRepo.RegionByParameter(e.Server.Id) == true)
                            {
                                returnstring +=
                                    "\nYou can use *-Region <League Region>* to assign a region to yourself.\nUse *-Region list* to see all the regions on this server.";
                            }
                        }

                        else
                        {
                            returnstring = Eng_Default.ServerDoesNotAllow();
                        }
                    }
                    else if (command == "remove" || command == "delete")
                    {
                        foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions())
                        {
                            if (region.ToLower() == e.GetArg("region").Split(' ').Last().ToLower())
                            {
                                try
                                {
                                    ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id);
                                    await e.User.RemoveRoles(e.Server.GetRole(id));
                                    returnstring = Eng_Default.RoleHasBeenRemoved(region);
                                    await e.User.RemoveRoles(e.Server.FindRoles(region.ToLower(), false).First());
                                    returnstring = Eng_Default.RoleHasBeenRemoved(region);
                                }
                                catch
                                {
                                }
                            }
                        }
                        try
                        {
                            foreach (string role in settingsRepo.GetAllOverrides(e.Server.Id))
                            {
                                var replacement = e.Server.GetRole(Convert.ToUInt64(role.Split(':').Last()));
                                if (e.GetArg("region").Substring(e.GetArg("region").IndexOf(" ") + 1, e.GetArg("region").Length - e.GetArg("region").IndexOf(" ") - 1).ToLower() == replacement.Name.ToLower())
                                {
                                    await e.User.RemoveRoles(replacement);
                                    returnstring = Eng_Default.RoleHasBeenRemoved(role);
                                }
                            }
                        }
                        catch { }
                    }
                    else if (e.GetArg("region").ToLower() == "list")
                    {
                        if (settingsRepo.RegionByParameter(e.Server.Id) == true ||
                            settingsRepo.RegionByAccount(e.Server.Id) == true)
                        {
                            returnstring            = "Assignable regions on this server:\n```";
                            List <string> overrides = new List <string>();
                            try
                            {
                                overrides = settingsRepo.GetAllOverrides(e.Server.Id);
                            }
                            catch { }
                            foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions())
                            {
                                bool found = false;
                                if (overrides != null)
                                {
                                    foreach (string over in overrides)
                                    {
                                        if (region.ToLower() == over.Substring(0, over.IndexOf(":")).ToLower())
                                        {
                                            returnstring += "\n- " + e.Server.GetRole(Convert.ToUInt64(over.Substring(over.IndexOf(":") + 1, over.Length - over.IndexOf(":") - 1))).Name;
                                            found         = true;
                                        }
                                    }
                                }
                                if (found == false)
                                {
                                    returnstring += "\n- " + region;
                                }
                            }
                            returnstring += "```";
                        }
                        else
                        {
                            returnstring = Eng_Default.ServerDoesNotAllow();
                        }
                    }
                    else
                    {
                        if (settingsRepo.RegionByAccount(e.Server.Id) == true && e.GetArg("region") == "")
                        {
                            Summoner summoner = null;
                            try
                            {
                                DataLibary.Models.User user =
                                    new UserRepo(new UserContext()).GetUserByDiscord(e.User.Id);
                                summoner =
                                    new SummonerAPI().GetSummoner(
                                        new SummonerRepo(new SummonerContext()).GetSummonerByUserId(user),
                                        ToolKit.LeagueAndDatabase.GetRegionFromDatabaseId(
                                            new RegionRepo(new RegionContext()).GetRegionId(user)
                                            ));
                            }
                            catch
                            {
                                returnstring = Eng_Default.RegisterAccount();
                            }
                            //summoner will be null when the item does not excist within the database.
                            //This is only done so there will be a proper returnmessage send to the user.
                            if (summoner != null)
                            {
                                foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions())
                                {
                                    if (region.ToLower() == summoner.Region.ToString().ToLower())
                                    {
                                        try
                                        {
                                            await e.User.AddRoles(
                                                e.Server.GetRole(settingsRepo.GetOverride(region.ToLower(), e.Server.Id)));
                                            returnstring = Eng_Default.RoleHasBeenGiven(region);
                                        }
                                        catch
                                        {
                                            await e.User.AddRoles(e.Server.FindRoles(region, false).First());
                                            returnstring = Eng_Default.RoleHasBeenGiven(region);
                                        }
                                    }
                                }
                            }
                        }
                        else if (e.GetArg("region") == "" && settingsRepo.RegionByAccount(e.Server.Id) == false)
                        {
                            returnstring = Eng_Default.ServerDoesNotAllow();
                        }
                        else if (settingsRepo.RegionByParameter(e.Server.Id) == true)
                        {
                            bool found = false;
                            foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions())
                            {
                                if (e.GetArg("region").ToLower() == region.ToLower())
                                {
                                    try
                                    {
                                        Discord.Role r =
                                            e.Server.GetRole(settingsRepo.GetOverride(region.ToLower(), e.Server.Id));
                                        if (settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id))
                                        {
                                            returnstring = Eng_Default.RoleHasBeenDisabled();
                                        }
                                        else
                                        {
                                            await e.User.AddRoles(r);
                                            returnstring = Eng_Default.RoleHasBeenGiven(r.Name);
                                        }

                                        found = true;
                                    }
                                    catch
                                    {
                                        Discord.Role r = e.Server.FindRoles(region, false).First();
                                        if (settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id))
                                        {
                                            returnstring = Eng_Default.RoleHasBeenDisabled();
                                        }
                                        else
                                        {
                                            await e.User.AddRoles(r);
                                            returnstring = Eng_Default.RoleHasBeenGiven(r.Name);
                                        }
                                        found = true;
                                    }
                                }
                            }
                            foreach (string role in settingsRepo.GetAllOverrides(e.Server.Id))
                            {
                                var replacement = e.Server.GetRole(Convert.ToUInt64(role.Substring(role.IndexOf(":") + 1, role.Length - role.IndexOf(":") - 1)));
                                if (e.GetArg("region").ToLower() == replacement.Name.ToLower())
                                {
                                    await e.User.AddRoles(replacement);
                                    returnstring = Eng_Default.RoleHasBeenGiven(role);
                                    found        = true;
                                }
                            }
                            if (found == false)
                            {
                                returnstring = Eng_Default.RoleNotFound(e.GetArg("region"));
                            }
                        }
                        else
                        {
                            returnstring = Eng_Default.ServerDoesNotAllow();
                        }
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }

                await e.Channel.SendMessage(returnstring);
            });
        }