本文整理汇总了Golang中github.com/iopred/bruxism.Message.UserID方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.UserID方法的具体用法?Golang Message.UserID怎么用?Golang Message.UserID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/iopred/bruxism.Message
的用法示例。
在下文中一共展示了Message.UserID方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Message
func (t *triviaChannel) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
if strings.ToLower(message.Message()) == t.Answer {
t.Lock()
defer t.Unlock()
if !t.Active {
return
}
ts := t.Scores[message.UserID()]
if ts == nil {
ts = &triviaScore{}
t.Scores[message.UserID()] = ts
}
ts.Name = message.UserName()
ts.Score++
service.SendMessage(message.Channel(), fmt.Sprintf("%s got it! The answer was %s.", message.UserName(), t.Answer))
service.SendMessage(message.Channel(), fmt.Sprintf("%s answered in %d seconds and their score is now %d.", message.UserName(), int(time.Now().Sub(t.Asked).Seconds()), ts.Score))
t.Unanswered = 0
if t.hintChan != nil {
close(t.hintChan)
t.hintChan = nil
}
}
}
示例2: InviteCommand
// InviteCommand is a command for accepting an invite to a channel.
func InviteCommand(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message, command string, parts []string) {
if service.Name() == bruxism.DiscordServiceName {
discord := service.(*bruxism.Discord)
if discord.ApplicationClientID != "" {
service.SendMessage(message.Channel(), fmt.Sprintf("Please visit https://discordapp.com/oauth2/authorize?client_id=%s&scope=bot to add %s to your server.", discord.ApplicationClientID, service.UserName()))
return
}
}
if len(parts) == 1 {
join := parts[0]
if service.Name() == bruxism.DiscordServiceName {
join = discordInviteID(join)
}
if err := service.Join(join); err != nil {
if service.Name() == bruxism.DiscordServiceName && err == bruxism.ErrAlreadyJoined {
service.PrivateMessage(message.UserID(), "I have already joined that server.")
return
}
log.Println("Error joining %s %v", service.Name(), err)
} else if service.Name() == bruxism.DiscordServiceName {
service.PrivateMessage(message.UserID(), "I have joined that server.")
}
}
}
示例3: makeComic
func (p *comicPlugin) makeComic(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message, script *comicgen.Script) {
p.Comics++
comic := comicgen.NewComicGen("arial", service.Name() != bruxism.DiscordServiceName)
image, err := comic.MakeComic(script)
if err != nil {
service.SendMessage(message.Channel(), fmt.Sprintf("Sorry %s, there was an error creating the comic. %s", message.UserName(), err))
} else {
go func() {
if service.Name() == bruxism.DiscordServiceName {
discord := service.(*bruxism.Discord)
p, err := discord.UserChannelPermissions(message.UserID(), message.Channel())
if err == nil && p&discordgo.PermissionAttachFiles != 0 {
b := &bytes.Buffer{}
err = png.Encode(b, image)
if err != nil {
service.SendMessage(message.Channel(), fmt.Sprintf("Sorry %s, there was a problem creating your comic.", message.UserName()))
return
}
if err := service.SendFile(message.Channel(), "comic.png", b); err == nil {
return
}
}
}
b := &bytes.Buffer{}
err = png.Encode(b, image)
if err != nil {
service.SendMessage(message.Channel(), fmt.Sprintf("Sorry %s, there was a problem creating your comic.", message.UserName()))
return
}
url, err := bot.UploadToImgur(b, "comic.png")
if err != nil {
service.SendMessage(message.Channel(), fmt.Sprintf("Sorry %s, there was a problem uploading the comic to imgur.", message.UserName()))
log.Println("Error uploading comic: ", err)
return
}
if service.Name() == bruxism.DiscordServiceName {
service.SendMessage(message.Channel(), fmt.Sprintf("Here's your comic <@%s>: %s", message.UserID(), url))
} else {
service.SendMessage(message.Channel(), fmt.Sprintf("Here's your comic %s: %s", message.UserName(), url))
}
runtime.GC()
}()
}
}
示例4: Message
func (p *ReminderPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
if !service.IsMe(message) {
if bruxism.MatchesCommand(service, "remind", message) || bruxism.MatchesCommand(service, "reminder", message) {
_, parts := bruxism.ParseCommand(service, message)
if len(parts) < 2 {
service.SendMessage(message.Channel(), fmt.Sprintf("Invalid reminder, no time or message. eg: %s", p.randomReminder(service)))
return
}
t, r, err := p.parseReminder(parts)
now := time.Now()
if err != nil || t.Before(now) || t.After(now.Add(time.Hour*24*365+time.Hour)) {
service.SendMessage(message.Channel(), fmt.Sprintf("Invalid time. eg: %s", strings.Join(randomTimes, ", ")))
return
}
if r == "" {
service.SendMessage(message.Channel(), fmt.Sprintf("Invalid reminder, no message. eg: %s", p.randomReminder(service)))
return
}
requester := message.UserName()
if service.Name() == bruxism.DiscordServiceName {
requester = fmt.Sprintf("<@%s>", message.UserID())
}
err = p.AddReminder(&Reminder{
StartTime: now,
Time: t,
Requester: requester,
Target: message.Channel(),
Message: r,
IsPrivate: service.IsPrivate(message),
})
if err != nil {
service.SendMessage(message.Channel(), err.Error())
return
}
service.SendMessage(message.Channel(), fmt.Sprintf("Reminder set for %s.", humanize.Time(t)))
}
}
}
示例5: avatarMessageFunc
func avatarMessageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
if !service.IsMe(message) {
if bruxism.MatchesCommand(service, "avatar", message) {
query := strings.Join(strings.Split(message.RawMessage(), " ")[1:], " ")
id := message.UserID()
match := userIDRegex.FindStringSubmatch(query)
if match != nil {
id = match[1]
}
discord := service.(*bruxism.Discord)
u, err := discord.Session.User(id)
if err != nil {
return
}
service.SendMessage(message.Channel(), discordgo.EndpointUserAvatar(u.ID, u.Avatar))
}
}
}
示例6: Message
// Message handler.
func (p *MusicPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
defer bruxism.MessageRecover()
if service.IsMe(message) {
return
}
if !bruxism.MatchesCommand(service, "music", message) && !bruxism.MatchesCommand(service, "mu", message) {
return
}
_, parts := bruxism.ParseCommand(service, message)
if len(parts) == 0 {
service.SendMessage(message.Channel(), strings.Join(p.Help(bot, service, message, true), "\n"))
return
}
// Get the Channel (and GuildID) for this channel because it's needed in
// a few locations below
channel, err := p.discord.Channel(message.Channel())
if err != nil {
log.Println("musicplugin: fetching channel err:", err.Error())
return
}
// grab pointer to this channels voice connection, if exists.
vc, vcok := p.VoiceConnections[channel.GuildID]
switch parts[0] {
case "help":
// display extended help information
service.SendMessage(message.Channel(), strings.Join(p.Help(bot, service, message, true), "\n"))
case "stats":
// TODO: maybe provide plugin stats, total channels, total song queues, etc
case "join":
if !service.IsBotOwner(message) {
service.SendMessage(message.Channel(), "Sorry, only bot owner can join, please ask him to run this command.")
return
}
// join the voice channel of the caller or the provided channel ID
channelID := ""
if len(parts) > 1 {
channelID = parts[1]
}
if channelID == "" {
messageUserID := message.UserID()
for _, g := range p.discord.Guilds() {
for _, v := range g.VoiceStates {
if v.UserID == messageUserID {
channelID = v.ChannelID
}
}
}
if channelID == "" {
service.SendMessage(message.Channel(), "I couldn't find you in any voice channels, please join one.")
return
}
}
_, err := p.join(channelID)
if err != nil {
service.SendMessage(message.Channel(), err.Error())
break
}
service.SendMessage(message.Channel(), "Now, let's play some music!")
case "leave":
// leave voice channel for this Guild
if !service.IsBotOwner(message) {
service.SendMessage(message.Channel(), "Sorry, only bot owner can leave, please ask him to run this command.")
return
}
if !vcok {
service.SendMessage(message.Channel(), "There is no voice connection for this Guild.")
}
vc.conn.Close()
delete(p.VoiceConnections, channel.GuildID)
service.SendMessage(message.Channel(), "Closed voice connection.")
case "debug":
// enable or disable debug
if !vcok {
service.SendMessage(message.Channel(), fmt.Sprintf("There is no voice connection for this Guild."))
}
vc.Lock()
vc.debug = !vc.debug
service.SendMessage(message.Channel(), fmt.Sprintf("debug mode set to %v", vc.debug))
//.........这里部分代码省略.........
示例7: messageFunc
func (p *chartPlugin) messageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
if service.IsMe(message) {
return
}
if bruxism.MatchesCommand(service, "chart", message) {
query, parts := bruxism.ParseCommand(service, message)
if len(parts) == 0 {
service.SendMessage(message.Channel(), fmt.Sprintf("Invalid chart eg: %s", p.randomChart(service)))
return
}
start, end := 0.5, 0.5
switch parts[0] {
case "up":
start, end = 0, 1
case "down":
start, end = 1, 0
case "flat":
case "straight":
default:
service.SendMessage(message.Channel(), fmt.Sprintf("Invalid chart direction. eg: %s", p.randomChart(service)))
return
}
axes := strings.Split(query[len(parts[0]):], ",")
if len(axes) != 2 {
service.SendMessage(message.Channel(), fmt.Sprintf("Invalid chart axis labels eg: %s", p.randomChart(service)))
return
}
pl, err := plot.New()
if err != nil {
service.SendMessage(message.Channel(), fmt.Sprintf("Error making chart, sorry! eg: %s", p.randomChart(service)))
return
}
service.Typing(message.Channel())
pl.Y.Label.Text = axes[0]
pl.X.Label.Text = axes[1]
num := 5 + rand.Intn(15)
start *= float64(num)
end *= float64(num)
pts := make(plotter.XYs, num)
for i := range pts {
pts[i].X = float64(i) + rand.Float64()*0.5 - 0.2
pts[i].Y = start + float64(end-start)/float64(num-1)*float64(i) + rand.Float64()*0.5 - 0.25
}
pl.X.Tick.Label.Color = color.Transparent
pl.Y.Tick.Label.Color = color.Transparent
pl.X.Min = -0.5
pl.X.Max = float64(num) + 0.5
pl.Y.Min = -0.5
pl.Y.Max = float64(num) + 0.5
lpLine, lpPoints, err := plotter.NewLinePoints(pts)
if err != nil {
service.SendMessage(message.Channel(), fmt.Sprintf("Sorry %s, there was a problem creating your chart.", message.UserName()))
}
lpLine.Color = plotutil.Color(rand.Int())
lpLine.Width = vg.Points(1 + 0.5*rand.Float64())
lpLine.Dashes = plotutil.Dashes(rand.Int())
lpPoints.Shape = plotutil.Shape(rand.Int())
lpPoints.Color = lpLine.Color
pl.Add(lpLine, lpPoints)
w, err := pl.WriterTo(320, 240, "png")
if err != nil {
service.SendMessage(message.Channel(), fmt.Sprintf("Sorry %s, there was a problem creating your chart.", message.UserName()))
return
}
b := &bytes.Buffer{}
w.WriteTo(b)
go func() {
if service.Name() == bruxism.DiscordServiceName {
discord := service.(*bruxism.Discord)
p, err := discord.UserChannelPermissions(message.UserID(), message.Channel())
if err == nil && p&discordgo.PermissionAttachFiles != 0 {
service.SendFile(message.Channel(), "chart.png", b)
return
}
}
url, err := bot.UploadToImgur(b, "chart.png")
if err != nil {
service.SendMessage(message.Channel(), fmt.Sprintf("Sorry %s, there was a problem uploading the chart to imgur.", message.UserName()))
log.Println("Error uploading chart: ", err)
return
}
//.........这里部分代码省略.........
示例8: Message
func (p *playedPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
defer bruxism.MessageRecover()
if service.Name() == bruxism.DiscordServiceName && !service.IsMe(message) {
if bruxism.MatchesCommand(service, "played", message) {
query := strings.Join(strings.Split(message.RawMessage(), " ")[1:], " ")
id := message.UserID()
match := userIDRegex.FindStringSubmatch(query)
if match != nil {
id = match[1]
}
p.Lock()
defer p.Unlock()
u := p.Users[id]
if u == nil {
service.SendMessage(message.Channel(), "I haven't seen that user.")
return
}
if len(u.Entries) == 0 {
service.SendMessage(message.Channel(), "I haven't seen anything played by that user.")
return
}
lc := humanize.Time(u.LastChanged)
u.Update(u.Current, time.Now())
pes := make(byDuration, len(u.Entries))
i := 0
for _, pe := range u.Entries {
pes[i] = pe
i++
}
sort.Sort(pes)
messageText := fmt.Sprintf("*First seen %s, last update %s*\n", humanize.Time(u.FirstSeen), lc)
for i = 0; i < len(pes) && i < 5; i++ {
pe := pes[i]
du := pe.Duration
ds := ""
hours := int(du / time.Hour)
if hours > 0 {
ds += fmt.Sprintf("%dh ", hours)
du -= time.Duration(hours) * time.Hour
}
minutes := int(du / time.Minute)
if minutes > 0 || len(ds) > 0 {
ds += fmt.Sprintf("%dm ", minutes)
du -= time.Duration(minutes) * time.Minute
}
seconds := int(du / time.Second)
ds += fmt.Sprintf("%ds", seconds)
messageText += fmt.Sprintf("**%s**: %s\n", pe.Name, ds)
}
service.SendMessage(message.Channel(), messageText)
}
}
}