-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added ML training on start (might be cached in future?) and ability to autoban
- Loading branch information
Showing
14 changed files
with
829 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module VahterBanBot.Tests.MLBanTests | ||
|
||
open System.Net | ||
open System.Threading.Tasks | ||
open VahterBanBot.Tests.ContainerTestBase | ||
open VahterBanBot.Tests.TgMessageUtils | ||
open Xunit | ||
open Xunit.Extensions.AssemblyFixture | ||
|
||
type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = | ||
|
||
[<Fact>] | ||
let ``Message IS autobanned if it looks like a spam`` () = task { | ||
// record a message, where 2 is in a training set as spam word | ||
// ChatsToMonitor[0] doesn't have stopwords | ||
let msgUpdate = Tg.quickMsg(chat = fixture.ChatsToMonitor[0], text = "2") | ||
let! _ = fixture.SendMessage msgUpdate | ||
|
||
// assert that the message got auto banned | ||
let! msgBanned = fixture.MessageIsAutoBanned msgUpdate.Message | ||
Assert.True msgBanned | ||
} | ||
|
||
[<Fact>] | ||
let ``Message is NOT autobanned if it has a stopword in specific chat`` () = task { | ||
// record a message, where 2 is in a training set as spam word | ||
// ChatsToMonitor[1] does have a stopword 2 | ||
let msgUpdate = Tg.quickMsg(chat = fixture.ChatsToMonitor[1], text = "2") | ||
let! _ = fixture.SendMessage msgUpdate | ||
|
||
// assert that the message got auto banned | ||
let! msgBanned = fixture.MessageIsAutoBanned msgUpdate.Message | ||
Assert.False msgBanned | ||
} | ||
|
||
[<Fact>] | ||
let ``Message is NOT autobanned if it is a known false-positive spam`` () = task { | ||
// record a message, where 3 is in a training set as spam word | ||
let msgUpdate = Tg.quickMsg(chat = fixture.ChatsToMonitor[0], text = "a") | ||
let! _ = fixture.SendMessage msgUpdate | ||
|
||
// assert that the message got auto banned | ||
let! msgBanned = fixture.MessageIsAutoBanned msgUpdate.Message | ||
Assert.False msgBanned | ||
} | ||
|
||
[<Fact>] | ||
let ``Message IS autobanned if it is a known false-negative spam`` () = task { | ||
// record a message, where 3 is in a training set as false negative spam word | ||
let msgUpdate = Tg.quickMsg(chat = fixture.ChatsToMonitor[0], text = "3") | ||
let! _ = fixture.SendMessage msgUpdate | ||
|
||
// assert that the message got auto banned | ||
let! msgBanned = fixture.MessageIsAutoBanned msgUpdate.Message | ||
Assert.True msgBanned | ||
} | ||
|
||
interface IAssemblyFixture<VahterTestContainers> | ||
interface IClassFixture<MlAwaitFixture> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.