forked from SunRed/discord-tweeter
feat: Major refactor, implement web, caching, better tests and build files
* Update golang version to 1.24 * Update multiarch Dockerfile to be more ISA agnostic * Refactor existing code and properly structure project into modules * Get rid of global variables except where necessary (go:embed) * Add default values to Config * Add webserver with templates to finally correctly serve videos and gifs * Add tiny caching library to decrease api load and improve latency * Improve Webhook data preparation by filtering out redundant links from the tweet text and properly attaching videos and gifs in separate webhook request by utilising new webserver * Improve tests for filter function * Improve bake definition for easier CI integration
This commit is contained in:
parent
7562b86894
commit
21d580d1a6
24 changed files with 752 additions and 209 deletions
43
cmd/tweeter/tweeter_test.go
Normal file
43
cmd/tweeter/tweeter_test.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package tweeter
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ts "github.com/imperatrona/twitter-scraper"
|
||||
)
|
||||
|
||||
func TestFilter(t *testing.T) {
|
||||
filter1 := []uint8{0b10101, 0b11111, 0b00000, 0b00111, 0b00101, 0b00001, 0b10111, 0b10101, 0b01101, 0b10101}
|
||||
filter2 := []uint8{0b10101, 0b11111, 0b00000, 0b00111, 0b00101, 0b00001, 0b01000, 0b01010, 0b01000, 0b11011}
|
||||
filterR := []uint8{0b10101, 0b11111, 0b00000, 0b00111, 0b00101, 0b00001, 0b00000, 0b00000, 0b01000, 0b10001}
|
||||
filterB := []bool{true, true, false, true, true, true, false, false, true, true}
|
||||
|
||||
for i, filterBool := range filterB {
|
||||
filterResult := filterR[i]
|
||||
|
||||
filterCheck := filter2[i]
|
||||
filterQuoted := (filterCheck & 1) != 0 // first bit
|
||||
filterPin := (filterCheck & 2) != 0 // second bit
|
||||
filterReply := (filterCheck & 4) != 0 // third bit
|
||||
filterRetweet := (filterCheck & 8) != 0 // fourth bit
|
||||
filterSelfThread := (filterCheck & 16) != 0 // fifth bit
|
||||
|
||||
tweet := ts.Tweet{
|
||||
IsSelfThread: filterSelfThread,
|
||||
IsRetweet: filterRetweet,
|
||||
IsReply: filterReply,
|
||||
IsPin: filterPin,
|
||||
IsQuoted: filterQuoted,
|
||||
}
|
||||
|
||||
resultBool := filterTweet(filter1[i], &tweet)
|
||||
if resultBool != filterBool {
|
||||
t.Errorf("%b AND %b > 0 = %t; got %t\n", filter1[i], filter2[i], filterBool, resultBool)
|
||||
}
|
||||
|
||||
resultByte := filterByte(filter1[i], &tweet)
|
||||
if resultByte != filterResult {
|
||||
t.Errorf("%b AND %b = %b; got %b\n", filter1[i], filter2[i], filterResult, resultByte)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue