예제 #1
0
        public async Task RemoveItem(int index)
        {
            DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id);

            if (server != null)
            {
                if (server.lootItems != null || server.lootItems.Count > 0)
                {
                    try
                    {
                        if (server.lootItems[index - 1] == null)
                        {
                            await ReplyAsync("There is no item at index " + index);
                        }
                        else
                        {
                            server.lootItems.RemoveAt(index - 1);
                            await ReplyAsync("Item Removed...");

                            server.SaveData();
                        }
                    }
                    catch (Exception)
                    {
                        await ReplyAsync("There is no item at index " + index);
                    }
                }
            }
        }
예제 #2
0
        public Task OnLeftGuild(SocketGuild guild)
        {
            DiscordServer server = DiscordServer.GetServerFromID(guild.Id);

            if (server != null)
            {
                DiscordServer.DeleteServerFile(guild);
                discordServers.Remove(server);
            }
            return(Task.CompletedTask);
        }
예제 #3
0
        public Task OnUserJoined(SocketGuildUser user)
        {
            DiscordServer server = DiscordServer.GetServerFromID(user.Guild.Id);

            if (server != null)
            {
                ((SocketTextChannel)server.WelcomeChannel).SendMessageAsync("Welcome to the server " + user.Mention + "!");
                user.AddRoleAsync(server.WelcomeRole);
                server.Users.Add(new ServerUser(user));
            }
            return(Task.CompletedTask);
        }
예제 #4
0
        public async Task Slot(float betPoints)
        {
            DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id);

            if (betPoints < server.minimumBetPoints)
            {
                await ReplyAsync("You cant gamble less than + " + server.minimumBetPoints + " points!");

                return;
            }
            await StartSlotting(betPoints);
        }
예제 #5
0
        public async Task SetMinimumBetPoints(float points = 10)
        {
            DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id);

            if (points > 0)
            {
                server.minimumBetPoints = points;
                await ReplyAsync("Minimum bet points set to: " + points);
            }
            else
            {
                await ReplyAsync("Minimum points cannot be lower than 1");
            }
        }
예제 #6
0
        public SaveDiscordServer(DiscordServer server)
        {
            if (server != null)
            {
                if (server.Guild.Name != null)
                {
                    ServerName = server.Guild.Name;
                }
                if (server.WelcomeChannel != null)
                {
                    WelcomeChannel = server.WelcomeChannel.Id.ToString();
                }
                if (server.WelcomeRole != null)
                {
                    WelcomeRole = server.WelcomeRole.Id.ToString();
                }
                if (server.swearJar != null)
                {
                    swearJar = server.swearJar;
                }
                if (server.Users != null)
                {
                    Users = server.Users;
                }
                if (server.voiceChannelRoles != null)
                {
                    voiceChannelRoles = server.voiceChannelRoles;
                }
                if (server.WelcomeRole != null)
                {
                    WelcomeRole = server.WelcomeRole.Id.ToString();
                }

                enabledSwearing = server.swearing;

                if (server.KickTimeStart != null)
                {
                    KickTimeStart = server.KickTimeStart;
                }
                PlayersKickedWithinTime = server.PlayersKickedWithinTime;

                if (server.lootItems != null)
                {
                    lootItems = server.lootItems;
                }

                minimumBetPoints = server.minimumBetPoints;
            }
        }
예제 #7
0
 private void AddPoints(SocketUserMessage message, DiscordServer server, ServerUser user)
 {
     if (server != null)
     {
         if (user != null)
         {
             if (user.LatestTalk.AddSeconds(server.PointGainDelayInSeconds) < DateTime.Now)
             {
                 user.LatestTalk = DateTime.Now;
                 user.Points    += 1;
                 server.SaveData();
             }
         }
     }
 }
예제 #8
0
        public async Task AddItem(string name, string description = "", string link = "")
        {
            DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id);

            if (server != null)
            {
                if (server.lootItems == null)
                {
                    server.lootItems = new List <LootItem>();
                }
                server.lootItems.Add(new LootItem(name, description, link));
                await ReplyAsync("Added " + name + " as a loot.");

                server.SaveData();
            }
        }
예제 #9
0
        public async Task Paginate()
        {
            DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id);

            if (server != null)
            {
                Console.WriteLine(server.lootItems.Count);
                if (server.lootItems == null || !(server.lootItems.Count > 0))
                {
                    await ReplyAsync("There is no loot.");

                    return;
                }
                var pages = new List <string>();

                int    itemPage   = 0;
                int    itemNumber = 0;
                string page       = "";
                foreach (LootItem item in server.lootItems)
                {
                    itemPage++;
                    itemNumber++;
                    page += itemNumber + " - " + item.Name + " : " + item.Description + "\n";
                    if (itemPage > 5)
                    {
                        itemPage = 0;
                        pages.Add(page);
                        page = "";
                    }
                }
                if (page != "")
                {
                    pages.Add(page);
                }

                var message = new PaginatedMessage(pages, "Reward List", new Color(0xb100c1), Context.User);

                await paginator.SendPaginatedMessageAsync(Context.Channel, message);
            }
        }
