Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement some cringe features #58

Merged
merged 1 commit into from Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions command.go
Expand Up @@ -75,6 +75,18 @@ var Commands = []Command{
},
Handler: rulesHandler,
},
{
Name: "cringe",
Description: "generates a random cringe image",
Usage: []string{""},
Handler: handleCringe,
},
{
Name: "addcringe",
Description: "adds a cringe photo to the collection",
Usage: []string{"", "url"},
Handler: handleAddCringe,
},
}

func init() {
Expand Down
46 changes: 46 additions & 0 deletions cringe.go
@@ -0,0 +1,46 @@
package main

import (
"fmt"
"github.com/bwmarrin/discordgo"
"net/url"
)

// this file is the story of my life lol

func handleCringe(_ *discordgo.Member, msg *discordgo.Message, _ []string) error {
var rngCringe string
err := DB.QueryRow("SELECT image FROM cringe ORDER BY RAND() LIMIT 1").Scan(&rngCringe)
if err != nil {
return err
}
reply := discordgo.MessageEmbed{
Title: ":camera_with_flash:",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome lmao

Image: &discordgo.MessageEmbedImage{
URL: rngCringe,
},
Color: prettyembedcolor,
}
_, err = discord.ChannelMessageSendEmbed(msg.ChannelID, &reply)
return err
}

func handleAddCringe(caller *discordgo.Member, msg *discordgo.Message, args []string) error {
if !IsUserAtLeast(caller, Support) {
return fmt.Errorf("you have to be at least support to call something cringe-worthy lol")
}

if len(args) == 0 {
if len(msg.Attachments) > 0 {
_, err := DB.Exec("INSERT INTO cringe(image) VALUES($1)", msg.Attachments[0].URL)
return err
}
return fmt.Errorf("error : no attachments / links found to add")
}
_, err := url.ParseRequestURI(args[0])
if err != nil {
return fmt.Errorf("invalid url scheme")
}
_, err = DB.Exec("INSERT INTO cringe(image) VALUES($1)", args[0])
return err
}
7 changes: 7 additions & 0 deletions db.go
Expand Up @@ -53,5 +53,12 @@ func schema() (err error) {
expiration TIMESTAMP
);
`)

_, err = DB.Exec(`
CREATE TABLE IF NOT EXISTS cringe (
image TEXT NOT NULL
)
`)

return
}