Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public async Task TestItDoesntAlwaysFail(string goodString) {

// Process the message and assert that we pass the message.
var chat = new TwitchChatMessage(true, goodString, "123", "456");
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
bool result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
Assert.That(result, Is.True);

// Process the message and assert that we pass the message.
chat = new TwitchChatMessage(false, goodString, "123", "456");
result = await rule.Handle("123", botProxy.Object, chat, _db);
result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
Assert.That(result, Is.True);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task TestKnownStrings(string badString) {
var chat = new TwitchChatMessage(true, badString, "123", "456");

// Process the message and assert that we fail the message.
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
bool result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
Assert.That(result, Is.False);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task TestKnownStrings(string badString) {
var chat = new TwitchChatMessage(true, badString, "123", "456");

// Process the message and assert that we fail the message.
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
bool result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
Assert.That(result, Is.False);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task TestKnownStrings(string badString) {
var chat = new TwitchChatMessage(true, badString, "123", "456");

// Process the message and assert that we fail the message.
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
bool result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
Assert.That(result, Is.False);
}

Expand All @@ -52,7 +52,7 @@ public async Task EnsureNoFalsePositives(string message) {
var chat = new TwitchChatMessage(true, message, "123", "456");

// Process the message and assert that we do not fail the message.
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
bool result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
Assert.That(result, Is.True);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task TestKnownStrings(string badString) {
var chat = new TwitchChatMessage(true, badString, "123", "456");

// Process the message and assert that we fail the message.
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
bool result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
Assert.That(result, Is.False);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task TestKnownStrings(string badString) {
var chat = new TwitchChatMessage(true, badString, "123", "456");

// Process the message and assert that we fail the message.
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
bool result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
Assert.That(result, Is.False);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task TestKnownStrings(string badString) {
var chat = new TwitchChatMessage(true, badString, "123", "456");

// Process the message and assert that we fail the message.
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
bool result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
Assert.That(result, Is.False);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task TestKnownStrings(string badString) {
var chat = new TwitchChatMessage(true, badString, "123", "456");

// Process the message and assert that we fail the message.
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
bool result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
Assert.That(result, Is.False);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.7"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
<PackageReference Include="Moq" Version="4.20.72"/>
<PackageReference Include="NUnit" Version="4.3.2"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xml:space="preserve">
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot.Tests/UnitTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public virtual void Setup() {
[TearDown]
public virtual async Task TearDown() {
// Dispose since it has one.
await _db.DisposeAsync();
await _db.DisposeAsync().ConfigureAwait(false);
}
}
4 changes: 2 additions & 2 deletions src/Nullinside.Api.TwitchBot/Bots/ABotRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ where string.Equals(bannedUsers.ChannelId, channelId) &&

// Perform the ban and get the list of people actually banned
IEnumerable<BannedUser> confirmedBans =
await botProxy.BanChannelUsers(channelId, Constants.BOT_ID, bansToTry, reason, stoppingToken);
await botProxy.BanChannelUsers(channelId, Constants.BOT_ID, bansToTry, reason, stoppingToken).ConfigureAwait(false);

await db.SaveTwitchBans(channelId, users, reason, stoppingToken);
await db.SaveTwitchBans(channelId, users, reason, stoppingToken).ConfigureAwait(false);
return confirmedBans;
}
}
4 changes: 2 additions & 2 deletions src/Nullinside.Api.TwitchBot/ChatRules/AChatRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract Task<bool> Handle(string channelId, ITwitchApiProxy botProxy, Tw
public async Task BanAndLog(string channelId, ITwitchApiProxy botProxy,
IEnumerable<(string Id, string Username)> users, string reason, INullinsideContext db,
CancellationToken stoppingToken = new()) {
await botProxy.BanChannelUsers(channelId, Constants.BOT_ID, users, reason, stoppingToken);
await db.SaveTwitchBans(channelId, users, reason, stoppingToken);
await botProxy.BanChannelUsers(channelId, Constants.BOT_ID, users, reason, stoppingToken).ConfigureAwait(false);
await db.SaveTwitchBans(channelId, users, reason, stoppingToken).ConfigureAwait(false);
}
}
4 changes: 2 additions & 2 deletions src/Nullinside.Api.TwitchBot/ChatRules/BestCheapViewers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
// If everything matches except 3 characters, take it. We will assume the 3 characters are "special" characters
// used to confuse us.
if (matches > expected.Length - 3) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Best Cheap Viewers)", db, stoppingToken);
(string UserId, string Username)[] users = new[] { (message.UserId, message.Username) };
await BanAndLog(channelId, botProxy, users, "[Bot] Spam (Best Cheap Viewers)", db, stoppingToken).ConfigureAwait(false);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/Botsister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
// Message will start with any of these variations.
if (message.IsFirstMessage && normalized.Contains("botsister")) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Botsister)", db, stoppingToken);
"[Bot] Spam (Botsister)", db, stoppingToken).ConfigureAwait(false);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
foreach (string phrase in _knownPhrases) {
if (normalized.Contains(phrase, StringComparison.InvariantCultureIgnoreCase)) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Discord Scammers)", db, stoppingToken);
"[Bot] Spam (Discord Scammers)", db, stoppingToken).ConfigureAwait(false);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/Dogehype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
// Message will start with any of these variations.
if (message.IsFirstMessage && normalized.Contains("dogehype")) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Dogehype)", db, stoppingToken);
"[Bot] Spam (Dogehype)", db, stoppingToken).ConfigureAwait(false);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/HostHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
// Message will contain the site name with different domains.
if (message.IsFirstMessage && normalized.Contains("hosthub.")) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (HostHub)", db, stoppingToken);
"[Bot] Spam (HostHub)", db, stoppingToken).ConfigureAwait(false);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
foreach (string expected in Expected) {
if (normalized.Contains(expected, StringComparison.InvariantCultureIgnoreCase)) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (If You Want Viewers)", db, stoppingToken);
"[Bot] Spam (If You Want Viewers)", db, stoppingToken).ConfigureAwait(false);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/Naked.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
(message.Message.TrimStart().StartsWith(SPAM, StringComparison.InvariantCultureIgnoreCase) ||
message.Message.TrimStart().StartsWith(SPAM2, StringComparison.InvariantCultureIgnoreCase))) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Naked)", db, stoppingToken);
"[Bot] Spam (Naked)", db, stoppingToken).ConfigureAwait(false);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/Nezhna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro

