Ejemplo n.º 1
0
        public async Task ToggleSpellTracking(ulong guildId, bool enabled)
        {
            using var context = new RPGContext(_options);

            GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(guildId).ConfigureAwait(false);

            guildPreferences.SpellingEnabled = enabled;

            context.GuildPreferences.Update(guildPreferences);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Ejemplo n.º 2
0
            public async Task guildInfo(CommandContext ctx)
            {
                await ctx.TriggerTypingAsync();

                AssignableRoleJson json = await GetRoleJson(ctx);

                GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id);

                StringBuilder sb = new StringBuilder();

                foreach (Roles role in json.Roles)
                {
                    DiscordEmoji emoji    = DiscordEmoji.FromGuildEmote(ctx.Client, role.EmojiId);
                    string       roleName = ctx.Guild.GetRole(role.RoleId).Name;

                    sb.Append(emoji + $" : {roleName}\n");
                }

                string timeoutRoleName;

                try { timeoutRoleName = ctx.Guild.GetRole(guildPreferences.TimeoutRoleId).Name; }
                catch { timeoutRoleName = "not set"; }

                var infoEmbed = new DiscordEmbedBuilder
                {
                    Title       = $"Wiggims Bot Settings for {ctx.Guild.Name}",
                    Description = "To edit any of the following settings, type `w!help guild` to see the options available.",
                    //Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url =  = ctx.Guild.IconUrl,
                    Color = DiscordColor.Orange
                };

                infoEmbed.AddField("Basic settings:",
                                   $"Spelling tracking: enabled = {guildPreferences.SpellingEnabled}. list length {guildPreferences.ErrorListLength}\n" +
                                   $"Xp earned per message: {guildPreferences.XpPerMessage} (For 10 messages within 60 seconds)\n" +
                                   $"Auto Role: Not Implemented yet\n" +
                                   $"Timeout role: {timeoutRoleName}");

                infoEmbed.AddField("Admin Settings:",
                                   $"Admin Role: Not Implemented yet\n" +
                                   $"Guild Event Notifications: Not Implemented yet\n" +
                                   $"Admin Notification Channel: Not Implemented yet\n" +
                                   $"Punish @ every ones: Not Implemented yet\n");

                infoEmbed.AddField("Roles available through `w!role join` and `w!role leave`:", sb.ToString());

                await ctx.Channel.SendMessageAsync("", embed : infoEmbed);
            }
Ejemplo n.º 3
0
                //######## Guild role Tasks ############
                public async Task <AssignableRoleJson> GetRoleJson(CommandContext ctx)
                {
                    GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id);

                    AssignableRoleJson json = JsonConvert.DeserializeObject <AssignableRoleJson>(guildPreferences.AssignableRoleJson);

                    return(json);
                }
Ejemplo n.º 4
0
        public async Task CreateOrModifyStatChannel(ulong guildId, ulong channelId, StatOption stat, string message)
        {
            using var context = new RPGContext(_options);

            GuildPreferences guildPrefs = await _guildPreferences.GetOrCreateGuildPreferences(guildId);

            CheckForGuildsStatCatergoryChannel(guildPrefs);

            var channelStat = guildPrefs.StatChannels.Where(x => x.StatOption == stat).FirstOrDefault();

            if (channelStat == null)
            {
                if (guildPrefs.StatChannels.Count >= 3)
                {
                    throw new Exception("You can only have 3 stats at a time, to create a new one, you must delete one of the channels and type `w@guild stats update true`, then try to create your stat channel again.");
                }

                channelStat = new StatChannel()
                {
                    StatMessage        = message,
                    StatOption         = stat,
                    ChannelId          = channelId,
                    GuildPreferencesId = guildPrefs.Id
                };
                context.Add(channelStat);
            }
            else
            {
                channelStat.StatMessage = message;
                channelStat.ChannelId   = channelId;
                channelStat.StatOption  = stat;
                context.Update(channelStat);
            }

            await context.SaveChangesAsync();
        }
