Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
Formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
Strum355 committed Sep 29, 2017
1 parent 4f32d4c commit 25fbd2f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 53 deletions.
23 changes: 11 additions & 12 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ type command struct {
}

var (
commMap = make(map[string]command)

commMap = make(map[string]command)
)

func prepareCommands() {
command{
Name: "git",
Help: "Args: none\n\nLinks 2Bots github page.\n\nExample:\n`"+ conf.Prefix + "git`",
Help: "Args: none\n\nLinks 2Bots github page.\n\nExample:\n`" + conf.Prefix + "git`",
Exec: msgGit,
}.add()
command{
Name: "emoji",
Help: "Args: [emoji]\n\nSends a large image of the given emoji.\n\nExample:\n`"+ conf.Prefix + ":smile:`",
Help: "Args: [emoji]\n\nSends a large image of the given emoji.\n\nExample:\n`" + conf.Prefix + ":smile:`",
Exec: msgEmoji,
}.add()
command{
Expand All @@ -39,17 +38,17 @@ func prepareCommands() {
command{
Name: "image",
Help: "Args: [save,recall,delete,list,status] [name]\n\nSave images and recall them at anytime! Everyone gets 8MB of image storage. Any name counts so long theres no `/` in it." +
"Only you can 'recall' your saved images. There's a review process to make sure nothing illegal is being uploaded but we're fairly relaxed for the most part\n\n" +
"Example:\n`!owo image save 2B Happy`\n2Bot downloads the image and sends it off for reviewing\n\n" +
"`"+ conf.Prefix + "image recall 2B Happy`\nIf your image was confirmed, 2Bot will send the image named `2B Happy`\n\n" +
"`"+ conf.Prefix + "image delete 2B Happy`\nThis will delete the image you saved called `2B Happy`\n\n" +
"`"+ conf.Prefix + "image list`\nThis will list your saved images along with a preview!\n\n" +
"`"+ conf.Prefix + "image status`\nShows some details on your saved images and quota",
"Only you can 'recall' your saved images. There's a review process to make sure nothing illegal is being uploaded but we're fairly relaxed for the most part\n\n" +
"Example:\n`!owo image save 2B Happy`\n2Bot downloads the image and sends it off for reviewing\n\n" +
"`" + conf.Prefix + "image recall 2B Happy`\nIf your image was confirmed, 2Bot will send the image named `2B Happy`\n\n" +
"`" + conf.Prefix + "image delete 2B Happy`\nThis will delete the image you saved called `2B Happy`\n\n" +
"`" + conf.Prefix + "image list`\nThis will list your saved images along with a preview!\n\n" +
"`" + conf.Prefix + "image status`\nShows some details on your saved images and quota",
Exec: msgImageRecall,
}.add()
command{"help",
"", msgHelp,
}.add()
}.add()
}

//Small wrapper function to reduce clutter
Expand Down Expand Up @@ -113,7 +112,7 @@ func msgHelp(s *discordgo.Session, m *discordgo.MessageCreate, msglist []string)
edit.setFields([]*discordgo.MessageEmbedField{
{Name: "Details", Value: val.Help},
})
edit.setTitle("Help "+val.Name)
edit.setTitle("Help " + val.Name)
edit.send()
return
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
infoLog *log.Logger
logF *os.File
// Zero width whitespace to replace message content
content = "​"
content = "​"
)

