Documentation ¶
Overview ¶
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
SPDX-License-Identifier: GPL-2.0
Index ¶
- Constants
- Variables
- func CronGetChatAdmins(j *Job) (interface{}, error)
- func FanOutProcessJobs(job *Job, jobsFn []ProcessJobFn) ([]interface{}, []error)
- func JobAdDetector(j *Job) (interface{}, error)
- func JobLeftParticipantDetector(j *Job) (interface{}, error)
- func JobMsgStats(j *Job) (interface{}, error)
- func JobNewChatMemberAuth(j *Job) (interface{}, error)
- func JobNewChatMemberDetector(j *Job) (interface{}, error)
- func JobSentimentDetector(j *Job) (interface{}, error)
- func JobUrlDuplicationDetector(j *Job) (interface{}, error)
- type App
- type AppError
- type BotAnswerCallbackQuery
- type BotDeleteMsg
- type BotForceReply
- type BotGetAdmins
- type BotInReq
- type BotInReqMsg
- type BotInResp
- type BotInResp2
- type BotInRespMult
- type BotKickChatMember
- type BotSendMsg
- type CallbackQuery
- type Chat
- type InlineKeyboardButton
- type InlineKeyboardMarkup
- type Job
- func (j *Job) DeleteMessage(resp *BotInReqMsg) (interface{}, error)
- func (j *Job) GetBatchFromRedis(redisConn *redis.Client, k string, limit int) interface{}
- func (j *Job) HasMessageContent() bool
- func (j *Job) KickChatMember(userId int, username string) (interface{}, error)
- func (j *Job) SaveInRedis(redisConn *redis.Client, k string, v interface{}, t int)
- func (j *Job) SendMessage(replyText string, replyMsgId int) (*BotInReqMsg, error)
- func (j *Job) SendMessageWCleanup(text string, delay uint8, reply interface{}) (interface{}, error)
- func (j *Job) SendMessageWReply(replyText string, replyMsgId int, reply interface{}) (*BotInReqMsg, error)
- type KeyboardBtn
- type Message
- type ProcessJobFn
- type ReplyKeyboardMarkup
- type Sticker
- type User
- type UserMessageStats
Constants ¶
const ( FLOOD_TIME_INTERVAL = 10 FLOOD_MAX_ALLOWED_MSGS = 3 FLOOD_MAX_ALLOWED_WORDS = 500 CONT_MSGS_ALLOWED = 20 CONT_USER_MSG_ALLOWED = 3 )
const ( BDFL = "novitoll" TELEGRAM_BOT_USERNAME = "novitoll_daemon_bot" TIME_TO_DELETE_REPLY_MSG = 10 // 7 days - 1 sec EVERY_LAST_SEC_7TH_DAY = 604799 // 15 min NEWCOMER_URL_POST_DELAY = 900 )
Variables ¶
var ( GET = "GET" POST = "POST" TELEGRAM_URL = "https://api.telegram.org/bot%s/%s" TELEGRAM_TOKEN = "123" ParseModeMarkdown = "Markdown" ParseModeHTML = "HTML" )
var ( // TODO(novitoll): Move this to configuration file AD_WORDS = []string{"t.me/", "t.cn/", "joinchat"} // TODO(novitoll): Make a channel dependent EXCEPTIONS = []string{"t.me/proxy", "t.me/cyberseckz"} )
var ( // All these REDIS_* are Redis keys with following common // nested map: // { <chat-id>: { <user_id>: timestamp } } REDIS_USER_PENDING = "NewComersAuthPending" REDIS_USER_VERIFIED = "NewComersAuthVerified" REDIS_USER_KICKED = "NewComersAuthKicked" REDIS_USER_LEFT = "ParticipantLeft" REDIS_USER_PREV_LEFT = "ParticipantLeftPrev" REDIS_USER_PREV_KICK = "NewComersAuthKickedPrev" REDIS_USER_PREV_VERIFIED = "NewComersAuthVerifiedPrev" REDIS_USER_SENT_URL = "UserSentUrl" )
var ( // This global variable is referenced in cronjobs.go ChatIds = make(map[int]time.Time) )
var ( // we could store this map in Redis as well, // but once we have the record here, we have to // check Redis (open TCP connection) per each message // because we don't know beforehand if the message is // from the Auth pending user or not. So fuck it NewComersAuthPending = make(map[int]string) )
var (
SENTIMENTS = []string{")", ""}
)
var ( // Map to store user message statistics per chat_id // Data in the map is cleaned up when the CronJob executes // (every last second of 7th day) UserStatistics = make(map[int]map[int]*UserMessageStats) )
Functions ¶
func CronGetChatAdmins ¶
func FanOutProcessJobs ¶
func FanOutProcessJobs(job *Job, jobsFn []ProcessJobFn) ( []interface{}, []error)
func JobAdDetector ¶
func JobMsgStats ¶
func JobNewChatMemberAuth ¶
func JobSentimentDetector ¶
Types ¶
type App ¶
type App struct { Features *cfg.FeaturesCfg Lang string Logger *logrus.Logger ChatAdmins map[int][]string }
func (*App) FlushQueueHandler ¶
func (app *App) FlushQueueHandler(w http.ResponseWriter, r *http.Request)
func (*App) ProcessHandler ¶
func (app *App) ProcessHandler(w http.ResponseWriter, r *http.Request)
Receives HTTP requests on /process end-point from Telegram and after parsing request body raw bytes, "BotInReq" struct is created which contains sufficient info about Telegram Chat, User, Message. After struct's creation, Process() goroutine is scheduled and the HTTP request handler is completed with 200/OK response.
func (*App) RegisterHandlers ¶
func (app *App) RegisterHandlers()
func (*App) SendToTelegram ¶
func (app *App) SendToTelegram(body interface{}, method string) (*BotInReqMsg, error)
type BotAnswerCallbackQuery ¶
type BotAnswerCallbackQuery struct {
CallbackQueryId string `json:"callback_query_id"`
}
https://core.telegram.org/bots/api#answercallbackquery
func (*BotAnswerCallbackQuery) AnswerCallbackQuery ¶
func (body *BotAnswerCallbackQuery) AnswerCallbackQuery(app *App) (*BotInReqMsg, error)
type BotDeleteMsg ¶
https://core.telegram.org/bots/api#deletemessage
func (*BotDeleteMsg) DeleteMsg ¶
func (body *BotDeleteMsg) DeleteMsg(app *App) (*BotInReqMsg, error)
type BotForceReply ¶
type BotGetAdmins ¶
type BotGetAdmins struct {
ChatId int `json:"chat_id"`
}
https://core.telegram.org/bots/api#getchatadministrators
func (*BotGetAdmins) GetAdmins ¶
func (body *BotGetAdmins) GetAdmins(app *App) ([]*BotInReqMsg, error)
This is the same wrapper as above struct functions, but its response and request parsing are different, so have to duplicate the code without ready func. wrappers
type BotInReq ¶
type BotInReq struct { Update_Id int `json:"update_id"` Message BotInReqMsg CallbackQuery CallbackQuery `json:"callback_query"` }
func (*BotInReq) CronSchedule ¶
type BotInReqMsg ¶
type BotInReqMsg struct { From User Text string `json:"text"` Entities []Message Date int64 `json:"date"` // time.Unix() MessageId int `json:"message_id"` Chat Chat `json:"chat"` NewChatMembers []User `json:"new_chat_members"` NewChatMember User `json:"new_chat_member"` NewChatParticipant User `json:"new_chat_participant"` LeftChatParticipant User `json:"left_chat_participant"` Sticker Sticker `json:"sticker"` Caption string `json:"caption"` }
type BotInResp ¶
type BotInResp struct { Ok bool `json:"ok"` Result BotInReqMsg `json:"result"` ErrorCode int `json:"error_code"` Description string `json:"description"` }
type BotInResp2 ¶
type BotInRespMult ¶
type BotInRespMult struct { Ok bool `json:"ok"` Result []*BotInReqMsg `json:"result"` ErrorCode int `json:"error_code"` Description string `json:"description"` }
type BotKickChatMember ¶
type BotKickChatMember struct { ChatId int `json:"chat_id"` UserId int `json:"user_id"` UntilDate int64 `json:"until_date"` }
https://core.telegram.org/bots/api#kickchatmember
func (*BotKickChatMember) KickChatMember ¶
func (body *BotKickChatMember) KickChatMember(app *App) (*BotInReqMsg, error)
type BotSendMsg ¶
type BotSendMsg struct { ChatId int `json:"chat_id"` Text string `json:"text"` ParseMode string `json:"parse_mode"` ReplyToMessageId int `json:"reply_to_message_id"` ReplyMarkup interface{} `json:"reply_markup"` }
https://core.telegram.org/bots/api#sendmessage
func (*BotSendMsg) SendMsg ¶
func (body *BotSendMsg) SendMsg(app *App) (*BotInReqMsg, error)
type CallbackQuery ¶
type InlineKeyboardButton ¶
type InlineKeyboardMarkup ¶
type InlineKeyboardMarkup struct {
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
}
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
func (*Job) DeleteMessage ¶
func (j *Job) DeleteMessage(resp *BotInReqMsg) (interface{}, error)
func (*Job) GetBatchFromRedis ¶
func (*Job) HasMessageContent ¶
func (*Job) KickChatMember ¶
func (*Job) SaveInRedis ¶
func (*Job) SendMessage ¶
func (j *Job) SendMessage(replyText string, replyMsgId int) (*BotInReqMsg, error)
func (*Job) SendMessageWCleanup ¶
func (*Job) SendMessageWReply ¶
func (j *Job) SendMessageWReply(replyText string, replyMsgId int, reply interface{}) (*BotInReqMsg, error)
type KeyboardBtn ¶
type KeyboardBtn struct {
Text string `json:"text"`
}
type Message ¶
type ProcessJobFn ¶
type ReplyKeyboardMarkup ¶
type ReplyKeyboardMarkup struct { Keyboard [][]KeyboardBtn `json:"keyboard"` OneTimeKeyboard bool `json:"one_time_keyboard"` Selective bool `json:"selective"` }
Source Files ¶
- app.go
- app_error.go
- concurrent_fanout_jobs.go
- cronjobs.go
- egress_request_actions.go
- egress_request_entity.go
- ingress_request_actions.go
- ingress_request_entity.go
- job_ad_detector.go
- job_chatmember_operate.go
- job_entity.go
- job_sentiment_detector.go
- job_statistics.go
- job_url_duplication_detector.go
- vars.go