mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-19 13:18:12 +02:00
volcano initial commit
This commit is contained in:
parent
25dc9d7b34
commit
f978d98252
4 changed files with 65 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ package runtime
|
|||
|
||||
import (
|
||||
cmap "github.com/orcaman/concurrent-map"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -20,6 +21,8 @@ type ResettableFunctionTicker struct {
|
|||
duration time.Duration
|
||||
Started bool
|
||||
name string
|
||||
Quit chan struct{}
|
||||
Wg sync.WaitGroup
|
||||
}
|
||||
type ResettableFunctionTickerOption func(*ResettableFunctionTicker)
|
||||
|
||||
|
|
@ -28,11 +31,11 @@ func WithDuration(d time.Duration) ResettableFunctionTickerOption {
|
|||
a.duration = d
|
||||
}
|
||||
}
|
||||
|
||||
func RemoveTicker(name string) {
|
||||
tickerMap.Remove(name)
|
||||
}
|
||||
func GetTicker(name string, option ...ResettableFunctionTickerOption) *ResettableFunctionTicker {
|
||||
|
||||
if t, ok := tickerMap.Get(name); ok {
|
||||
return t.(*ResettableFunctionTicker)
|
||||
} else {
|
||||
|
|
@ -44,6 +47,8 @@ func GetTicker(name string, option ...ResettableFunctionTickerOption) *Resettabl
|
|||
func NewResettableFunctionTicker(name string, option ...ResettableFunctionTickerOption) *ResettableFunctionTicker {
|
||||
t := &ResettableFunctionTicker{
|
||||
ResetChan: make(chan struct{}, 1),
|
||||
Quit: make(chan struct{}, 1),
|
||||
Wg: sync.WaitGroup{},
|
||||
name: name,
|
||||
}
|
||||
|
||||
|
|
@ -57,12 +62,20 @@ func NewResettableFunctionTicker(name string, option ...ResettableFunctionTicker
|
|||
return t
|
||||
}
|
||||
|
||||
func (t *ResettableFunctionTicker) DoWait(f func()) {
|
||||
t.Do(f)
|
||||
t.Wg.Wait()
|
||||
}
|
||||
func (t *ResettableFunctionTicker) Do(f func()) {
|
||||
t.Started = true
|
||||
tickerMap.Set(t.name, t)
|
||||
t.Wg.Add(1)
|
||||
go func() {
|
||||
defer t.Wg.Done()
|
||||
for {
|
||||
select {
|
||||
case <-t.Quit:
|
||||
return
|
||||
case <-t.Ticker.C:
|
||||
// ticker delivered signal. do function f
|
||||
f()
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import (
|
|||
var (
|
||||
inlineFaucetMenu = &tb.ReplyMarkup{ResizeReplyKeyboard: true}
|
||||
btnCancelInlineFaucet = inlineFaucetMenu.Data("🚫 Cancel", "cancel_faucet_inline")
|
||||
btnAcceptInlineFaucet = inlineFaucetMenu.Data("✅ Collect", "confirm_faucet_inline")
|
||||
btnAcceptInlineFaucet = inlineFaucetMenu.Data("✅ Start", "confirm_faucet_inline")
|
||||
)
|
||||
|
||||
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"},
|
||||
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},
|
||||
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") {
|
||||
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 len(strings.Split(q.Text, " ")) > 1 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue