Beispiel #1
0
        private void Request(SocketCommandContext Context, dynamic target, string name)
        {
            //Check if the user has a town or nation.
            NationAccount nationAccount = new NationAccount("", Context.Message.Author.Id);

            if (DatabaseService.CheckExistance(nationAccount) == DatabaseService.NationExistance.LeaderAlreadyHasNation)
            {
                Request2(Context, nationAccount, target, name);
            }
            else
            {
                //Check if they're a town.
                TownAccount townAccount = new TownAccount("", Context.Message.Author.Id);
                if (DatabaseService.CheckExistance(townAccount) == DatabaseService.TownExistance.LeaderAlreadyHasTown)
                {
                    Request2(Context, townAccount, target, name);
                }
                else
                {
                    Context.Message.AddReactionAsync(new Emoji("❎"));
                    ReplyAsync("You do not have a town or nation. Create a town by doing `-town register`.");
                    return;
                }
            }
        }
Beispiel #2
0
        public Task RemoveAlly(string name = null)
        {
            if (name == null)
            {
                return(ReplyAsync("Please also enter a name."));
            }

            //Check if they're a nation.
            NationAccount nationAccount = new NationAccount(name, 0);

            if (DatabaseService.CheckExistance(nationAccount) == DatabaseService.NationExistance.NameInUse)
            {
                Remove(Context, nationAccount, name);
            }
            else
            {
                //Check if they're a town.
                TownAccount townAccount = new TownAccount(name, 0);
                if (DatabaseService.CheckExistance(townAccount) == DatabaseService.TownExistance.NameInUse)
                {
                    Remove(Context, townAccount, name);
                }
                else
                {
                    Context.Message.AddReactionAsync(new Emoji("❎"));
                    return(ReplyAsync("That nation or town couldn't be found."));
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #3
0
        public TownExistance CheckExistance(TownAccount account)
        {
            ValueRange values = GetValues("towns");

            foreach (IList <object> row in values.Values.Skip(1))
            {
                if (row[2].ToString() == account.LeaderID)
                {
                    return(TownExistance.LeaderAlreadyHasTown);
                }
                if (row[1].ToString() == account.Name)
                {
                    return(TownExistance.NameInUse);
                }
            }

            return(TownExistance.DoesntExist);
        }
Beispiel #4
0
        public Task RegisterNation(string name = null)
        {
            if (name == null)
            {
                return(ReplyAsync("Please also specify a nation name."));
            }

            UserAccount userAccount = new UserAccount(Context.Message.Author.Id, Context.Message.Author.ToString());

            if (DatabaseService.CheckExistance(userAccount) == DatabaseService.UserExistance.DoesntExist)
            {
                Context.Message.AddReactionAsync(new Emoji("❎"));
                return(ReplyAsync("Please create an account first by using `-register`."));
            }

            NationAccount account = new NationAccount(name, Context.Message.Author.Id);

            TownAccount town = DatabaseService.GetTownByLeaderID(Context.Message.Author.Id.ToString());

            town.NationID = account.ID;
            DatabaseService.UpdateEntry(town);

            var response = DatabaseService.CheckExistance(account);

            if (response == DatabaseService.NationExistance.DoesntExist)
            {
                DatabaseService.AddEntry(account);
                Context.Message.AddReactionAsync(new Emoji("✅"));
                return(ReplyAsync("Your nation has been registered. Use `-nation` to access your nation."));
            }
            else if (response == DatabaseService.NationExistance.LeaderAlreadyHasNation)
            {
                Context.Message.AddReactionAsync(new Emoji("❎"));
                return(ReplyAsync("You already have a nation registered. Use `-nation` to access your nation."));
            }
            else if (response == DatabaseService.NationExistance.NameInUse)
            {
                Context.Message.AddReactionAsync(new Emoji("❎"));
                return(ReplyAsync("That name is already in use, try a different name."));
            }

            return(Task.CompletedTask);
        }
Beispiel #5
0
 public void UpdateEntry(TownAccount account)
 {
     UpdateEntry("towns", account.List);
 }
Beispiel #6
0
 public void AddEntry(TownAccount account)
 {
     AddEntry("towns", account.List);
 }
Beispiel #7
0
        private void Request2(SocketCommandContext Context, dynamic user, dynamic target, string name)
        {
            string aID = "";
            string bID = "";

            string aDiscordID = "";
            string bDiscordID = "";

            string nameA = "";
            string nameB = "";

            if (user.GetType() == typeof(TownAccount))
            {
                TownAccount town = DatabaseService.GetTownByLeaderID(Context.Message.Author.Id.ToString());
                aID        = town.ID;
                nameA      = $"the city of {town.Name}";
                aDiscordID = town.LeaderID;
            }
            else
            {
                var nation = DatabaseService.GetNationByLeaderID(Context.Message.Author.Id.ToString());
                aID        = nation.ID;
                nameA      = $"the nation of {nation.Name}";
                aDiscordID = nation.LeaderID;
            }

            if (target.GetType() == typeof(TownAccount))
            {
                TownAccount town = DatabaseService.GetTownByName(name);
                bID        = town.ID;
                nameB      = $"the city of {town.Name}";
                bDiscordID = town.LeaderID;
            }
            else
            {
                NationAccount nation = DatabaseService.GetNationByName(name);
                bID        = nation.ID;
                nameB      = $"the nation of {nation.Name}";
                bDiscordID = nation.LeaderID;
            }

            AllyEntry ally = new AllyEntry(aID, bID, aDiscordID, bDiscordID, nameA, nameB);

            //Check if the alliance is already pending.
            if (DatabaseService.CheckExistancePending(ally))
            {
                Context.Message.AddReactionAsync(new Emoji("❎"));
                ReplyAsync($"You already have a pending alliance request with *`{name}`*.");
                return;
            }

            //Check if the alliance already exists.
            if (DatabaseService.CheckExistance(ally))
            {
                Context.Message.AddReactionAsync(new Emoji("❎"));
                ReplyAsync($"You already have an alliance with *`{name}`*.");
                return;
            }

            if (aID == bID)
            {
                Context.Message.AddReactionAsync(new Emoji("❎"));
                ReplyAsync($"You're already allied with yourself.");
                return;
            }

            Context.Client.GetUser(ulong.Parse(bDiscordID)).GetOrCreateDMChannelAsync().Result.SendMessageAsync($@"***New alliance request***

*Greetings,*

*`{FirstLetterToUpper(nameA)}`* has requested an alliance with *`{nameB}`*.
Please reply with `-accept {ally.ID}` or `-deny {ally.ID}`.");

            DatabaseService.AddEntryPending(ally);

            Context.Message.AddReactionAsync(new Emoji("✅"));
            ReplyAsync($"The alliance request has been sent to *`{name}`*. I will get back to you with their reaction.");
        }
Beispiel #8
0
        private void Remove2(SocketCommandContext Context, dynamic user, dynamic target, string name)
        {
            string aID = "";
            string bID = "";

            string aDiscordID = "";
            string bDiscordID = "";

            string nameA = "";
            string nameB = "";

            if (user.GetType() == typeof(TownAccount))
            {
                TownAccount town = DatabaseService.GetTownByLeaderID(Context.Message.Author.Id.ToString());
                aID        = town.ID;
                nameA      = $"the city of {town.Name}";
                aDiscordID = town.LeaderID;
            }
            else
            {
                var nation = DatabaseService.GetNationByLeaderID(Context.Message.Author.Id.ToString());
                aID        = nation.ID;
                nameA      = $"the nation of {nation.Name}";
                aDiscordID = nation.LeaderID;
            }

            if (target.GetType() == typeof(TownAccount))
            {
                TownAccount town = DatabaseService.GetTownByName(name);
                bID        = town.ID;
                nameB      = $"the city of {town.Name}";
                bDiscordID = town.LeaderID;
            }
            else
            {
                NationAccount nation = DatabaseService.GetNationByName(name);
                bID        = nation.ID;
                nameB      = $"the nation of {nation.Name}";
                bDiscordID = nation.LeaderID;
            }

            AllyEntry entry = new AllyEntry(aID, bID, aDiscordID, bDiscordID, nameA, nameB);

            //Check if the alliance exists.
            if (!DatabaseService.CheckExistance(entry))
            {
                Context.Message.AddReactionAsync(new Emoji("❎"));
                ReplyAsync($"You do not have an alliance with *`{name}`*.");
                return;
            }

            entry = DatabaseService.GetAlliance(aID, bID);

            if (aID == bID)
            {
                Context.Message.AddReactionAsync(new Emoji("❎"));
                ReplyAsync($"You can't betray yourself.");
                return;
            }

            Context.Client.GetUser(ulong.Parse(bDiscordID)).GetOrCreateDMChannelAsync().Result.SendMessageAsync($@"***Alliance terminated***

*Greetings,*

*`{FirstLetterToUpper(nameA)}`* has hereby terminated the alliance with *`{nameB}`*.
Please accept our condolences.
");

            DatabaseService.AddEntry(entry);
            DatabaseService.AddEntry(new AllyEntry(entry.BPartyID, entry.APartyID, entry.BPartyDiscordID, entry.APartyDiscordID, entry.BPartyName, entry.APartyName));

            Context.Message.AddReactionAsync(new Emoji("✅"));
            ReplyAsync($"The alliance with *`{name}`* has been terminated. I have informed them as well.");
        }