예제 #1
0
        public async Task AnnounceUserJoined(SocketGuildUser user)
        {
            BotConfig config = new BotConfig();

            config         = Update.UpdateConfig(config);
            config.Members = BotConfig.Load().Members + 1;
            config.Save();

            var ranks = new RankSaves();

            ranks.newMembersCount  = RankSaves.Load().newMembersCount + 1;
            ranks.userCount        = RankSaves.Load().userCount;
            ranks.musicCount       = RankSaves.Load().musicCount;
            ranks.programmingCount = RankSaves.Load().programmingCount;
            ranks.graphicsCount    = RankSaves.Load().graphicsCount;
            ranks.Save();

            var newMemberRank = BotConfig.Load().NewMemberRank;
            var role          = user.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == newMemberRank);

            await(user as IGuildUser).AddRoleAsync(role);

            var welcomeChannel = Context.Guild.GetChannelAsync(BotConfig.Load().welcomeChannelId);

            if (welcomeChannel != null)
            {
                var message = await Context.Channel.SendMessageAsync("Hey " + Context.User.Mention + ", read the above post, read the rules and then head into #bot-commands and get your roles to enter the full discord!");

                await Delete.DelayDeleteMessage(message, 60);
            }
            else
            {
                await errors.sendErrorTemp(Context.Channel, "Welcome channel not found, make sure the config.json is set up correctly!", Colours.errorCol);
            }
        }
예제 #2
0
        public async Task ranks()
        {
            await Context.Message.DeleteAsync();

            var members     = BotConfig.Load().Members;
            var users       = RankSaves.Load().userCount;
            var music       = RankSaves.Load().musicCount;
            var programming = RankSaves.Load().programmingCount;
            var graphics    = RankSaves.Load().graphicsCount;
            var newbs       = RankSaves.Load().newMembersCount;

            var embed = new EmbedBuilder()
            {
                Color = Colours.generalCol
            };
            var usersField = new EmbedFieldBuilder()
            {
                Name = BotConfig.Load().UserRank.ToString() + ":", Value = users
            };
            var musicField = new EmbedFieldBuilder()
            {
                Name = BotConfig.Load().MusicRank.ToString() + ":", Value = music
            };
            var programmingField = new EmbedFieldBuilder()
            {
                Name = BotConfig.Load().ProgrammingRank.ToString() + ":", Value = programming
            };
            var graphicsField = new EmbedFieldBuilder()
            {
                Name = BotConfig.Load().GraphicsRank.ToString() + ":", Value = graphics
            };
            var newbsField = new EmbedFieldBuilder()
            {
                Name = "New", Value = "That leaves " + newbs.ToString() + " not in any rank yet!"
            };

            var footer = new EmbedFooterBuilder()
            {
                Text = "Requested by " + Context.User.Username
            };

            embed.Title       = ("Members Count");
            embed.Description = ("There are a total of " + members + " members in the discord, how many in each rank?");
            embed.AddField(usersField);
            embed.AddField(musicField);
            embed.AddField(programmingField);
            embed.AddField(graphicsField);
            embed.AddField(newbsField);
            embed.WithFooter(footer);
            embed.WithCurrentTimestamp();

            var message = await Context.Channel.SendMessageAsync("", false, embed);

            await Delete.DelayDeleteEmbed(message, 30);
        }
예제 #3
0
        public async Task AnnounceLeftUser(SocketGuildUser user)
        {
            BotConfig config = new BotConfig();

            config         = Update.UpdateConfig(config);
            config.Members = BotConfig.Load().Members - 1;
            config.Save();

            var ranks = new RankSaves();

            config = Update.UpdateConfig(config);
            ranks.newMembersCount = RankSaves.Load().newMembersCount - 1;
            ranks.Save();
        }
