Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f978d98252 |
@@ -2,6 +2,7 @@ package runtime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
cmap "github.com/orcaman/concurrent-map"
|
cmap "github.com/orcaman/concurrent-map"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,6 +21,8 @@ type ResettableFunctionTicker struct {
|
|||||||
duration time.Duration
|
duration time.Duration
|
||||||
Started bool
|
Started bool
|
||||||
name string
|
name string
|
||||||
|
Quit chan struct{}
|
||||||
|
Wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
type ResettableFunctionTickerOption func(*ResettableFunctionTicker)
|
type ResettableFunctionTickerOption func(*ResettableFunctionTicker)
|
||||||
|
|
||||||
@@ -28,11 +31,11 @@ func WithDuration(d time.Duration) ResettableFunctionTickerOption {
|
|||||||
a.duration = d
|
a.duration = d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveTicker(name string) {
|
func RemoveTicker(name string) {
|
||||||
tickerMap.Remove(name)
|
tickerMap.Remove(name)
|
||||||
}
|
}
|
||||||
func GetTicker(name string, option ...ResettableFunctionTickerOption) *ResettableFunctionTicker {
|
func GetTicker(name string, option ...ResettableFunctionTickerOption) *ResettableFunctionTicker {
|
||||||
|
|
||||||
if t, ok := tickerMap.Get(name); ok {
|
if t, ok := tickerMap.Get(name); ok {
|
||||||
return t.(*ResettableFunctionTicker)
|
return t.(*ResettableFunctionTicker)
|
||||||
} else {
|
} else {
|
||||||
@@ -44,6 +47,8 @@ func GetTicker(name string, option ...ResettableFunctionTickerOption) *Resettabl
|
|||||||
func NewResettableFunctionTicker(name string, option ...ResettableFunctionTickerOption) *ResettableFunctionTicker {
|
func NewResettableFunctionTicker(name string, option ...ResettableFunctionTickerOption) *ResettableFunctionTicker {
|
||||||
t := &ResettableFunctionTicker{
|
t := &ResettableFunctionTicker{
|
||||||
ResetChan: make(chan struct{}, 1),
|
ResetChan: make(chan struct{}, 1),
|
||||||
|
Quit: make(chan struct{}, 1),
|
||||||
|
Wg: sync.WaitGroup{},
|
||||||
name: name,
|
name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,12 +62,20 @@ func NewResettableFunctionTicker(name string, option ...ResettableFunctionTicker
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *ResettableFunctionTicker) DoWait(f func()) {
|
||||||
|
t.Do(f)
|
||||||
|
t.Wg.Wait()
|
||||||
|
}
|
||||||
func (t *ResettableFunctionTicker) Do(f func()) {
|
func (t *ResettableFunctionTicker) Do(f func()) {
|
||||||
t.Started = true
|
t.Started = true
|
||||||
tickerMap.Set(t.name, t)
|
tickerMap.Set(t.name, t)
|
||||||
|
t.Wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
defer t.Wg.Done()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
case <-t.Quit:
|
||||||
|
return
|
||||||
case <-t.Ticker.C:
|
case <-t.Ticker.C:
|
||||||
// ticker delivered signal. do function f
|
// ticker delivered signal. do function f
|
||||||
f()
|
f()
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
inlineFaucetMenu = &tb.ReplyMarkup{ResizeReplyKeyboard: true}
|
inlineFaucetMenu = &tb.ReplyMarkup{ResizeReplyKeyboard: true}
|
||||||
btnCancelInlineFaucet = inlineFaucetMenu.Data("🚫 Cancel", "cancel_faucet_inline")
|
btnCancelInlineFaucet = inlineFaucetMenu.Data("🚫 Cancel", "cancel_faucet_inline")
|
||||||
btnAcceptInlineFaucet = inlineFaucetMenu.Data("✅ Collect", "confirm_faucet_inline")
|
btnAcceptInlineFaucet = inlineFaucetMenu.Data("✅ Start", "confirm_faucet_inline")
|
||||||
)
|
)
|
||||||
|
|
||||||
type InlineFaucet struct {
|
type InlineFaucet struct {
|
||||||
|
|||||||
@@ -248,6 +248,22 @@ func (bot TipBot) getHandler() []Handler {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Endpoints: []interface{}{"/volcano"},
|
||||||
|
Handler: bot.volcanoHandler,
|
||||||
|
Interceptor: &Interceptor{
|
||||||
|
Type: MessageInterceptor,
|
||||||
|
Before: []intercept.Func{
|
||||||
|
bot.localizerInterceptor,
|
||||||
|
bot.logMessageInterceptor,
|
||||||
|
bot.requireUserInterceptor,
|
||||||
|
bot.lockInterceptor,
|
||||||
|
},
|
||||||
|
OnDefer: []intercept.Func{
|
||||||
|
bot.unlockInterceptor,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Endpoints: []interface{}{"/tipjar", "/spendendose"},
|
Endpoints: []interface{}{"/tipjar", "/spendendose"},
|
||||||
Handler: bot.tipjarHandler,
|
Handler: bot.tipjarHandler,
|
||||||
@@ -543,6 +559,37 @@ func (bot TipBot) getHandler() []Handler {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Endpoints: []interface{}{&btnAcceptInlineVolcano},
|
||||||
|
Handler: bot.acceptInlineVolcanoHandler,
|
||||||
|
Interceptor: &Interceptor{
|
||||||
|
Type: CallbackInterceptor,
|
||||||
|
Before: []intercept.Func{
|
||||||
|
//bot.singletonCallbackInterceptor,
|
||||||
|
bot.localizerInterceptor,
|
||||||
|
bot.loadUserInterceptor,
|
||||||
|
bot.lockInterceptor,
|
||||||
|
},
|
||||||
|
OnDefer: []intercept.Func{
|
||||||
|
bot.unlockInterceptor,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Endpoints: []interface{}{&btnCancelInlineVolcano},
|
||||||
|
Handler: bot.cancelInlineVolcanoHandler,
|
||||||
|
Interceptor: &Interceptor{
|
||||||
|
Type: CallbackInterceptor,
|
||||||
|
Before: []intercept.Func{
|
||||||
|
bot.localizerInterceptor,
|
||||||
|
bot.requireUserInterceptor,
|
||||||
|
bot.lockInterceptor,
|
||||||
|
},
|
||||||
|
OnDefer: []intercept.Func{
|
||||||
|
bot.unlockInterceptor,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Endpoints: []interface{}{&btnAcceptInlineFaucet},
|
Endpoints: []interface{}{&btnAcceptInlineFaucet},
|
||||||
Handler: bot.acceptInlineFaucetHandler,
|
Handler: bot.acceptInlineFaucetHandler,
|
||||||
|
|||||||
@@ -146,6 +146,9 @@ func (bot TipBot) anyQueryHandler(ctx context.Context, q *tb.Query) {
|
|||||||
if strings.HasPrefix(q.Text, "send") || strings.HasPrefix(q.Text, "pay") {
|
if strings.HasPrefix(q.Text, "send") || strings.HasPrefix(q.Text, "pay") {
|
||||||
bot.handleInlineSendQuery(ctx, q)
|
bot.handleInlineSendQuery(ctx, q)
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(q.Text, "volcano") {
|
||||||
|
//bot.handleInlineVolcanoQuery(ctx, q)
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(q.Text, "faucet") || strings.HasPrefix(q.Text, "zapfhahn") || strings.HasPrefix(q.Text, "kraan") || strings.HasPrefix(q.Text, "grifo") {
|
if strings.HasPrefix(q.Text, "faucet") || strings.HasPrefix(q.Text, "zapfhahn") || strings.HasPrefix(q.Text, "kraan") || strings.HasPrefix(q.Text, "grifo") {
|
||||||
if len(strings.Split(q.Text, " ")) > 1 {
|
if len(strings.Split(q.Text, " ")) > 1 {
|
||||||
|
|||||||
Reference in New Issue
Block a user