Ejemplo n.º 5
0
                public async Task AddOrModify(CommandContext ctx)
                {
                    var guildPrefs = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id);

                    DiscordChannel parentChannel = ctx.Guild.GetChannel(guildPrefs.StatChannelCatergoryId);

                    if (parentChannel == null)
                    {
                        throw new Exception("You have not yet added a category where stats will be shown under. `w@guild stat setcategory <Channel category>`.");
                    }

                    var messageStep = new TextStep("What would you like the channel name to say? Will show as `<Your text here>: [stat] [Members name]` the limited number of characters is set low to prevent the stat from being hidden.", null, 0, 12);
                    var statStep    = new IntStep("What kind of stat would you like to track you can only have one of each type, to modify an existing one just select the same option? Please enter the corresponding number.\nMost gold - 0\nRobbing attack success rate - 1\nRobbing defense success rate - 2\nXp - 3\nGots - 4\nBoganness - 5\nGold Stolen - 6\nSpelling accuracy - 7\nGold Lost From Theft - 8\nRobbing Attack Wins - 9\nRobbing Defend Wins - 10\nHeads or tails wins - 11\nHeads or tails losses - 12\nCoin flip Win Rate - 13", messageStep, 0, 13);

                    int        statInput;
                    StatOption stat = StatOption.Gold;

                    string msgInput;
                    string message = "1";

                    statStep.OnValidResult += (result) =>
                    {
                        statInput = result;

                        stat = (StatOption)result;

                        statStep.SetNextStep(messageStep);
                    };

                    messageStep.onValidResult += (result) =>
                    {
                        msgInput = result;

                        message = result;
                    };

                    var userChannel = await ctx.Member.CreateDmChannelAsync().ConfigureAwait(false);

                    var inputDialogueHandler = new DialogueHandler(
                        ctx.Client,
                        ctx.Channel,
                        ctx.User,
                        statStep
                        );

                    bool succeeded = await inputDialogueHandler.ProcessDialogue().ConfigureAwait(false);

                    if (!succeeded)
                    {
                        return;
                    }

                    ulong channelId;

                    if (guildPrefs.StatChannels.Exists(x => x.StatOption == stat))
                    {
                        channelId = guildPrefs.StatChannels.Where(x => x.StatOption == stat).FirstOrDefault().ChannelId;
                    }
                    else
                    {
                        channelId = ctx.Guild.CreateVoiceChannelAsync("waiting for update...", parentChannel).Result.Id;
                    }

                    await _statChannelService.CreateOrModifyStatChannel(ctx.Guild.Id, channelId, stat, message);

                    await ctx.Channel.SendMessageAsync("There should be a new text channel in the specified category and will be updated on the next stat update cycle.").ConfigureAwait(false);
                }
Ejemplo n.º 6
0
            public async Task GiveTimeout(CommandContext ctx, [Description("Mention or use ID")] DiscordMember member, [Description("Timeout duration (s, m, h) default is 10 minutes.")] TimeSpan?timeSpan = null)
            {
                await ctx.Message.DeleteAsync();

                var guildPrefs = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id);

                if (guildPrefs.TimeoutRoleId == 0U)
                {
                    await ctx.RespondAsync("There is no timeout role set yet, please use ` w@guild settimeoutrole <role>` to set it.");

                    return;
                }

                if (timeSpan == null)
                {
                    timeSpan = TimeSpan.FromMinutes(10);
                }

                if (timeSpan > TimeSpan.FromMinutes(30))
                {
                    await ctx.RespondAsync("Please use a timeout duration of less that half an hour.");

                    return;
                }

                string      filePath    = MakeTimeoutJson(ctx, member, $"{member.Username}-{DateTime.Now.Day}-{DateTime.Now.Month}-{DateTime.Now.Hour}-{DateTime.Now.Minute}.json");
                var         roles       = member.Roles.ToArray();
                DiscordRole timeoutRole = ctx.Guild.GetRole(guildPrefs.TimeoutRoleId);

                foreach (var role in roles)
                {
                    try
                    {
                        await member.RevokeRoleAsync(role);
                    }
                    catch (UnauthorizedException ex)
                    {
                        await ctx.RespondAsync("Wiggimsbot is unable to remove the roles of this member, as they have a role with higher permissions than the bot.");

                        return;
                    }
                }

                await member.GrantRoleAsync(timeoutRole);

                var embed = new DiscordEmbedBuilder
                {
                    Title       = $"{member.Username} has been sent to a timeout",
                    Color       = DiscordColor.Orange,
                    Description = $"To manually reset the roles of this member for whatever reason type `w@timeout restore {member.Id} {filePath}`"
                };

                await ctx.Channel.SendMessageAsync(embed : embed).ConfigureAwait(false);

                System.Threading.Thread.Sleep(Convert.ToInt32(timeSpan.Value.TotalMilliseconds));

                await member.RevokeRoleAsync(timeoutRole);

                var roleJson = GetTimeoutJson(filePath);

                if (roleJson.HasBeenRestored)
                {
                    return;
                }

                foreach (var roleId in roleJson.RoleId)
                {
                    DiscordRole role = ctx.Guild.GetRole(roleId);
                    await member.GrantRoleAsync(role);
                }

                MarkTimeoutDone(filePath);
                await ctx.Channel.SendMessageAsync($"{member.Username}'s timeout has ended.");
            }
