36 lines
937 B
Go
36 lines
937 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
type JobChan chan int // receives project IDs
|
||
|
type NextChan chan int64 // receives user IDs for whoever clicks the next button
|
||
|
|
||
|
func (ctx *Context) waitForNext(userID int64) {
|
||
|
for n := range ctx.Next {
|
||
|
if n == userID || n == ctx.Settings.Admin {
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
func (ctx *Context) listenJobChannel() {
|
||
|
for jobID := range ctx.Queue {
|
||
|
|
||
|
job := ctx.Projects[jobID]
|
||
|
msgID := ctx.sendMessage(job.User, "🐾 <b>Your image is being printed!</b> Don't forget to <u>click the button below once you've cut your sticker off the roll</u>.", getNextKeyboard())
|
||
|
|
||
|
err := ctx.Client.Print(job.Og, job.Options, false)
|
||
|
if err != nil {
|
||
|
log.Println("Error printing image", err.Error())
|
||
|
ctx.sendMessage(job.User, "❗️ Got an error printing image, try again")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ctx.waitForNext(job.User)
|
||
|
ctx.editMessage(job.User, msgID, "🤗 All done, thanks!")
|
||
|
ctx.Projects[jobID] = nil
|
||
|
|
||
|
}
|
||
|
}
|