async Task RunDiscord(CancellationToken cancellationToken) { var firstBot = new ChatBot { ConnectionString = Environment.GetEnvironmentVariable("TGS4_TEST_DISCORD_TOKEN"), Enabled = false, Name = "r4407", Provider = ChatProvider.Discord, ReconnectionInterval = 1, ChannelLimit = 1 }; var csb = new DiscordConnectionStringBuilder(firstBot.ConnectionString); Assert.IsTrue(csb.Valid, $"Invalid Discord connection string: {firstBot.ConnectionString}"); firstBot = await chatClient.Create(firstBot, cancellationToken); Assert.AreEqual(csb.ToString(), firstBot.ConnectionString); Assert.AreNotEqual(0, firstBot.Id); var bots = await chatClient.List(cancellationToken); Assert.AreEqual(firstBot.Id, bots.First(x => x.Provider.Value == ChatProvider.Discord).Id); var retrievedBot = await chatClient.GetId(firstBot, cancellationToken); Assert.AreEqual(firstBot.Id, retrievedBot.Id); firstBot.Enabled = true; var updatedBot = await chatClient.Update(firstBot, cancellationToken); Assert.AreEqual(true, updatedBot.Enabled); var channelId = UInt64.Parse(Environment.GetEnvironmentVariable("TGS4_TEST_DISCORD_CHANNEL")); firstBot.Channels = new List <ChatChannel> { new ChatChannel { IsAdminChannel = true, IsUpdatesChannel = true, IsWatchdogChannel = true, Tag = "butt", DiscordChannelId = channelId } }; updatedBot = await chatClient.Update(firstBot, cancellationToken); Assert.AreEqual(true, updatedBot.Enabled); Assert.IsNotNull(updatedBot.Channels); Assert.AreEqual(1, updatedBot.Channels.Count); Assert.AreEqual(true, updatedBot.Channels.First().IsAdminChannel); Assert.AreEqual(true, updatedBot.Channels.First().IsUpdatesChannel); Assert.AreEqual(true, updatedBot.Channels.First().IsWatchdogChannel); Assert.AreEqual("butt", updatedBot.Channels.First().Tag); Assert.AreEqual(channelId, updatedBot.Channels.First().DiscordChannelId); Assert.IsNull(updatedBot.Channels.First().IrcChannel); }
/// <summary> /// Construct a <see cref="DiscordProvider"/> /// </summary> /// <param name="jobManager">The <see cref="IJobManager"/> for the <see cref="Provider"/>.</param> /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param> /// <param name="logger">The <see cref="ILogger"/> for the <see cref="Provider"/>.</param> /// <param name="chatBot">The <see cref="ChatBot"/> for the <see cref="Provider"/>.</param> public DiscordProvider( IJobManager jobManager, IAssemblyInformationProvider assemblyInformationProvider, ILogger <DiscordProvider> logger, Models.ChatBot chatBot) : base(jobManager, logger, chatBot) { this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider)); var csb = new DiscordConnectionStringBuilder(chatBot.ConnectionString); botToken = csb.BotToken; basedMeme = csb.BasedMeme; outputDisplayType = csb.DMOutputDisplay; client = new DiscordSocketClient(); client.MessageReceived += Client_MessageReceived; mappedChannels = new List <ulong>(); }