예제 #4
0
        public async Task Rank(string rank)
        {
            var chan          = Context.Channel;
            var userName      = Context.User as SocketGuildUser;
            var newMemberRole = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().NewMemberRank);
            await Context.Message.DeleteAsync();

            if (rank.ToLower().Equals("user"))
            {
                var user = Context.User;

                var config = new BotConfig();
                var role   = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().UserRank);
                await(user as IGuildUser).AddRoleAsync(role);

                var ranks = new RankSaves();

                ranks.userCount        = RankSaves.Load().userCount + 1;
                ranks.musicCount       = RankSaves.Load().musicCount;
                ranks.programmingCount = RankSaves.Load().programmingCount;
                ranks.graphicsCount    = RankSaves.Load().graphicsCount;

                if (userName.Roles.Contains(newMemberRole))
                {
                    var remrole = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().NewMemberRank);
                    await(user as IGuildUser).RemoveRoleAsync(remrole);
                    ranks.newMembersCount = RankSaves.Load().newMembersCount - 1;
                }
                else
                {
                    ranks.newMembersCount = RankSaves.Load().newMembersCount;
                }

                ranks.Save();

                await success.sendSuccessTemp(Context.Channel, "Add Rank", "@" + Context.User.Id + " you was added to the '" + rank.ToLower() + "' sub rank successfully!", Colours.generalCol);
            }
            else if (rank.ToLower().Equals("music"))
            {
                var user   = Context.User;
                var config = new BotConfig();
                var role   = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().MusicRank);
                await(user as IGuildUser).AddRoleAsync(role);

                var ranks = new RankSaves();
                ranks.userCount        = RankSaves.Load().userCount;
                ranks.musicCount       = RankSaves.Load().musicCount + 1;
                ranks.programmingCount = RankSaves.Load().programmingCount;
                ranks.graphicsCount    = RankSaves.Load().graphicsCount;

                if (userName.Roles.Contains(newMemberRole))
                {
                    var remrole = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().NewMemberRank);
                    await(user as IGuildUser).RemoveRoleAsync(remrole);
                    ranks.newMembersCount = RankSaves.Load().newMembersCount - 1;
                }
                else
                {
                    ranks.newMembersCount = RankSaves.Load().newMembersCount;
                }

                ranks.Save();

                await success.sendSuccessTemp(Context.Channel, "Add Rank", "@" + Context.User.Id + " you was added to the '" + rank.ToLower() + "' sub rank successfully!", Colours.generalCol);
            }
            else if (rank.ToLower().Equals("programming"))
            {
                var user = Context.User;

                var config = new BotConfig();
                var role   = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().ProgrammingRank);
                await(user as IGuildUser).AddRoleAsync(role);

                var ranks = new RankSaves();
                ranks.userCount        = RankSaves.Load().userCount;
                ranks.musicCount       = RankSaves.Load().musicCount;
                ranks.programmingCount = RankSaves.Load().programmingCount + 1;
                ranks.graphicsCount    = RankSaves.Load().graphicsCount;

                if (userName.Roles.Contains(newMemberRole))
                {
                    var remrole = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().NewMemberRank);
                    await(user as IGuildUser).RemoveRoleAsync(remrole);
                    ranks.newMembersCount = RankSaves.Load().newMembersCount - 1;
                }
                else
                {
                    ranks.newMembersCount = RankSaves.Load().newMembersCount;
                }

                ranks.Save();

                await success.sendSuccessTemp(Context.Channel, "Add Rank", "@" + Context.User.Id + " you was added to the '" + rank.ToLower() + "' sub rank successfully!", Colours.generalCol);
            }
            else if (rank.ToLower().Equals("graphics"))
            {
                var user = Context.User;

                var config = new BotConfig();
                var role   = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().GraphicsRank);
                await(user as IGuildUser).AddRoleAsync(role);

                var ranks = new RankSaves();
                ranks.userCount        = RankSaves.Load().userCount;
                ranks.musicCount       = RankSaves.Load().musicCount;
                ranks.programmingCount = RankSaves.Load().programmingCount;
                ranks.graphicsCount    = RankSaves.Load().graphicsCount + 1;

                if (userName.Roles.Contains(newMemberRole))
                {
                    var remrole = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().NewMemberRank);
                    await(user as IGuildUser).RemoveRoleAsync(remrole);
                    ranks.newMembersCount = RankSaves.Load().newMembersCount - 1;
                }
                else
                {
                    ranks.newMembersCount = RankSaves.Load().newMembersCount;
                }

                ranks.Save();

                await success.sendSuccessTemp(Context.Channel, "Add Rank", "@" + Context.User.Id + " you was added to the '" + rank.ToLower() + "' sub rank successfully!", Colours.generalCol);
            }
            else
            {
                await Context.Message.DeleteAsync();

                await errors.sendErrorTemp(chan, "You need to choose one of the listed roles!", Colours.errorCol);
            }
        }
