Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Add PAP field
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyaglow committed Nov 29, 2018
1 parent 7355299 commit bffd341
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import (
)

const (
// defaultTLP is Green because indicators reaching telegram servers
// defaultTLP is Green because indicators reaching telegram servers.
// Same for defaultPAP
// TODO: think about making it configurable
defaultTLP = 1
defaultPAP = 1
boltFileName = "bolt.db"
bucket = "users"
tgTokenEnvName = "TGBOT_API_TOKEN"
Expand Down Expand Up @@ -52,7 +54,7 @@ type Client struct {
Password string
DB *bolt.DB
UsersBucket string
TLP int
TLP, PAP int
Timeout time.Duration
Debug bool
}
Expand Down Expand Up @@ -165,6 +167,7 @@ func NewClient() *Client {
DB: db,
UsersBucket: bucket,
TLP: defaultTLP,
PAP: defaultPAP,
Timeout: timeout,
Debug: debug,
}
Expand Down
10 changes: 6 additions & 4 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ func (c *Client) processCallback(callback *tgbotapi.CallbackQuery) error {
return err
}

j, err = newFileArtifactFromURL(link, callback.Message.ReplyToMessage.Document.FileName, c.TLP, c.Bot.Client)
j, err = newFileArtifactFromURL(link, callback.Message.ReplyToMessage.Document.FileName, c.TLP, c.PAP, c.Bot.Client)
if err != nil {
log.Println(err.Error())
return err
}
} else {
j = newArtifact(callback.Message.ReplyToMessage.Text, c.TLP)
j = newArtifact(callback.Message.ReplyToMessage.Text, c.TLP, c.PAP)
}

switch callback.Data {
Expand Down Expand Up @@ -189,11 +189,12 @@ func buildTaxonomies(txs []cortex.Taxonomy) string {
}

// newArtifact makes an Artifact depends on its type
func newArtifact(s string, tlp int) cortex.Observable {
func newArtifact(s string, tlp, pap int) cortex.Observable {
return &cortex.Task{
Data: s,
DataType: dataType(s),
TLP: &tlp,
PAP: &pap,
}
}

Expand All @@ -216,7 +217,7 @@ func dataType(d string) (t string) {
}

// newFileArtifactFromURL makes a FileArtifact from URL
func newFileArtifactFromURL(link string, fname string, tlp int, client *http.Client) (cortex.Observable, error) {
func newFileArtifactFromURL(link, fname string, tlp, pap int, client *http.Client) (cortex.Observable, error) {
req, err := http.NewRequest("GET", link, nil)
if err != nil {
return nil, err
Expand All @@ -231,6 +232,7 @@ func newFileArtifactFromURL(link string, fname string, tlp int, client *http.Cli
FileTaskMeta: cortex.FileTaskMeta{
DataType: "file",
TLP: &tlp,
PAP: &pap,
},
FileName: fname,
Reader: resp.Body,
Expand Down

0 comments on commit bffd341

Please sign in to comment.