Skip to content

Commit

Permalink
update deps and fix bot (#437)
Browse files Browse the repository at this point in the history
* fix: update a lot of functions

* fix: update dispatcher and updater

* fix: bot token in paste command

* fix: use type assertion

* fix: try forwardOrigin

* fix: add missing error loggin

* fix: make image runnable using docker compose

* fix: app.json for heroku

* style: format code with Gofumpt

This commit fixes the style issues introduced in 47f8746 according to the output
from Gofumpt.

Details: #437

* fix: remove unused var

* fix: remove unused parameter

* fix: deepsource errors

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
Divkix and deepsource-autofix[bot] authored Jul 28, 2024
1 parent c9e945a commit b1889d4
Show file tree
Hide file tree
Showing 31 changed files with 614 additions and 362 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ dist/
# Executables
Alita_Robot
Alita_Robot.exe
*.env
.env
.db.env

# Mac OS DS_Store file
.DS_Store
6 changes: 3 additions & 3 deletions alita/db/lang_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
)

func GetLanguage(ctx *ext.Context) string {
var chat *gotgbot.Chat
var chat gotgbot.Chat
if ctx.CallbackQuery != nil {
chat = &ctx.CallbackQuery.Message.Chat
chat = ctx.CallbackQuery.Message.GetChat()
} else {
chat = &ctx.Update.Message.Chat
chat = ctx.Update.Message.Chat
}
// FIXME: this is a hack
// if ctx.Update.Message.Chat.Type == "private" || ctx.CallbackQuery.Message.Chat.Type == "private" {
Expand Down
9 changes: 6 additions & 3 deletions alita/modules/bans.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,14 +1126,17 @@ func (moduleStruct) unrestrictButtonHandler(b *gotgbot.Bot, ctx *ext.Context) er
)
}

// type assertion to get the message
_updatedMsg := msg.(*gotgbot.Message)