Ejemplo n.º 7
0
        public async Task WiggimsBotSpell(CommandContext ctx)
        {
            bool isCommand   = ctx.Message.Content.ToLower().Contains("w!") || ctx.Message.Content.ToLower().Contains("w@");
            bool isBot       = ctx.Message.Author.IsBot;
            bool isCodeBlock = ctx.Message.Content.Contains("```");

            string[]      message      = ctx.Message.Content.Split();
            int           errorCount   = 0;
            int           correctCount = 0;
            int           boganCount   = 0;
            List <string> sb           = new List <string> {
            };

            GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id);

            if (!isCommand && !isBot && !isCodeBlock)
            {
                foreach (string word in message)
                {
                    if (
                        string.IsNullOrWhiteSpace(word) ||
                        word.Contains("https://") ||
                        word.Length > 18 ||
                        word.Contains(":") ||
                        word.Contains("😢") ||
                        word.Contains("👍") ||
                        word.Contains("👎") ||
                        word.Contains("😀") ||
                        word.Contains("😃") ||
                        word.Contains("😄") ||
                        word.Contains("😁") ||
                        word.Contains("😆") ||
                        word.Contains("😅") ||
                        word.Contains("😂") ||
                        word.StartsWith("!") ||
                        word.StartsWith("d!") ||
                        word.StartsWith(">") ||
                        !guildPreferences.SpellingEnabled
                        )
                    {
                        return;
                    }

                    var    dictionary      = WordList.CreateFromFiles(@"Resources/en_au.dic");
                    var    boganDictionary = WordList.CreateFromFiles(@"Resources/badwords.dic");
                    string cleanedWord     = Regex.Replace(word.ToLower(), @"[^\w\s]", "");
                    bool   notOk           = dictionary.Check(cleanedWord);
                    bool   Bogan           = boganDictionary.Check(cleanedWord);

                    if (notOk == false)
                    {
                        errorCount += 1;
                        Console.WriteLine(cleanedWord);
                        sb.Add(cleanedWord);
                        await File.AppendAllTextAsync(@"Resources/missspelledwordsall.txt", $"\n{cleanedWord} - {word}");

                        var  wrongDictionary = WordList.CreateFromFiles(@"Resources/missspelledwords.dic");
                        bool alreadyPresent  = wrongDictionary.Check(cleanedWord);

                        if (alreadyPresent == false)
                        {
                            string dicFilePath = @"Resources/missspelledwords.dic";
                            await File.AppendAllTextAsync(dicFilePath, $"\n{cleanedWord}");
                        }

                        if (Bogan == true)
                        {
                            boganCount += 1;
                        }
                    }
                    else
                    {
                        correctCount += 1;

                        if (Bogan == true)
                        {
                            boganCount += 1;
                        }
                    }
                }

                Console.WriteLine($"{ctx.Message.Author.Username} sent a message in the {ctx.Guild.Name} guild. spelling stats:\nCorrect: {correctCount}\tIncorrect: {errorCount}\tBogan words: {boganCount}");

                Profile profile = await _profileService.GetOrCreateProfileAsync(ctx.Member.Id, ctx.Guild.Id);

                TextProcessorViewModel viewModel = await _textProcessorService.ProcessTextAsync(ctx.Member.Id, ctx.Guild.Id, $"{ctx.Member.Username}#{ctx.Member.Discriminator}", correctCount, errorCount, boganCount, 1, guildPreferences.ErrorListLength, sb).ConfigureAwait(false);

                if (!viewModel.LevelledUp)
                {
                    return;
                }

                var json = string.Empty;

                using (var fs = File.OpenRead("config.json"))
                    using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                        json = sr.ReadToEnd();

                var configJson     = JsonConvert.DeserializeObject <ConfigJson>(json);
                int goldperlevelup = configJson.goldperlevelup;

                await _goldService.TransferGold(ctx.Client.CurrentUser.Id, ctx.Member.Id, ctx.Guild.Id, goldperlevelup, true);

                if (profile.QuietMode == true)
                {
                    return;
                }

                var levelUpEmbed = new DiscordEmbedBuilder
                {
                    Title     = $"{ctx.Member.DisplayName} Is Now Level {viewModel.Profile.Level}",
                    Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail {
                        Url = ctx.Member.AvatarUrl
                    },
                    Color = ctx.Member.Color
                };

                if (goldperlevelup > 0)
                {
                    levelUpEmbed.WithDescription($"+ {goldperlevelup} :moneybag:");
                }

                levelUpEmbed.WithFooter("`w!profile togglenotifications` to hide In future.");

                await ctx.Channel.SendMessageAsync(embed : levelUpEmbed).ConfigureAwait(false);
            }
        }