Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Add ID field to User struct (#40)
Browse files Browse the repository at this point in the history
Also make sure it's filled in the appropriate places. This allows you to add
some granularity to whom can run certain commands.

Fixes #39
  • Loading branch information
doenietzomoeilijk authored and fabioxgn committed Feb 6, 2017
1 parent 175cb6d commit 88f9e21
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ type PeriodicConfig struct {
CmdFunc func(channel string) (string, error) // func to be executed at the period specified on CronSpec
}

// User holds user id (nick) and real name
// User holds user id, nick and real name
type User struct {
ID string
Nick string
RealName string
}
Expand Down
5 changes: 4 additions & 1 deletion irc/irc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ func responseHandler(target string, message string, sender *bot.User) {
}

func onPRIVMSG(e *ircevent.Event) {
b.MessageReceived(e.Arguments[0], e.Message(), &bot.User{Nick: e.Nick})
b.MessageReceived(e.Arguments[0], e.Message(), &bot.User{
ID: e.Host,
Nick: e.Nick,
RealName: e.User})
}

func getServerName(server string) string {
Expand Down
5 changes: 4 additions & 1 deletion slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ func extractUser(userID string) *bot.User {
fmt.Printf("Error retrieving slack user: %s\n", err)
return &bot.User{Nick: userID}
}
return &bot.User{Nick: slackUser.Name, RealName: slackUser.Profile.RealName}
return &bot.User{
ID: userID,
Nick: slackUser.Name,
RealName: slackUser.Profile.RealName}
}

func readBotInfo(api *slack.Client) {
Expand Down
9 changes: 7 additions & 2 deletions telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package telegram
import (
"log"
"strconv"
"strings"

"github.com/go-chat-bot/bot"
"gopkg.in/telegram-bot-api.v3"
Expand Down Expand Up @@ -52,7 +53,11 @@ func Run(token string, debug bool) {

for update := range updates {
target := strconv.FormatInt(update.Message.Chat.ID, 10)
sender := strconv.Itoa(update.Message.From.ID)
b.MessageReceived(target, update.Message.Text, &bot.User{Nick: sender})
name := []string{update.Message.From.FirstName, update.Message.From.LastName}

b.MessageReceived(target, update.Message.Text, &bot.User{
ID: strconv.Itoa(update.Message.From.ID),
Nick: update.Message.From.UserName,
RealName: strings.Join(name, " ")})
}
}

0 comments on commit 88f9e21

Please sign in to comment.