// only strikethrough if msg.Text is non-empty
if msg.Text != "" {
msg.Text = fmt.Sprint("<s>", msg.Text, "</s>", "\n\n")
if _updatedMsg.Text != "" {
_updatedMsg.Text = fmt.Sprint("<s>", _updatedMsg.Text, "</s>", "\n\n")
}

_, _, err := msg.EditText(
b,
fmt.Sprint(msg.Text, helpText),
fmt.Sprint(_updatedMsg.Text, helpText),
&gotgbot.EditMessageTextOpts{
ParseMode: helpers.HTML,
},
Expand Down
10 changes: 6 additions & 4 deletions alita/modules/blacklists.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ func (m moduleStruct) listBlacklists(b *gotgbot.Bot, ctx *ext.Context) error {
_, err := msg.Reply(b,
blacklistsText,
&gotgbot.SendMessageOpts{
ReplyToMessageId: replyMsgId,
AllowSendingWithoutReply: true,
ParseMode: helpers.HTML,
ReplyParameters: &gotgbot.ReplyParameters{
MessageId: replyMsgId,
AllowSendingWithoutReply: true,
},
ParseMode: helpers.HTML,
},
)
if err != nil {
Expand Down Expand Up @@ -341,7 +343,7 @@ func (m moduleStruct) buttonHandler(b *gotgbot.Bot, ctx *ext.Context) error {

switch creatorAction {
case "yes":
go db.RemoveAllBlacklist(query.Message.Chat.Id)
go db.RemoveAllBlacklist(query.Message.GetChat().Id)
helpText = tr.GetString("strings." + m.moduleName + ".rm_all_bl.button_handler.yes")
case "no":
helpText = tr.GetString("strings." + m.moduleName + ".rm_all_bl.button_handler.yes")
Expand Down
2 changes: 1 addition & 1 deletion alita/modules/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (m moduleStruct) reconnect(b *gotgbot.Bot, ctx *ext.Context) error {
return err
}

if !chat_status.IsUserInChat(b, gchat, user.Id) {
if !chat_status.IsUserInChat(b, gchat.PersonalChat, user.Id) {
return ext.EndGroups
}

Expand Down
12 changes: 7 additions & 5 deletions alita/modules/devs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (moduleStruct) chatInfo(b *gotgbot.Bot, ctx *ext.Context) error {
_, _ = msg.Reply(b, err.Error(), nil)
return ext.EndGroups
}
con, _ := chat.GetMemberCount(b, nil)
con, _ := chat.PersonalChat.GetMemberCount(b, nil)
replyText = fmt.Sprintf("<b>Name:</b> %s\n<b>Chat ID</b>: %d\n<b>Users Count:</b> %d\n<b>Link:</b> %s", chat.Title, chat.Id, con, chat.InviteLink)
}

Expand Down Expand Up @@ -112,11 +112,13 @@ func (moduleStruct) chatList(b *gotgbot.Bot, ctx *ext.Context) error {

_, err = b.SendDocument(
chat.Id,
openedFile,
gotgbot.InputFileByReader(fileName, openedFile),
&gotgbot.SendDocumentOpts{
Caption: "Here is the list of chats in my Database!",
ReplyToMessageId: msg.MessageId,
AllowSendingWithoutReply: true,
Caption: "Here is the list of chats in my Database!",
ReplyParameters: &gotgbot.ReplyParameters{
MessageId: msg.MessageId,
AllowSendingWithoutReply: true,
},
},
)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions alita/modules/disabling.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ func (moduleStruct) disabled(b *gotgbot.Bot, ctx *ext.Context) error {
_, err := msg.Reply(b,
"There are no disabled commands in this chat.",
&gotgbot.SendMessageOpts{
ReplyToMessageId: replyMsgId,
AllowSendingWithoutReply: true,
ReplyParameters: &gotgbot.ReplyParameters{
MessageId: replyMsgId,
AllowSendingWithoutReply: true,
},
},
)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions alita/modules/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ func (moduleStruct) filtersList(b *gotgbot.Bot, ctx *ext.Context) error {
_, err := msg.Reply(b,
info,
&gotgbot.SendMessageOpts{
ParseMode: helpers.HTML,
ReplyToMessageId: replyMsgId,
AllowSendingWithoutReply: true,
ParseMode: helpers.HTML,
ReplyParameters: &gotgbot.ReplyParameters{
MessageId: replyMsgId,
AllowSendingWithoutReply: true,
},
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion alita/modules/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (m moduleStruct) formattingHandler(b *gotgbot.Bot, ctx *ext.Context) error
_, _, err := msg.EditText(b,
m.getMarkdownHelp(module),
&gotgbot.EditMessageTextOpts{
MessageId: msg.MessageId,
MessageId: msg.GetMessageId(),
ReplyMarkup: gotgbot.InlineKeyboardMarkup{
InlineKeyboard: [][]gotgbot.InlineKeyboardButton{
{
Expand Down
58 changes: 37 additions & 21 deletions alita/modules/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ func (moduleStruct) about(b *gotgbot.Bot, ctx *ext.Context) error {
_, _, err := query.Message.EditText(b,
currText,
&gotgbot.EditMessageTextOpts{
ReplyMarkup: currKb,
DisableWebPagePreview: true,
ParseMode: helpers.HTML,
ReplyMarkup: currKb,
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: true,
},
ParseMode: helpers.HTML,
},
)
if err != nil {
Expand Down Expand Up @@ -220,9 +222,11 @@ func (moduleStruct) about(b *gotgbot.Bot, ctx *ext.Context) error {
b,
currText,
&gotgbot.SendMessageOpts{
ParseMode: helpers.HTML,
DisableWebPagePreview: true,
ReplyMarkup: &currKb,
ParseMode: helpers.HTML,
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: true,
},
ReplyMarkup: &currKb,
},
)
if err != nil {
Expand Down Expand Up @@ -267,9 +271,11 @@ func (moduleStruct) helpButtonHandler(b *gotgbot.Bot, ctx *ext.Context) error {
b,
helpText,
&gotgbot.EditMessageTextOpts{
ParseMode: _parsemode,
ReplyMarkup: replyKb,
DisableWebPagePreview: true,
ParseMode: _parsemode,
ReplyMarkup: replyKb,
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: true,
},
},
)
if err != nil {
Expand Down Expand Up @@ -297,9 +303,11 @@ func (moduleStruct) start(b *gotgbot.Bot, ctx *ext.Context) error {
_, err := msg.Reply(b,
startHelp,
&gotgbot.SendMessageOpts{
ParseMode: helpers.HTML,
DisableWebPagePreview: true,
ReplyMarkup: &startMarkup,
ParseMode: helpers.HTML,
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: true,
},
ReplyMarkup: &startMarkup,
},
)
if err != nil {
Expand Down Expand Up @@ -332,10 +340,14 @@ func (moduleStruct) donate(b *gotgbot.Bot, ctx *ext.Context) error {
_, err := b.SendMessage(chat.Id,
i18n.I18n{LangCode: "en"}.GetString("strings.Help.DonateText"),
&gotgbot.SendMessageOpts{
ParseMode: helpers.HTML,
DisableWebPagePreview: true,
ReplyToMessageId: msg.MessageId,
AllowSendingWithoutReply: true,
ParseMode: helpers.HTML,
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: true,
},
ReplyParameters: &gotgbot.ReplyParameters{
MessageId: msg.MessageId,
AllowSendingWithoutReply: true,
},
},
)
if err != nil {
Expand All @@ -350,7 +362,7 @@ func (moduleStruct) botConfig(b *gotgbot.Bot, ctx *ext.Context) error {
msg := query.Message

// just in case
if msg.Chat.Type != "private" {
if msg.GetChat().Type != "private" {
_, _, err := msg.EditText(b, "Configuration only works in private", nil)
if err != nil {
log.Error(err)
Expand Down Expand Up @@ -410,7 +422,9 @@ func (moduleStruct) botConfig(b *gotgbot.Bot, ctx *ext.Context) error {
b,
text,
&gotgbot.EditMessageTextOpts{
DisableWebPagePreview: true,
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: true,
},
ReplyMarkup: gotgbot.InlineKeyboardMarkup{
InlineKeyboard: iKeyboard,
},
Expand Down Expand Up @@ -491,9 +505,11 @@ func (moduleStruct) help(b *gotgbot.Bot, ctx *ext.Context) error {
_, err := msg.Reply(b,
moduleHelpString,
&gotgbot.SendMessageOpts{
ParseMode: helpers.HTML,
ReplyToMessageId: replyMsgId,
AllowSendingWithoutReply: true,
ParseMode: helpers.HTML,
ReplyParameters: &gotgbot.ReplyParameters{
MessageId: replyMsgId,
AllowSendingWithoutReply: true,
},
ReplyMarkup: gotgbot.InlineKeyboardMarkup{
InlineKeyboard: [][]gotgbot.InlineKeyboardButton{
{
Expand Down
24 changes: 15 additions & 9 deletions alita/modules/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func startHelpPrefixHandler(b *gotgbot.Bot, ctx *ext.Context, user *gotgbot.User
return ext.ContinueGroups
}
}
_, err := helpers.SendNote(b, chatinfo, ctx, noteData, msg.MessageId)
_, err := helpers.SendNote(b, chatinfo.PersonalChat, ctx, noteData, msg.MessageId)
if err != nil {
log.Error(err)
return err
Expand All @@ -255,11 +255,15 @@ func startHelpPrefixHandler(b *gotgbot.Bot, ctx *ext.Context, user *gotgbot.User
_, err := b.SendMessage(chat.Id,
aboutText,
&gotgbot.SendMessageOpts{
ParseMode: "Markdown",
DisableWebPagePreview: true,
ReplyToMessageId: msg.MessageId,
ReplyMarkup: &aboutKb,
AllowSendingWithoutReply: true,
ParseMode: "Markdown",
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: true,
},
ReplyParameters: &gotgbot.ReplyParameters{
MessageId: msg.MessageId,
AllowSendingWithoutReply: true,
},
ReplyMarkup: &aboutKb,
},
)
if err != nil {
Expand All @@ -271,9 +275,11 @@ func startHelpPrefixHandler(b *gotgbot.Bot, ctx *ext.Context, user *gotgbot.User
_, err := b.SendMessage(chat.Id,
startHelp,
&gotgbot.SendMessageOpts{
ParseMode: helpers.HTML,
DisableWebPagePreview: true,
ReplyMarkup: &startMarkup,
ParseMode: helpers.HTML,
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: true,
},
ReplyMarkup: &startMarkup,
},
)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions alita/modules/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (m moduleStruct) changeLanguage(b *gotgbot.Bot, ctx *ext.Context) error {

func (moduleStruct) langBtnHandler(b *gotgbot.Bot, ctx *ext.Context) error {
query := ctx.Update.CallbackQuery
chat := query.Message.Chat
chat := query.Message.GetChat()
user := query.From

var replyString string
Expand All @@ -90,8 +90,10 @@ func (moduleStruct) langBtnHandler(b *gotgbot.Bot, ctx *ext.Context) error {
b,
replyString,
&gotgbot.EditMessageTextOpts{
ParseMode: helpers.HTML,
DisableWebPagePreview: true,
ParseMode: helpers.HTML,
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: true,
},
},
)
if err != nil {
Expand Down
48 changes: 31 additions & 17 deletions alita/modules/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ func (moduleStruct) echomsg(b *gotgbot.Bot, ctx *ext.Context) error {
strings.Split(msg.OriginalHTML(), " ")[1:], " ",
),
&gotgbot.SendMessageOpts{
ReplyToMessageId: replyMsg.MessageId,
ParseMode: helpers.Shtml().ParseMode,
ReplyParameters: &gotgbot.ReplyParameters{
MessageId: replyMsg.MessageId,
},
ParseMode: helpers.Shtml().ParseMode,
},
)
if err != nil {
Expand Down Expand Up @@ -98,18 +100,28 @@ func (moduleStruct) getId(b *gotgbot.Bot, ctx *ext.Context) error {
originalId,
)
}
if msg.ReplyToMessage.ForwardFrom != nil {
user1Id := msg.ReplyToMessage.ForwardFrom.Id
_, user1Name, _ := extraction.GetUserInfo(user1Id)
replyText += fmt.Sprintf(
"<b>Forwarded from %s's ID:</b> <code>%d</code>\n",
user1Name, user1Id,
)
}
if msg.ReplyToMessage.ForwardFromChat != nil {
replyText += fmt.Sprintf("<b>Forwarded from chat %s's ID:</b> <code>%d</code>\n",
msg.ReplyToMessage.ForwardFromChat.Title, msg.ReplyToMessage.ForwardFromChat.Id,
)

if rpm := msg.ReplyToMessage; rpm != nil {
if frpm := rpm.ForwardOrigin; frpm != nil {
if frpm.GetDate() != 0 {
fwdd := frpm.MergeMessageOrigin()

if fwdc := fwdd.SenderUser; fwdc != nil {
user1Id := fwdc.Id
_, user1Name, _ := extraction.GetUserInfo(user1Id)
replyText += fmt.Sprintf(
"<b>Forwarded from %s's ID:</b> <code>%d</code>\n",
user1Name, user1Id,
)
}

if fwdc := fwdd.Chat; fwdc != nil {
replyText += fmt.Sprintf("<b>Forwarded from chat %s's ID:</b> <code>%d</code>\n",
fwdc.Title, fwdc.Id,
)
}
}
}
}
if msg.ReplyToMessage.Animation != nil {
replyText += fmt.Sprintf("<b>GIF ID:</b> <code>%s</code>\n",
Expand Down Expand Up @@ -199,7 +211,7 @@ func (moduleStruct) paste(b *gotgbot.Bot, ctx *ext.Context) error {
return ext.EndGroups
}
fileName := fmt.Sprintf("paste_%d_%d.txt", msg.Chat.Id, msg.MessageId)
raw, err := http.Get(config.ApiServer + "/file/bot" + b.GetToken() + "/" + f.FilePath)
raw, err := http.Get(config.ApiServer + "/file/bot" + config.BotToken + "/" + f.FilePath)
if err != nil {
log.Error(err)
}
Expand Down Expand Up @@ -235,8 +247,10 @@ func (moduleStruct) paste(b *gotgbot.Bot, ctx *ext.Context) error {
if pasted {
_, _, err = edited.EditText(b, fmt.Sprintf("<b>Pasted Successfully!</b>\nhttps://www.nekobin.com/%s.%s", key, extention),
&gotgbot.EditMessageTextOpts{
ParseMode: helpers.HTML,
DisableWebPagePreview: true,
ParseMode: helpers.HTML,
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: true,
},
},
)
if err != nil {
Expand Down
Loading

0 comments on commit b1889d4

Please sign in to comment.