func createConfig() error {
Expand Down
26 changes: 13 additions & 13 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import (
)

type editComplex struct {
Content *string
Embed *discordgo.MessageEmbed
Content *string
Embed *discordgo.MessageEmbed

MessageCreate *discordgo.MessageCreate
Session *discordgo.Session
Session *discordgo.Session
}

func newEdit(s *discordgo.Session, m *discordgo.MessageCreate, color int) *editComplex {
return &editComplex {
return &editComplex{
Content: &content,

MessageCreate: m,
Session: s,
Session: s,

Embed: &discordgo.MessageEmbed {
Embed: &discordgo.MessageEmbed{
Color: color,
},
}
Expand All @@ -30,7 +30,7 @@ func (e *editComplex) setTitle(title string) {
}

func (e *editComplex) setImage(url string) {
e.Embed.Image = &discordgo.MessageEmbedImage {
e.Embed.Image = &discordgo.MessageEmbedImage{
URL: url,
}
}
Expand All @@ -43,16 +43,16 @@ func (e *editComplex) setDescription(text string) {
e.Embed.Description = text
}

func (e *editComplex) send() *discordgo.Message{
func (e *editComplex) send() *discordgo.Message {
msg, err := e.Session.ChannelMessageEditComplex(&discordgo.MessageEdit{
Channel: e.MessageCreate.ChannelID,
ID: e.MessageCreate.Message.ID,
ID: e.MessageCreate.Message.ID,

Content: &content,

Embed: &discordgo.MessageEmbed {
Color: e.Embed.Color,
Title: e.Embed.Title,
Embed: &discordgo.MessageEmbed{
Color: e.Embed.Color,
Title: e.Embed.Title,
Description: e.Embed.Description,

Fields: e.Embed.Fields,
Expand All @@ -67,4 +67,4 @@ func (e *editComplex) send() *discordgo.Message{
}

return msg
}
}
6 changes: 3 additions & 3 deletions msgEmoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func msgFindEmoji(s *discordgo.Session, m *discordgo.MessageCreate, msglist []st
}

userColor := s.State.UserColor(s.State.User.ID, m.ChannelID)

if len(emojis) == 0 {
edit := newEdit(s, m, userColor)
edit.setTitle("No emojis found!")
Expand All @@ -114,9 +114,9 @@ func msgFindEmoji(s *discordgo.Session, m *discordgo.MessageCreate, msglist []st
}

_, err := s.ChannelMessageEditComplex(&discordgo.MessageEdit{
ID: m.Message.ID,
ID: m.Message.ID,
Channel: m.ChannelID,
Content: &content,
Content: &content,
Embed: &discordgo.MessageEmbed{
Title: "Emojis with the substring `" + emojiName + "`",

Expand Down
51 changes: 28 additions & 23 deletions msgImageRecall.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package main

import (
"bytes"
"encoding/hex"
"fmt"
"github.com/bwmarrin/discordgo"
"net/http"
"golang.org/x/crypto/blake2b"
"net/http"
"strings"
"bytes"
"encoding/hex"
)

func msgImageRecall(s *discordgo.Session, m *discordgo.MessageCreate, msglist []string) {
if len(msglist) < 1 {
if len(msglist) < 1 {
s.ChannelMessageEdit(m.ChannelID, m.Message.ID, "Available sub-commands for `image`:\n`save`, `delete`, `recall`, `list`, `status`\n"+
"Type `"+conf.Prefix+"help image` to see more info about this command")
return
Expand All @@ -20,34 +20,35 @@ func msgImageRecall(s *discordgo.Session, m *discordgo.MessageCreate, msglist []
switch msglist[0] {
case "recall":
fimageRecall(s, m, msglist[1:])
case "save":
fimageSave(s, m, msglist[1:])
case "list":
fimageList(s, m, msglist[1:])
case "delete":
fimageDelete(s, m, msglist[1:])
case "info":
fimageInfo(s, m, msglist[1:])
/* case "save":
fimageSave(s, m, msglist[1:])
case "list":
fimageList(s, m, msglist[1:])
case "delete":
fimageDelete(s, m, msglist[1:])
case "info":
fimageInfo(s, m, msglist[1:]) */
}
}

func fimageRecall(s *discordgo.Session, m *discordgo.MessageCreate, msglist []string) {
prefixedImgName := m.Author.ID + "_" + strings.Join(msglist, " ")
hash := blake2b.Sum256([]byte(prefixedImgName))
imgFileName := hex.EncodeToString(hash[:])

URL := fmt.Sprintf("https://api.2bot.ml/image/%s/recall/%s", m.Author.ID, imgFileName)
resp, err := http.Get(URL)
if err != nil {
errorLog.Println(err)
return
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
errorLog.Println(fmt.Sprintf("%d %s", resp.StatusCode, URL))
return
}

buf := new(bytes.Buffer)
buf.ReadFrom(resp.Body)
imgURL := buf.String()
Expand All @@ -59,28 +60,32 @@ func fimageRecall(s *discordgo.Session, m *discordgo.MessageCreate, msglist []st
}

func fimageSave(s *discordgo.Session, m *discordgo.MessageCreate, msglist []string) {
resp, err := http.Get("https://api.2bot.ml/inServer?id="+m.Author.ID)
resp, err := http.Get("https://api.2bot.ml/inServer?id=" + m.Author.ID)
if err != nil {
errorLog.Println(err)
return
}
defer resp.Body.Close()

exists := resp.Header.Get("exists")
if exists == "false" {
errorLog.Println("Gotta be in the 2Bot server for this command")
if resp.StatusCode == http.StatusNotFound {
errorLog.Println("Need to be in 2Bot server to use this command https://discord.gg/9T34Y6u")
return
}

if len(m.Attachments) == 0 || m.Attachments[0].Height == 0 {
errorLog.Println("Need to send an image to be saved")
return
}
}

func fimageList(s *discordgo.Session, m *discordgo.MessageCreate, msglist []string) {

}

func fimageDelete(s *discordgo.Session, m *discordgo.MessageCreate, msglist []string) {

}

func fimageInfo(s *discordgo.Session, m *discordgo.MessageCreate, msglist []string) {
}

}
1 change: 0 additions & 1 deletion utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ func guildDetails(channelID string, s *discordgo.Session) (*discordgo.Guild, err
}
return guildDetails, nil
}

0 comments on commit 25fbd2f

Please sign in to comment.