public async Task <GuildPreferences> GetOrCreateGuildPreferences(ulong guildId) { using var context = new RPGContext(_options); GuildPreferences guildPrefences = await context.GuildPreferences .Where(x => x.GuildId == guildId) .Include(sc => sc.StatChannels) .FirstOrDefaultAsync(x => x.GuildId == guildId).ConfigureAwait(false); if (guildPrefences != null) { return(guildPrefences); } guildPrefences = new GuildPreferences { GuildId = guildId, XpPerMessage = 1, SpellingEnabled = false, ErrorListLength = 10, AssignableRoleJson = "{\"Roles\":[]}", GoldPerLevelUp = 50, IsGoldEnabled = true }; context.Add(guildPrefences); await context.SaveChangesAsync().ConfigureAwait(false); return(guildPrefences); }
public async Task CheckForGuildsStatCatergoryChannel(GuildPreferences guildPreferences) { if (guildPreferences.StatChannelCatergoryId == 0u) { throw new Exception("No channel category has been set for the guild, please set one now with `w@guild stats setcategory <Catergories Id>`."); } }
//######## 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); }
public async Task togglespelling(CommandContext ctx) { GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id); await _spellingSettingsService.ToggleSpellTracking(ctx.Guild.Id, !guildPreferences.SpellingEnabled); await ctx.Channel.SendMessageAsync($"Spell checking enabled: {!guildPreferences.SpellingEnabled}"); }
public async Task SetSpellListLength(ulong guildId, int listLength) { using var context = new RPGContext(_options); GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(guildId).ConfigureAwait(false); guildPreferences.ErrorListLength = listLength; context.GuildPreferences.Update(guildPreferences); await context.SaveChangesAsync().ConfigureAwait(false); }
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); }
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); }
public async Task DeleteStatChannel(ulong guildId, StatOption stat) { 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) { return; } context.Remove(channelStat); await context.SaveChangesAsync(); }
public async Task RemoveRoleFromAssignableRoles(ulong guildId, ulong roleId) { using var context = new RPGContext(_options); GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(guildId).ConfigureAwait(false); AssignableRoleJson roleArray = JsonConvert.DeserializeObject <AssignableRoleJson>(guildPreferences.AssignableRoleJson); int roleIndex = roleArray.Roles.FindIndex(x => x.RoleId == roleId); roleArray.Roles.RemoveAt(roleIndex); string newRoleArray = JsonConvert.SerializeObject(roleArray); guildPreferences.AssignableRoleJson = newRoleArray; context.GuildPreferences.Update(guildPreferences); await context.SaveChangesAsync().ConfigureAwait(false); }
public async Task AddRoleToAssignableRoles(ulong guildId, ulong roleId, ulong emojiId) { using var context = new RPGContext(_options); GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(guildId).ConfigureAwait(false); AssignableRoleJson roleArray = JsonConvert.DeserializeObject <AssignableRoleJson>(guildPreferences.AssignableRoleJson); Roles roleToAdd = new Roles { RoleId = roleId, EmojiId = emojiId }; roleArray.Roles.Add(roleToAdd); string newRoleArray = JsonConvert.SerializeObject(roleArray); guildPreferences.AssignableRoleJson = newRoleArray; context.GuildPreferences.Update(guildPreferences); await context.SaveChangesAsync().ConfigureAwait(false); }
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(); }
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); } }