move user registration to linkbot menu file
This commit is contained in:
parent
c9615cbdfb
commit
ed13dd5216
37
NTFServer.go
37
NTFServer.go
@ -148,43 +148,6 @@ func NewNTFServer(configFile string, verbose bool) (*NTFServer, error) {
|
|||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerUser lodges a user mapping in the configuration file.
|
|
||||||
// This allows them to join the group chat (unbanning them if necessary).
|
|
||||||
// An actual NMDC connection will occur once the user joins for the first time.
|
|
||||||
func (this *NTFServer) registerUser(telegramUserId int64, hubUsername string) error {
|
|
||||||
if existingHubNick, ok := this.config.KnownUsers[telegramUserId]; ok {
|
|
||||||
if existingHubNick == hubUsername {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Telegram account is already registered with hub nick '%s'", existingHubNick)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, v := range this.config.KnownUsers {
|
|
||||||
if v == hubUsername {
|
|
||||||
return fmt.Errorf("Requested hub nick '%s' is already used by another member", hubUsername)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.config.KnownUsers[telegramUserId] = hubUsername
|
|
||||||
err := this.config.Save(this.configFile)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unban from groupchat, if necessary
|
|
||||||
// Ignore errors because the user might not have been banned
|
|
||||||
_, err = this.bot.UnbanChatMember(telegram.ChatMemberConfig{
|
|
||||||
ChatID: this.config.GroupChatID,
|
|
||||||
UserID: int(telegramUserId),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Couldn't unban user '%s' from groupchat because: %s (assuming OK, continuing)", hubUsername, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// LaunchUpstreamWorker opens an NMDC connection.
|
// LaunchUpstreamWorker opens an NMDC connection.
|
||||||
func (this *NTFServer) LaunchUpstreamWorker(telegramUserId int64, hubUsername string) error {
|
func (this *NTFServer) LaunchUpstreamWorker(telegramUserId int64, hubUsername string) error {
|
||||||
|
|
||||||
|
@ -10,6 +10,43 @@ import (
|
|||||||
telegram "github.com/go-telegram-bot-api/telegram-bot-api"
|
telegram "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// registerUser lodges a user mapping in the configuration file.
|
||||||
|
// This allows them to join the group chat (unbanning them if necessary).
|
||||||
|
// An actual NMDC connection will occur once the user joins for the first time.
|
||||||
|
func (this *NTFServer) registerUser(telegramUserId int64, hubUsername string) error {
|
||||||
|
if existingHubNick, ok := this.config.KnownUsers[telegramUserId]; ok {
|
||||||
|
if existingHubNick == hubUsername {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("Telegram account is already registered with hub nick '%s'", existingHubNick)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range this.config.KnownUsers {
|
||||||
|
if v == hubUsername {
|
||||||
|
return fmt.Errorf("Requested hub nick '%s' is already used by another member", hubUsername)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.config.KnownUsers[telegramUserId] = hubUsername
|
||||||
|
err := this.config.Save(this.configFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unban from groupchat, if necessary
|
||||||
|
// Ignore errors because the user might not have been banned
|
||||||
|
_, err = this.bot.UnbanChatMember(telegram.ChatMemberConfig{
|
||||||
|
ChatID: this.config.GroupChatID,
|
||||||
|
UserID: int(telegramUserId),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Couldn't unban user '%s' from groupchat because: %s (assuming OK, continuing)", hubUsername, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (this *NTFServer) HandleDirectMessage(update telegram.Update) error {
|
func (this *NTFServer) HandleDirectMessage(update telegram.Update) error {
|
||||||
|
|
||||||
// Registration workflow
|
// Registration workflow
|
||||||
|
Loading…
Reference in New Issue
Block a user