예제 #10
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            var message = arg as SocketUserMessage;

            if (message is null || message.Author.IsBot)
            {
                return;
            }

            DiscordServer server = discordServers.Find(x => x.Guild.GetChannel(message.Channel.Id) == message.Channel);
            ServerUser    user   = server.Users.Find(x => x.userID == message.Author.Id);
            await Swearing.CheckText(user, server, message);

            int argPos = 0;

            if (message.HasStringPrefix(botPrefix.ToString(), ref argPos))
            {
                var context = new SocketCommandContext(_client, message);

                var result = await _commands.ExecuteAsync(context, argPos, _services);

                if (!result.IsSuccess)
                {
                    if (result.ErrorReason != "Unknown command.")
                    {
                        Console.WriteLine(result.ErrorReason);
                        await message.Channel.SendMessageAsync(result.ErrorReason);
                    }
                }
            }
            else if (message.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                Modules.Talk.TalkWithBot(message);
            }

            AddPoints(message, server, user);
            await Swearing.SwearChecker(message, server, user);
        }
예제 #11
0
 private async Task OnMessageUpdated(Cacheable <IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3)
 {
     DiscordServer server = discordServers.Find(x => x.Guild.GetChannel(arg2.Channel.Id) == arg2.Channel);
     ServerUser    user   = server.Users.Find(x => x.userID == arg2.Author.Id);
     await Swearing.SwearChecker((SocketUserMessage)arg2, server, user);
 }
예제 #12
0
        public async Task StartSlotting(float betPoints)
        {
            DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id);

            if (server == null)
            {
                return;
            }

            ServerUser user = server.Users.Find(x => x.userID == Context.User.Id);

            if (user == null)
            {
                return;
            }

            if (user.Points < betPoints)
            {
                await ReplyAsync("You dont have enough points to bet: " + betPoints + "! (" + user.Points + ")");

                return;
            }
            user.Points -= betPoints;

            int[]         one          = int3();
            int[]         two          = int3();
            int[]         three        = int3();
            List <string> selectedRoll = new List <string>()
            {
                rolls[one[0]],
                rolls[two[0]],
                rolls[three[0]],

                rolls[one[1]],
                rolls[two[1]],
                rolls[three[1]],

                rolls[one[2]],
                rolls[two[2]],
                rolls[three[2]]
            };
            bool won = false;

            if (selectedRoll[0] == selectedRoll[1] && selectedRoll[0] == selectedRoll[2])
            {
                won = true;
            }
            else if (selectedRoll[3] == selectedRoll[4] && selectedRoll[3] == selectedRoll[5])
            {
                won = true;
            }
            else if (selectedRoll[6] == selectedRoll[7] && selectedRoll[6] == selectedRoll[8])
            {
                won = true;
            }

            LootItem wonItem = null;

            if (server.lootItems.Count > 0)
            {
                wonItem = server.lootItems[Program.random.Next(0, server.lootItems.Count)];
            }

            Embed newEmbed = new EmbedBuilder()
                             .WithTitle("Slot Machine")
                             .WithColor(Program.embedColor)
                             .WithTimestamp(DateTimeOffset.Now)
                             .WithFooter(footer => {
                footer
                .WithText("Slot Machine");
            })
                             .AddField("D-did you win?",
                                       selectedRoll[0] + " | " + selectedRoll[1] + " | " + selectedRoll[2] + "\n"
                                       + selectedRoll[3] + "  | " + selectedRoll[4] + "  | " + selectedRoll[5] + "\n"
                                       + selectedRoll[6] + "  | " + selectedRoll[7] + "  | " + selectedRoll[8] + "")
                             .AddField("Results:", "Betting: " + betPoints + " Points.\n" +
                                       (won ? "Won: " + (server.lootItems != null || server.lootItems.Count > 0 ? wonItem.Name : "Nothing") : "Lost: " + betPoints + " Points.")).Build();

            await ReplyAsync("", false, newEmbed);

            GlobalUser gUser = Program.globalUsers.Find(x => x.UserID == Context.User.Id);

            if (won && server.lootItems.Count > 0)
            {
                if (gUser != null)
                {
                    await Rewards.SendReward(gUser, wonItem, (SocketTextChannel)Context.Channel);
                }
            }

            if (string.IsNullOrEmpty(gUser?.email) && won)
            {
                await ReplyAsync("We reccomend you to register your email so we can send you the rewards. PM " + Program._client.CurrentUser.Mention + " your email!");
            }
        }
예제 #13
0
        public async Task Slot()
        {
            DiscordServer server = DiscordServer.GetServerFromID(Context.Guild.Id);

            await Slot(server.minimumBetPoints);
        }