Skip to content

Commit

Permalink
Add the /welcomemute command
Browse files Browse the repository at this point in the history
Signed-off-by: ATechnoHazard <[email protected]>
  • Loading branch information
SphericalKat committed Dec 2, 2019
1 parent dfcbb33 commit 10e5c1d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
10 changes: 10 additions & 0 deletions go_bot/modules/sql/welcome_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,13 @@ func SetDelPref(chatID string, pref bool) {
tx.Save(w)
tx.Commit()
}

// SetMutePref Set whether to mute users when they join or not
func SetMutePref(chatID string, pref bool) {
w := &Welcome{ChatId: chatID}
tx := SESSION.Begin()
tx.FirstOrCreate(w)
w.ShouldMute = pref
tx.Save(w)
tx.Commit()
}
1 change: 1 addition & 0 deletions go_bot/modules/welcome/welcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,5 @@ func LoadWelcome(u *gotgbot.Updater) {
u.Dispatcher.AddHandler(handlers.NewPrefixCommand("resetwelcome", []rune{'!', '/'}, resetWelcome))
u.Dispatcher.AddHandler(handlers.NewPrefixArgsCommand("cleanwelcome", []rune{'!', '/'}, cleanWelcome))
u.Dispatcher.AddHandler(handlers.NewPrefixArgsCommand("deljoined", []rune{'!', '/'}, delJoined))
u.Dispatcher.AddHandler(handlers.NewPrefixArgsCommand("welcomemute", []rune{'!', '/'}, welcomeMute))
}
35 changes: 34 additions & 1 deletion go_bot/modules/welcome/welcome_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func cleanWelcome(_ ext.Bot, u *gotgbot.Update, args []string) error {
}
}

func delJoined(bot ext.Bot, u *gotgbot.Update, args []string) error {
func delJoined(_ ext.Bot, u *gotgbot.Update, args []string) error {
chat := u.EffectiveChat
if !chat_status.IsUserAdmin(chat, u.EffectiveUser.Id) {
_, _ = u.EffectiveMessage.ReplyText("You need to be an admin to do this.")
Expand Down Expand Up @@ -200,3 +200,36 @@ func delJoined(bot ext.Bot, u *gotgbot.Update, args []string) error {
return err
}
}

func welcomeMute(_ ext.Bot, u *gotgbot.Update, args []string) error {
chat := u.EffectiveChat
if !chat_status.IsUserAdmin(chat, u.EffectiveUser.Id) {
_, _ = u.EffectiveMessage.ReplyText("You need to be an admin to do this.")
return gotgbot.ContinueGroups{}
}

if len(args) == 0 {
welcPref := sql.GetWelcomePrefs(strconv.Itoa(chat.Id))
if welcPref.ShouldMute {
_, err := u.EffectiveMessage.ReplyMarkdown("I'm currently muting users when they join.")
return err
} else {
_, err := u.EffectiveMessage.ReplyText("I'm currently not muting users when they join.")
return err
}
}

switch strings.ToLower(args[0]) {
case "off", "no":
go sql.SetMutePref(strconv.Itoa(chat.Id), false)
_, err := u.EffectiveMessage.ReplyText("I won't delete joined messages.")
return err
case "on", "yes":
go sql.SetMutePref(strconv.Itoa(chat.Id), true)
_, err := u.EffectiveMessage.ReplyText("I'll try to delete joined messages!")
return err
default:
_, err := u.EffectiveMessage.ReplyText("I understand 'on/yes' or 'off/no' only!")
return err
}
}

0 comments on commit 10e5c1d

Please sign in to comment.