예제 #5
0
        public async Task RankRemove(string rank)
        {
            var chan     = Context.Channel;
            var user     = Context.User;
            var userName = user as SocketGuildUser;
            await Context.Message.DeleteAsync();

            if (rank.ToLower().Equals("user"))
            {
                var role = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().UserRank);
                await(user as IGuildUser).RemoveRoleAsync(role);

                var ranks = new RankSaves();
                ranks.userCount        = RankSaves.Load().userCount - 1;
                ranks.musicCount       = RankSaves.Load().musicCount;
                ranks.programmingCount = RankSaves.Load().programmingCount;
                ranks.graphicsCount    = RankSaves.Load().graphicsCount;
                ranks.Save();

                await success.sendSuccessTemp(Context.Channel, "Remove Rank", "@" + Context.User.Id + " you was removed from the '" + rank.ToLower() + "' sub rank successfully!", Colours.generalCol);
            }
            else if (rank.ToLower().Equals("music"))
            {
                var role = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().MusicRank);
                await(user as IGuildUser).RemoveRoleAsync(role);

                var ranks = new RankSaves();
                ranks.userCount        = RankSaves.Load().userCount;
                ranks.musicCount       = RankSaves.Load().musicCount - 1;
                ranks.programmingCount = RankSaves.Load().programmingCount;
                ranks.graphicsCount    = RankSaves.Load().graphicsCount;
                ranks.Save();

                await success.sendSuccessTemp(Context.Channel, "Remove Rank", "@" + Context.User.Id + " you was removed from the '" + rank.ToLower() + "' sub rank successfully!", Colours.generalCol);
            }
            else if (rank.ToLower().Equals("programming"))
            {
                var role = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().ProgrammingRank);
                await(user as IGuildUser).RemoveRoleAsync(role);

                var ranks = new RankSaves();
                ranks.userCount        = RankSaves.Load().userCount;
                ranks.musicCount       = RankSaves.Load().musicCount;
                ranks.programmingCount = RankSaves.Load().programmingCount - 1;
                ranks.graphicsCount    = RankSaves.Load().graphicsCount;
                ranks.Save();

                await success.sendSuccessTemp(Context.Channel, "Remove Rank", "@" + Context.User.Id + " you was removed from the '" + rank.ToLower() + "' sub rank successfully!", Colours.generalCol);
            }
            else if (rank.ToLower().Equals("graphics"))
            {
                var role = Context.Guild.Roles.FirstOrDefault(x => x.Name.ToString() == BotConfig.Load().GraphicsRank);
                await(user as IGuildUser).RemoveRoleAsync(role);

                var ranks = new RankSaves();
                ranks.userCount        = RankSaves.Load().userCount;
                ranks.musicCount       = RankSaves.Load().musicCount;
                ranks.programmingCount = RankSaves.Load().programmingCount;
                ranks.graphicsCount    = RankSaves.Load().graphicsCount - 1;
                ranks.Save();

                await success.sendSuccessTemp(Context.Channel, "Remove Rank", "@" + Context.User.Id + " you was removed from the '" + rank.ToLower() + "' sub rank successfully!", Colours.generalCol);
            }
            else
            {
                await errors.sendErrorTemp(chan, "Parameter not recognised. Parameters are as follows user, music, programming or graphics", Colours.errorCol);
            }
        }
예제 #6
0
        public static void EnsureBotConfigExists()
        {
            if (!Directory.Exists(Path.Combine(AppContext.BaseDirectory, "configuration")))
            {
                Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "configuration"));
            }

            string configLoc   = Path.Combine(AppContext.BaseDirectory, "configuration/config.json");
            string ranksLoc    = Path.Combine(AppContext.BaseDirectory, "configuration/ranks.json");
            string subRanksLoc = Path.Combine(AppContext.BaseDirectory, "configuration/sub_ranks.json");

            if (!File.Exists(configLoc))
            {
                var config = new BotConfig();

                Console.WriteLine("Please enter the following information to save into your configuration/config.json file");
                Console.Write("Bot Token: ");
                config.Token = Console.ReadLine();
                Console.Write("Bot Prefix: ");
                config.Prefix = Console.ReadLine();
                Console.WriteLine("New Member Rank: ");
                config.NewMemberRank = Console.ReadLine();
                Console.WriteLine("User Rank: ");
                config.UserRank = Console.ReadLine();
                Console.WriteLine("Music Rank: ");
                config.MusicRank = Console.ReadLine();
                Console.WriteLine("Programming Rank: ");
                config.ProgrammingRank = Console.ReadLine();
                Console.WriteLine("Graphics Rank: ");
                config.GraphicsRank     = Console.ReadLine();
                config.welcomeChannelId = 0;
                config.Messages         = 1;
                config.Members          = 1;
                Console.WriteLine("You will have to enter the config file to manually set welcomeChannelId, Messages and Members. (configuration/config.json)");
                config.Save();
            }
            Console.WriteLine("Configuration has been loaded");

            if (!File.Exists(ranksLoc))
            {
                var ranks = new RankSaves();
                ranks.newMembersCount  = 0;
                ranks.userCount        = 0;
                ranks.musicCount       = 0;
                ranks.programmingCount = 0;
                ranks.graphicsCount    = 0;
                Console.WriteLine("You will have to enter the ranks save file to manually set the beginning statistics. (configuration/ranks.json)");
                ranks.Save();
            }
            Console.WriteLine("Ranks have been loaded");

            if (!File.Exists(subRanksLoc))
            {
                var subRanks = new SubRanksSaves();
                subRanks.MaxRanks = 20;
                subRanks.SubRanks = 1;
                Console.WriteLine("You will have to enter the sub ranks save file to manually set the beginning statistics. (configuration/sub_ranks.json)");
                subRanks.Save();
            }
            Console.WriteLine("Sub ranks have been loaded");
        }