static TranslateCommands() { NadekoBot.Client.MessageReceived += async(msg) => { try { var umsg = msg as SocketUserMessage; if (umsg == null) { return; } bool autoDelete; if (!TranslatedChannels.TryGetValue(umsg.Channel.Id, out autoDelete)) { return; } var key = new UserChannelPair() { UserId = umsg.Author.Id, ChannelId = umsg.Channel.Id, }; string langs; if (!UserLanguages.TryGetValue(key, out langs)) { return; } var text = await TranslateInternal(langs, umsg.Resolve(TagHandling.Ignore), true) .ConfigureAwait(false); if (autoDelete) { try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { } } await umsg.Channel.SendConfirmAsync($"{umsg.Author.Mention} `:` " + text.Replace("<@ ", "<@").Replace("<@! ", "<@!")).ConfigureAwait(false); } catch { } }; }
public SearchesService(DiscordSocketClient client, IGoogleApiService google, DbService db, Kotocorn bot, IDataCache cache, FontProvider fonts) { Http = new HttpClient(); Http.AddFakeHeaders(); _client = client; _google = google; _db = db; _log = LogManager.GetCurrentClassLogger(); _imgs = cache.LocalImages; _cache = cache; _fonts = fonts; _blacklistedTags = new ConcurrentDictionary <ulong, HashSet <string> >( bot.AllGuildConfigs.ToDictionary( x => x.GuildId, x => new HashSet <string>(x.NsfwBlacklistedTags.Select(y => y.Tag)))); //translate commands _client.MessageReceived += (msg) => { var _ = Task.Run(async() => { try { var umsg = msg as SocketUserMessage; if (umsg == null) { return; } if (!TranslatedChannels.TryGetValue(umsg.Channel.Id, out var autoDelete)) { return; } var key = new UserChannelPair() { UserId = umsg.Author.Id, ChannelId = umsg.Channel.Id, }; if (!UserLanguages.TryGetValue(key, out string langs)) { return; } var text = await Translate(langs, umsg.Resolve(TagHandling.Ignore)) .ConfigureAwait(false); if (autoDelete) { try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { } } await umsg.Channel.SendConfirmAsync($"{umsg.Author.Mention} `:` " + text.Replace("<@ ", "<@").Replace("<@! ", "<@!")).ConfigureAwait(false); } catch { } }); return(Task.CompletedTask); }; //joke commands if (File.Exists("data/wowjokes.json")) { WowJokes = JsonConvert.DeserializeObject <List <WoWJoke> >(File.ReadAllText("data/wowjokes.json")); } else { _log.Warn("data/wowjokes.json is missing. WOW Jokes are not loaded."); } if (File.Exists("data/magicitems.json")) { MagicItems = JsonConvert.DeserializeObject <List <MagicItem> >(File.ReadAllText("data/magicitems.json")); } else { _log.Warn("data/magicitems.json is missing. Magic items are not loaded."); } }