if (message.Message.Contains(SPAM, StringComparison.InvariantCultureIgnoreCase)) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Nezhna)", db, stoppingToken);
"[Bot] Spam (Nezhna)", db, stoppingToken).ConfigureAwait(false);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/StreamRise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
INullinsideContext db, CancellationToken stoppingToken = new()) {
if (message.IsFirstMessage && SPAM.Equals(message.Message, StringComparison.InvariantCultureIgnoreCase)) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (StreamRise)", db, stoppingToken);
"[Bot] Spam (StreamRise)", db, stoppingToken).ConfigureAwait(false);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/StreamViewers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
// 3. In places where the characters didn't match, they only didn't match because the message used a non-english keyboard character. It was never because a different letter was in the position.
// 4. It was probably an @ mention to another user where the @ was the first thing in the message.
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (StreamViewers)", db, stoppingToken);
"[Bot] Spam (StreamViewers)", db, stoppingToken).ConfigureAwait(false);
return false;
}
}
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/Streamboo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
// Message will start with any of these variations.
if (message.IsFirstMessage && normalized.Contains("streamboo")) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Streamboo)", db, stoppingToken);
"[Bot] Spam (Streamboo)", db, stoppingToken).ConfigureAwait(false);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private async void MainLoop() {
}

// Get the bot proxy
ITwitchApiProxy? botProxy = await _db.ConfigureBotApiAndRefreshToken(_api);
ITwitchApiProxy? botProxy = await _db.ConfigureBotApiAndRefreshToken(_api).ConfigureAwait(false);
if (null == botProxy) {
continue;
}
Expand All @@ -154,7 +154,7 @@ private async void MainLoop() {
foreach (IChatRule rule in rules) {
try {
if (rule.ShouldRun(user.TwitchConfig)) {
if (!await rule.Handle(user.TwitchId, botProxy, new TwitchChatMessage(message), _db)) {
if (!await rule.Handle(user.TwitchId, botProxy, new TwitchChatMessage(message), _db).ConfigureAwait(false)) {
break;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/Nullinside.Api.TwitchBot/Controllers/BotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public BotController(INullinsideContext dbContext, IConfiguration configuration)
}

api.Configure(user);
IEnumerable<Moderator> mods = await api.GetChannelMods(user.TwitchId, token);
IEnumerable<Moderator> mods = await api.GetChannelMods(user.TwitchId, token).ConfigureAwait(false);
return Ok(new {
isMod = null != mods.FirstOrDefault(m =>
string.Equals(m.UserId, Constants.BOT_ID, StringComparison.InvariantCultureIgnoreCase))
Expand Down Expand Up @@ -97,7 +97,7 @@ public async Task<IActionResult> ModBotAccount([FromServices] ITwitchApiProxy ap
}

api.Configure(user);
bool success = await api.AddChannelMod(user.TwitchId, Constants.BOT_ID, token);
bool success = await api.AddChannelMod(user.TwitchId, Constants.BOT_ID, token).ConfigureAwait(false);
return Ok(success);
}

Expand All @@ -114,13 +114,13 @@ public async Task<IActionResult> GetConfig(CancellationToken token) {
return Unauthorized();
}

User? user = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == int.Parse(userId.Value) && !u.IsBanned, token);
User? user = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == int.Parse(userId.Value) && !u.IsBanned, token).ConfigureAwait(false);
if (null == user) {
return Unauthorized();
}

Api.Model.Ddl.TwitchUserConfig? config =
await _dbContext.TwitchUserConfig.FirstOrDefaultAsync(c => c.UserId == user.Id, token);
await _dbContext.TwitchUserConfig.FirstOrDefaultAsync(c => c.UserId == user.Id, token).ConfigureAwait(false);
if (null == config) {
return Ok(new TwitchUserConfig {
IsEnabled = true,
Expand All @@ -144,7 +144,7 @@ public async Task<IActionResult> GetConfig(CancellationToken token) {
[Route("chat/timestamp")]
public async Task<IActionResult> GetLastChatTimestamp(CancellationToken token) {
TwitchUserChatLogs? message =
await _dbContext.TwitchUserChatLogs.OrderByDescending(c => c.Timestamp).FirstOrDefaultAsync(token);
await _dbContext.TwitchUserChatLogs.OrderByDescending(c => c.Timestamp).FirstOrDefaultAsync(token).ConfigureAwait(false);
if (null == message) {
return StatusCode(500);
}
Expand All @@ -168,22 +168,22 @@ public async Task<IActionResult> SetConfig(TwitchUserConfig config, Cancellation

int userId = int.Parse(userIdClaim.Value);
Api.Model.Ddl.TwitchUserConfig? configDb =
await _dbContext.TwitchUserConfig.FirstOrDefaultAsync(c => c.UserId == userId, token);
await _dbContext.TwitchUserConfig.FirstOrDefaultAsync(c => c.UserId == userId, token).ConfigureAwait(false);
if (null == configDb) {
await _dbContext.TwitchUserConfig.AddAsync(new Api.Model.Ddl.TwitchUserConfig {
BanKnownBots = config.BanKnownBots,
Enabled = config.IsEnabled,
UserId = userId,
UpdatedOn = DateTime.UtcNow
}, token);
}, token).ConfigureAwait(false);
}
else {
configDb.Enabled = config.IsEnabled;
configDb.BanKnownBots = config.BanKnownBots;
configDb.UpdatedOn = DateTime.UtcNow;
}

await _dbContext.SaveChangesAsync(token);
await _dbContext.SaveChangesAsync(token).ConfigureAwait(false);
return Ok(config);
}
}
8 changes: 4 additions & 4 deletions src/Nullinside.Api.TwitchBot/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ public LoginController(INullinsideContext dbContext, IConfiguration configuratio
[HttpGet]
public async Task<IActionResult> TwitchLogin([FromQuery] string code, [FromServices] ITwitchApiProxy api, CancellationToken token) {
string? siteUrl = _configuration.GetValue<string>("Api:SiteUrl");
if (null == await api.CreateAccessToken(code, token)) {
if (null == await api.CreateAccessToken(code, token).ConfigureAwait(false)) {
return Redirect($"{siteUrl}/twitch-bot/config?error={TwitchBotLoginErrors.TWITCH_ERROR_WITH_TOKEN}");
}

string? email = await api.GetUserEmail(token);
string? email = await api.GetUserEmail(token).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(email)) {
return Redirect($"{siteUrl}/twitch-bot/config?error={TwitchBotLoginErrors.TWITCH_ACCOUNT_HAS_NO_EMAIL}");
}

User? user = await api.GetUser(token);
User? user = await api.GetUser(token).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(user?.Login) || string.IsNullOrWhiteSpace(user.Id)) {
return Redirect($"{siteUrl}/twitch-bot/config?error={TwitchBotLoginErrors.INTERNAL_ERROR}");
}

string? bearerToken = await UserHelpers.GenerateTokenAndSaveToDatabase(_dbContext, email, token, api.OAuth?.AccessToken,
api.OAuth?.RefreshToken, api.OAuth?.ExpiresUtc, user.Login, user.Id);
api.OAuth?.RefreshToken, api.OAuth?.ExpiresUtc, user.Login, user.Id).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(bearerToken)) {
return Redirect($"{siteUrl}/twitch-bot/config?error={TwitchBotLoginErrors.INTERNAL_ERROR}");
}
Expand Down
Loading