-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
347 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,225 @@ | ||
package teletest | ||
|
||
import ( | ||
"time" | ||
|
||
tele "gopkg.in/telebot.v3" | ||
) | ||
|
||
type Context struct { | ||
nc tele.Context | ||
|
||
reply Response | ||
} | ||
|
||
func (c *Context) Bot() *tele.Bot { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Update() tele.Update { | ||
return c.nc.Update() | ||
} | ||
|
||
func (c *Context) Message() *tele.Message { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Callback() *tele.Callback { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Query() *tele.Query { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) InlineResult() *tele.InlineResult { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) ShippingQuery() *tele.ShippingQuery { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) PreCheckoutQuery() *tele.PreCheckoutQuery { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Poll() *tele.Poll { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) PollAnswer() *tele.PollAnswer { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) ChatMember() *tele.ChatMemberUpdate { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) ChatJoinRequest() *tele.ChatJoinRequest { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Migration() (int64, int64) { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Topic() *tele.Topic { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Boost() *tele.BoostUpdated { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) BoostRemoved() *tele.BoostRemoved { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Sender() *tele.User { | ||
return c.nc.Sender() | ||
} | ||
|
||
func (c *Context) Chat() *tele.Chat { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Recipient() tele.Recipient { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Text() string { | ||
return c.nc.Text() | ||
} | ||
|
||
func (c *Context) Entities() tele.Entities { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Data() string { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Args() []string { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Send(what interface{}, opts ...interface{}) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) SendAlbum(a tele.Album, opts ...interface{}) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Reply(what interface{}, opts ...interface{}) error { | ||
c.reply = Response{what, opts} | ||
return nil | ||
} | ||
|
||
func (c *Context) Forward(msg tele.Editable, opts ...interface{}) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) ForwardTo(to tele.Recipient, opts ...interface{}) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Edit(what interface{}, opts ...interface{}) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) EditCaption(caption string, opts ...interface{}) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) EditOrSend(what interface{}, opts ...interface{}) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) EditOrReply(what interface{}, opts ...interface{}) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Delete() error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) DeleteAfter(d time.Duration) *time.Timer { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Notify(action tele.ChatAction) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Ship(what ...interface{}) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Accept(errorMessage ...string) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Answer(resp *tele.QueryResponse) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Respond(resp ...*tele.CallbackResponse) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) RespondText(text string) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) RespondAlert(text string) error { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Get(key string) interface{} { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (c *Context) Set(key string, val interface{}) { | ||
//TODO implement me | ||
panic("implement me") | ||
} |
This file contains 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,32 @@ | ||
package example | ||
|
||
import ( | ||
tele "gopkg.in/telebot.v3" | ||
) | ||
|
||
var users = make(map[int64]bool) | ||
|
||
func NewBot() (*tele.Bot, error) { | ||
pref := tele.Settings{ | ||
Synchronous: true, | ||
Offline: true, | ||
} | ||
|
||
b, err := tele.NewBot(pref) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
b.Handle("/start", func(c tele.Context) error { | ||
id := c.Sender().ID | ||
if !users[id] { | ||
users[id] = true | ||
} | ||
return c.Reply("Hello!") | ||
}) | ||
b.Handle(tele.OnText, func(c tele.Context) error { | ||
return c.Reply(c.Text()) | ||
}) | ||
|
||
return b, nil | ||
} |
This file contains 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,35 @@ | ||
package example | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
tele "gopkg.in/telebot.v3" | ||
"gopkg.in/telebot.v3/teletest" | ||
) | ||
|
||
var b, _ = NewBot() | ||
|
||
func TestBot(t *testing.T) { | ||
r, expect := teletest.New(b) | ||
|
||
r.Trigger(tele.Update{ | ||
Message: &tele.Message{ | ||
Sender: &tele.User{ID: 1}, | ||
Text: "/start", | ||
}, | ||
}) | ||
|
||
expect.Reply(t, "Hello!") | ||
require.Contains(t, users, int64(1)) | ||
|
||
r.Trigger(tele.Update{ | ||
Message: &tele.Message{ | ||
Sender: &tele.User{ID: 1}, | ||
Text: "echo", | ||
}, | ||
}) | ||
|
||
expect.Reply(t, "echo") | ||
} |
This file contains 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,31 @@ | ||
package teletest | ||
|
||
import ( | ||
"testing" | ||
|
||
tele "gopkg.in/telebot.v3" | ||
) | ||
|
||
type Recorder struct { | ||
b *tele.Bot | ||
e *Expect | ||
} | ||
|
||
func New(b *tele.Bot) (*Recorder, *Expect) { | ||
r := &Recorder{b: b, e: &Expect{}} | ||
return r, r.e | ||
} | ||
|
||
func (r *Recorder) Trigger(u tele.Update) { | ||
c := &Context{nc: r.b.NewContext(u)} | ||
r.b.ProcessContext(c) | ||
*r.e = Expect{c: c} | ||
} | ||
|
||
type Expect struct { | ||
c *Context | ||
} | ||
|
||
func (e Expect) Reply(t *testing.T, what interface{}, opts ...interface{}) { | ||
e.c.reply.Expect(t, what, opts) | ||
} |
This file contains 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,17 @@ | ||
package teletest | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type Response struct { | ||
what interface{} | ||
opts []interface{} | ||
} | ||
|
||
func (r Response) Expect(t *testing.T, what interface{}, opts []interface{}) { | ||
assert.Equal(t, what, r.what) | ||
assert.Equal(t, opts, r.opts) | ||
} |
This file contains 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