本文整理汇总了Golang中github.com/iopred/bruxism.Service.SendFile方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.SendFile方法的具体用法?Golang Service.SendFile怎么用?Golang Service.SendFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/iopred/bruxism.Service
的用法示例。
在下文中一共展示了Service.SendFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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()
}()
}
}
示例2: emojiMessageFunc
func emojiMessageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
if service.Name() == bruxism.DiscordServiceName && !service.IsMe(message) {
if bruxism.MatchesCommand(service, "emoji", message) || bruxism.MatchesCommand(service, "hugemoji", message) {
base := "emoji/twitter"
if bruxism.MatchesCommand(service, "hugemoji", message) {
base = "emoji/twitterhuge"
}
_, parts := bruxism.ParseCommand(service, message)
if len(parts) == 1 {
submatches := discordRegex.FindStringSubmatch(parts[0])
if len(submatches) != 0 {
h, err := http.Get("https://cdn.discordapp.com/emojis/" + submatches[1] + ".png")
if err != nil {
return
}
service.SendFile(message.Channel(), "emoji.png", h.Body)
h.Body.Close()
return
}
s := strings.TrimSpace(parts[0])
for i := range s {
filename := emojiFile(base, s[i:])
if filename != "" {
if f, err := os.Open(fmt.Sprintf("%s/%s.png", base, filename)); err == nil {
defer f.Close()
service.SendFile(message.Channel(), "emoji.png", f)
return
}
}
}
}
}
}
}
示例3: 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
}
//.........这里部分代码省略.........