-
Notifications
You must be signed in to change notification settings - Fork 14
add parser for URL that returns image #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ronaudinho
wants to merge
2
commits into
eFishery:master
Choose a base branch
from
ronaudinho:parse-image
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,46 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "image" | ||
| "image/color" | ||
| "image/draw" | ||
| "image/jpeg" | ||
| "net/http" | ||
| "strconv" | ||
| ) | ||
|
|
||
| var ( | ||
| testTextURL1 = "/text/1" | ||
| testTextURL2 = "/text/2" | ||
| testTextURL3 = "/text/3" | ||
| testImageURL1 = "/image/1" | ||
| ) | ||
|
|
||
| // sets up required value here | ||
| func main() { | ||
| http.HandleFunc(testTextURL1, func(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("Content-Type", "application/json") | ||
| w.Write(json.RawMessage(`{"message": "1"}`)) | ||
| }) | ||
| http.HandleFunc(testTextURL2, func(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("Content-Type", "application/json") | ||
| w.Write(json.RawMessage(`{"massage": "2"}`)) | ||
| }) | ||
| http.HandleFunc(testImageURL1, func(w http.ResponseWriter, r *http.Request) { | ||
| m := image.NewRGBA(image.Rect(0, 0, 240, 240)) | ||
| blue := color.RGBA{0, 0, 255, 255} | ||
| draw.Draw(m, m.Bounds(), &image.Uniform{blue}, image.ZP, draw.Src) | ||
| buffer := new(bytes.Buffer) | ||
| err := jpeg.Encode(buffer, m, nil) | ||
| if err != nil { | ||
| return | ||
| } | ||
| w.Header().Set("Content-Type", "image/jpeg") | ||
| w.Header().Set("Content-Length", strconv.Itoa(len(buffer.Bytes()))) | ||
| w.Write(buffer.Bytes()) | ||
| }) | ||
|
|
||
| http.ListenAndServe(":6969", nil) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,28 +1,27 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/gob" | ||
| "math/rand" | ||
| "os/signal" | ||
|
|
||
| "fmt" | ||
| "log" | ||
| "math/rand" | ||
| "os" | ||
| "time" | ||
| "os/signal" | ||
| "strings" | ||
| "syscall" | ||
| "time" | ||
|
|
||
| whatsapp "github.com/Rhymen/go-whatsapp" | ||
| cron "github.com/robfig/cron/v3" | ||
| godotenv "github.com/joho/godotenv" | ||
| cron "github.com/robfig/cron/v3" | ||
| // "github.com/davecgh/go-spew/spew" | ||
| ) | ||
|
|
||
| type waHandler struct { | ||
| c *whatsapp.Conn | ||
| startTime uint64 | ||
| chats map[string]struct{} | ||
|
|
||
| chats map[string]struct{} | ||
| } | ||
|
|
||
| var Schedules []Schedule | ||
|
|
@@ -34,9 +33,9 @@ var BuildCommands []BuildCommand | |
| var BuildGreetings []BuildGreeting | ||
|
|
||
| func init() { | ||
| if err := godotenv.Load(); err != nil { | ||
| log.Print("No .env file found") | ||
| } | ||
| if err := godotenv.Load(); err != nil { | ||
| log.Print("No .env file found") | ||
| } | ||
| } | ||
|
|
||
| func main() { | ||
|
|
@@ -79,20 +78,20 @@ func main() { | |
| if !pong || err != nil { | ||
| log.Fatalf("error pinging in: %v\n", err) | ||
| } | ||
|
|
||
| schedule := readScheduleFiles() | ||
| if !schedule { | ||
| log.Println("Can't read Schedule Files") | ||
| return | ||
| } | ||
|
|
||
| for index := range(Schedules) { | ||
| for index := range Schedules { | ||
| phone_numbers := Schedules[index].ExpectedUsers | ||
| process_name := Schedules[index].ProcessName | ||
| log.Println("Read the schedule to run with cron formula " + Schedules[index].Rule) | ||
| jadwal.AddFunc(Schedules[index].Rule, func(){ | ||
| jadwal.AddFunc(Schedules[index].Rule, func() { | ||
| log.Println("Run Schedule " + process_name) | ||
| for pIndex := range(phone_numbers) { | ||
| for pIndex := range phone_numbers { | ||
| go sendMessage(wac, Schedules[index].Message, phone_numbers[pIndex]) | ||
| } | ||
| }) | ||
|
|
@@ -118,7 +117,6 @@ func main() { | |
| } | ||
|
|
||
| func sendMessage(wac *whatsapp.Conn, message string, RJID string) { | ||
|
|
||
| msg := whatsapp.TextMessage{ | ||
| Info: whatsapp.MessageInfo{ | ||
| RemoteJid: RJID, | ||
|
|
@@ -135,13 +133,13 @@ func sendMessage(wac *whatsapp.Conn, message string, RJID string) { | |
| // if min is 2 then 2 + (50/2) = 27 | ||
| // if max is 4 then 4 + (50/2) = 29 | ||
| // if 29 > 5 then max is 5 | ||
| min = min + (len(kata)/2) | ||
| max = max + (len(kata)/2) | ||
| min = min + (len(kata) / 2) | ||
| max = max + (len(kata) / 2) | ||
| if max > limit_max { | ||
| min = limit_max - 2 | ||
| max = limit_max | ||
| } | ||
| waitSec := rand.Intn(max-min)+min | ||
| waitSec := rand.Intn(max-min) + min | ||
| log.Printf("Randomly paused %d for throtling", waitSec) | ||
| wac.Presence(RJID, whatsapp.PresenceComposing) | ||
| time.Sleep(time.Duration(waitSec) * time.Second) | ||
|
|
@@ -154,6 +152,26 @@ func sendMessage(wac *whatsapp.Conn, message string, RJID string) { | |
| } | ||
| } | ||
|
|
||
| func sendImageMessage(wac *whatsapp.Conn, img ImageMessage, RJID string) { | ||
| msg := whatsapp.ImageMessage{ | ||
| Info: whatsapp.MessageInfo{ | ||
| RemoteJid: RJID, | ||
| }, | ||
| Caption: img.Caption, | ||
| Thumbnail: img.Thumbnail, | ||
| Type: img.Type, | ||
| Content: bytes.NewReader(img.Content), | ||
| } | ||
|
|
||
| wac.Presence(RJID, whatsapp.PresenceComposing) | ||
| msgId, err := wac.Send(msg) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ronaudinho I have this kind of bug from another bot that I develop by sending image the I'm using this image https://miro.medium.com/max/356/1*EnF9uIN_u2_X7ey24lB7Tg.png |
||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "error sending message: %v", err) | ||
| } else { | ||
| fmt.Println("Message Sent -> ID : " + msgId) | ||
| } | ||
| } | ||
|
|
||
| func login(wac *whatsapp.Conn, phone_number string) error { | ||
| session, err := readSession(phone_number) | ||
| if err == nil { | ||
|
|
@@ -236,4 +254,4 @@ func (h *waHandler) HandleError(err error) { | |
| } else { | ||
| log.Printf("error occoured: %v\n", err) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ronaudinho this will be much better if the caption from the text
messagelike example if the
coralhavecommands messageso this will returned "Let's start how cool you are man"