bots

package module
v0.0.0-...-177ba30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2018 License: MIT Imports: 19 Imported by: 0

README

yegle-bots

Some Telegram bots

Yet-Another Hacker News Channel

Documentation

Index

Constants

View Source
const BatchSize = 30

BatchSize is the number of top stories to fetch from Hacker News.

View Source
const DefaultChatID = `@yahnc`

DefaultChatID is the default chat ID.

View Source
const DefaultTimeout = 9 * time.Minute

DefaultTimeout is the default URLFetch timeout.

View Source
const Hot = "🔥"

Hot is the sign for a hot story, either because it has high score or it has large number of discussions.

View Source
const NumCommentsThreshold = 5

NumCommentsThreshold is the threshold for number of comments. Story with less than this threshold will not be posted in the channel.

View Source
const ScoreThreshold = 50

ScoreThreshold is the threshold for the score. Story with less than this threshold will not be posted in the channel.

View Source
const TelegramAPIBase = `https://api.telegram.org/`

TelegramAPIBase is the API base of telegram API.

Variables

View Source
var ErrIgnoredItem = errors.New("item ignored")

ErrIgnoredItem is returned when the story should be ignored.

Functions

func GetKey

func GetKey(ctx context.Context, i int64) *datastore.Key

GetKey get a datastore key for the given item ID.

func GetTopStoryURL

func GetTopStoryURL() string

GetTopStoryURL is a helper function to get the

func ItemURL

func ItemURL(id int64) string

ItemURL is a helper function to get the API of an item.

func NewsURL

func NewsURL(id int64) string

NewsURL is a helper function to get the URL to the story's HackerNews page.

func TelegramAPI

func TelegramAPI(method string) string

TelegramAPI is a helper function to get the Telegram API endpoint.

Types

type DeleteMessageRequest

type DeleteMessageRequest struct {
	ChatID    string `json:"chat_id"`
	MessageID int64  `json:"message_id"`
}

DeleteMessageRequest is the request to deleteMessage method.

type DeleteMessageResponse

type DeleteMessageResponse struct {
	OK          bool   `json:"ok"`
	ErrorCode   int64  `json:"error_code"`
	Description string `json:"description"`
}

DeleteMessageResponse is the response to deleteMessage method.

func (*DeleteMessageResponse) ShouldIgnoreError

func (r *DeleteMessageResponse) ShouldIgnoreError() bool

ShouldIgnoreError return true if the message contains an error but should be ignored.

type EditMessageTextRequest

type EditMessageTextRequest struct {
	ChatID      string               `json:"chat_id"`
	MessageID   int64                `json:"message_id"`
	Text        string               `json:"text"`
	ParseMode   string               `json:"parse_mode,omitempty"`
	ReplyMarkup InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}

EditMessageTextRequest is the request to editMessageText method.

type InlineKeyboardButton

type InlineKeyboardButton struct {
	Text string `json:"text,omitempty"`
	URL  string `json:"url,omitempty"`
}

InlineKeyboardButton type.

type InlineKeyboardMarkup

type InlineKeyboardMarkup struct {
	InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard,omitempty"`
}

InlineKeyboardMarkup type.

type IntSet

type IntSet map[int64]struct{}

IntSet is an int64 set type.

func (IntSet) Add

func (set IntSet) Add(i int64) bool

Add add an int64 number to the set. Return false if the number already exists in the set.

func (IntSet) AddAll

func (set IntSet) AddAll(xs []int64)

AddAll add a slice of ints to the set.

func (IntSet) Max

func (set IntSet) Max() int64

Max returns the max number in the set. O(n).

func (IntSet) Min

func (set IntSet) Min() int64

Min returns the min number in the set. O(n).

type Result

type Result struct {
	MessageID int64 `json:"message_id"`
}

Result is a submessage in SendMessageResponse. We only care the MessageID for now.

type SendMessageRequest

type SendMessageRequest struct {
	ChatID              string               `json:"chat_id"`
	Text                string               `json:"text"`
	ParseMode           string               `json:"parse_mode,omitempty"`
	ReplyMarkup         InlineKeyboardMarkup `json:"reply_markup,omitempty"`
	DisableNotification bool                 `json:"disable_notification,omitempty"`
}

SendMessageRequest is a struct that maps to a sendMessage request.

type SendMessageResponse

type SendMessageResponse struct {
	OK     bool   `json:"ok"`
	Result Result `json:"result"`
}

SendMessageResponse is the response from sendMessage request.

type Story

type Story struct {
	ID          int64     `json:"id"`
	URL         string    `json:"url"`
	Title       string    `json:"title"`
	Descendants int64     `json:"descendants"`
	Score       int64     `json:"score"`
	MessageID   int64     `json:"-"`
	LastSave    time.Time `json:"-"`
	Type        string    `json:"type"`
	// contains filtered or unexported fields
}

Story is a struct represents an item stored in datastore. Part of the fields will be saved to datastore.

func NewFromDatastore

func NewFromDatastore(ctx context.Context, id int64) (Story, error)

NewFromDatastore create a Story from datastore.

func (*Story) DeleteMessage

func (s *Story) DeleteMessage(ctx context.Context) error

DeleteMessage delete a message from telegram Channel and from channel.

func (*Story) EditMessage

func (s *Story) EditMessage(ctx context.Context) error

EditMessage send a request to edit a message.

func (*Story) FillMissingFields

func (s *Story) FillMissingFields(ctx context.Context) error

FillMissingFields is used to fill the missing story data from HN API.

func (*Story) GetReplyMarkup

func (s *Story) GetReplyMarkup() InlineKeyboardMarkup

GetReplyMarkup will return the markup for the story.

func (*Story) InDatastore

func (s *Story) InDatastore(ctx context.Context) bool

InDatastore checks if the story is already in datastore.

func (*Story) Load

func (s *Story) Load(ps []datastore.Property) error

Load implements the PropertyLoadSaver interface.

func (*Story) Save

func (s *Story) Save() ([]datastore.Property, error)

Save implements the PropertyLoadSaver interface.

func (*Story) SendMessage

func (s *Story) SendMessage(ctx context.Context) error

SendMessage send a request to send a new message.

func (*Story) ShouldIgnore

func (s *Story) ShouldIgnore() bool

ShouldIgnore is a filter for story.

func (*Story) ToDeleteMessageRequest

func (s *Story) ToDeleteMessageRequest() DeleteMessageRequest

ToDeleteMessageRequest returns a DeleteMessageRequest.

func (*Story) ToEditMessageTextRequest

func (s *Story) ToEditMessageTextRequest() EditMessageTextRequest

ToEditMessageTextRequest will return a new EditMessageTextRequest object

func (*Story) ToSendMessageRequest

func (s *Story) ToSendMessageRequest() SendMessageRequest

ToSendMessageRequest will return a new SendMessageRequest object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL