Compare commits
9 Commits
e9af59d541
...
d73bb37279
Author | SHA1 | Date |
---|---|---|
skeletable | d73bb37279 | |
skeletable | 554aeb9575 | |
skeletable | 9aa2ec506c | |
skeletable | 15f4a6e6a3 | |
skeletable | 76751063a6 | |
skeletable | 986cf3b4a2 | |
skeletable | 5a65afbce3 | |
skeletable | 013ff5ffb1 | |
skeletable | 6c9a47081f |
202
main.go
202
main.go
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -115,6 +116,8 @@ func getCandyPic() string {
|
|||
"https://cdn.discordapp.com/attachments/956628829735125042/1023245478869078026/candythis.jpg",
|
||||
"https://cdn.discordapp.com/attachments/956628829735125042/1023245479187841075/candy15.jpg",
|
||||
"https://cdn.discordapp.com/attachments/956628829735125042/1023259345934352414/candysad.jpg",
|
||||
"https://cdn.discordapp.com/attachments/956628829735125042/1024353063076642866/candynemorgal.jpg",
|
||||
"https://cdn.discordapp.com/attachments/956628829735125042/1024353428027211826/candyschizo.jpg",
|
||||
}
|
||||
return pics[rand.Intn(len(pics))]
|
||||
}
|
||||
|
@ -240,11 +243,35 @@ func candy(s *discordgo.Session, channel string) {
|
|||
Author: &discordgo.MessageEmbedAuthor{},
|
||||
Fields: []*discordgo.MessageEmbedField{},
|
||||
}
|
||||
candyXorcon := &discordgo.MessageEmbed{
|
||||
URL: "",
|
||||
Type: "",
|
||||
Title: "Xorconium Pills",
|
||||
Description: "",
|
||||
Timestamp: "",
|
||||
Color: 0x306AC0,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "candyXorcon",
|
||||
IconURL: "",
|
||||
ProxyIconURL: "",
|
||||
},
|
||||
Image: &discordgo.MessageEmbedImage{
|
||||
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1024326522389147718/Alpha_Xorcon.png",
|
||||
ProxyURL: "",
|
||||
Width: 0,
|
||||
Height: 0,
|
||||
},
|
||||
Thumbnail: &discordgo.MessageEmbedThumbnail{},
|
||||
Video: &discordgo.MessageEmbedVideo{},
|
||||
Provider: &discordgo.MessageEmbedProvider{},
|
||||
Author: &discordgo.MessageEmbedAuthor{},
|
||||
Fields: []*discordgo.MessageEmbedField{},
|
||||
}
|
||||
|
||||
drop := candy1
|
||||
|
||||
rand.Seed(time.Now().Unix())
|
||||
switch rand.Intn(10) {
|
||||
switch rand.Intn(15) {
|
||||
case 1:
|
||||
drop = candyCaptain
|
||||
case 2:
|
||||
|
@ -253,6 +280,8 @@ func candy(s *discordgo.Session, channel string) {
|
|||
drop = candyRadmeal
|
||||
case 4:
|
||||
drop = candyMeta
|
||||
case 5:
|
||||
drop = candyXorcon
|
||||
default:
|
||||
drop = candy1
|
||||
}
|
||||
|
@ -418,7 +447,8 @@ func initdb() {
|
|||
users_table := `CREATE TABLE users (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"userID" TEXT,
|
||||
"candy" INT);`
|
||||
"candy" INT,
|
||||
"buff" INT);`
|
||||
query, err := db.Prepare(users_table)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
|
@ -427,19 +457,19 @@ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|||
query.Exec()
|
||||
}
|
||||
|
||||
func addUser(userID string, candy int) {
|
||||
func addUser(userID string, candy int, buff int) {
|
||||
db, err := sql.Open("sqlite3", "guilds.db")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
records := `INSERT INTO users(userID, candy) VALUES (?, ?)`
|
||||
records := `INSERT INTO users(userID, candy, buff) VALUES (?, ?, ?)`
|
||||
query, err := db.Prepare(records)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
_, err = query.Exec(userID, candy)
|
||||
_, err = query.Exec(userID, candy, buff)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
|
@ -460,6 +490,87 @@ func delUser(userID string) {
|
|||
query.Exec()
|
||||
}
|
||||
|
||||
func checkUser(userID string) bool {
|
||||
db, err := sql.Open("sqlite3", "guilds.db")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return false
|
||||
}
|
||||
err = db.QueryRow(`SELECT userID FROM users WHERE userID = ?`, userID).Scan(&userID)
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func checkUserCandy(userID string) int {
|
||||
db, err := sql.Open("sqlite3", "guilds.db")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return 0
|
||||
}
|
||||
var candy int
|
||||
err = db.QueryRow(`SELECT candy FROM users WHERE userID = ?`, userID).Scan(&candy)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return 0
|
||||
}
|
||||
return candy
|
||||
}
|
||||
|
||||
func addCandy(userID string, amount int) {
|
||||
db, err := sql.Open("sqlite3", "guilds.db")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
query, err := db.Prepare(`UPDATE users SET candy = candy + ? WHERE userID = ?`)
|
||||
_, err = query.Exec(amount, userID)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func addBuff(userID string, amount int) {
|
||||
db, err := sql.Open("sqlite3", "guilds.db")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
query, err := db.Prepare(`UPDATE users SET buff = buff + ? WHERE userID = ?`)
|
||||
_, err = query.Exec(amount, userID)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func candyRank() (string, error) {
|
||||
ms := ""
|
||||
db, err := sql.Open("sqlite3", "guilds.db")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return ms, err
|
||||
}
|
||||
query, err := db.Query(`SELECT userID, candy FROM users ORDER BY candy DESC LIMIT 10`)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return ms, err
|
||||
}
|
||||
defer query.Close()
|
||||
n := 1
|
||||
for query.Next() {
|
||||
var userID string
|
||||
var candy int
|
||||
query.Scan(&userID, &candy)
|
||||
ms += fmt.Sprint(n) + `. <@` + userID + "> " + fmt.Sprint(candy) + "\n"
|
||||
n++
|
||||
}
|
||||
return ms, err
|
||||
}
|
||||
|
||||
func main() {
|
||||
commitID, err := exec.Command("git", "log", "-1", "--format=%h").Output()
|
||||
if err != nil {
|
||||
|
@ -484,7 +595,7 @@ func main() {
|
|||
fmt.Println("Initialising database...")
|
||||
initdb()
|
||||
fmt.Println("Testing database:")
|
||||
addUser("0000000", 100)
|
||||
addUser("0000000", 100, 0)
|
||||
delUser("0000000")
|
||||
fmt.Println("Test complete.")
|
||||
}
|
||||
|
@ -561,12 +672,23 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||
|
||||
// Ignore all messages created by the bot itself
|
||||
// This isn't required in this specific example but it's a good practice.
|
||||
|
||||
var claimed bool
|
||||
var tickrate time.Duration
|
||||
const maxtickrate = 2000 * time.Millisecond
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
if m.Content == "🍬 ***Some candy has appeared! React to this message to claim it.*** 🍬" {
|
||||
s.MessageReactionAdd(m.ChannelID, m.Reference().MessageID, "🍬")
|
||||
}
|
||||
tickrate = 100 * time.Millisecond
|
||||
claimed = false
|
||||
for i := 0; i < 480; i++ {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
time.Sleep(tickrate)
|
||||
if tickrate < maxtickrate {
|
||||
if i % 2 == 0 {
|
||||
tickrate += 10 * time.Millisecond
|
||||
}
|
||||
}
|
||||
reactions, err := s.MessageReactions(m.ChannelID, m.Reference().MessageID, "🍬", 2, "", "")
|
||||
if err != nil {
|
||||
s.ChannelMessageSend(m.ChannelID, err.Error())
|
||||
|
@ -598,21 +720,49 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||
continue
|
||||
}
|
||||
if blocked == false {
|
||||
var candyvalue int
|
||||
bufftype := "none"
|
||||
buffvalue := 0
|
||||
var candystr string
|
||||
switch m.Embeds[0].Footer.Text {
|
||||
case "candyMilky":
|
||||
s.ChannelMessageSend(m.ChannelID, reactions[0].Username + " has claimed the candy! (+500 🍬)\n" +
|
||||
"*Good luck!* Global candy droprate temporarily increased!")
|
||||
candyvalue = 500
|
||||
bufftype = "tewi"
|
||||
case "candyMeta":
|
||||
s.ChannelMessageSend(m.ChannelID, reactions[0].Username + " has claimed the candy! (+1000 🍬)")
|
||||
candyvalue = 1000
|
||||
case "candyCaptain":
|
||||
s.ChannelMessageSend(m.ChannelID, reactions[0].Username + " has claimed the candy! (+250 🍬)")
|
||||
candyvalue = 250
|
||||
case "candyRadmeal":
|
||||
s.ChannelMessageSend(m.ChannelID, reactions[0].Username + " has claimed the radmeal! (-200 🍬)")
|
||||
default: s.ChannelMessageSend(m.ChannelID, reactions[0].Username + " has claimed the candy! (+100 🍬)")
|
||||
candyvalue = -200
|
||||
case "candyXorcon":
|
||||
candyvalue = 50
|
||||
bufftype = "alpha"
|
||||
buffvalue = 1
|
||||
default:
|
||||
candyvalue = 100
|
||||
}
|
||||
if !math.Signbit(float64(candyvalue)) {
|
||||
candystr = "+" + fmt.Sprint(candyvalue)
|
||||
} else { candystr = fmt.Sprint(candyvalue) }
|
||||
msg := reactions[0].Username + " has claimed the candy! (" + candystr + " 🍬)"
|
||||
switch bufftype {
|
||||
case "tewi":
|
||||
msg += "\n*Good luck!* Global candy droprate temporarily increased!"
|
||||
case "alpha":
|
||||
msg += "\n*Bash!* Crit chance permanently increased!"
|
||||
}
|
||||
if !checkUser(reactions[0].ID) {
|
||||
addUser(reactions[0].ID, candyvalue, buffvalue)
|
||||
} else {
|
||||
addCandy(reactions[0].ID, candyvalue)
|
||||
addBuff(reactions[0].ID, buffvalue)
|
||||
}
|
||||
s.ChannelMessageSend(m.ChannelID, msg)
|
||||
claimed = true
|
||||
}
|
||||
break
|
||||
if claimed { break }
|
||||
}
|
||||
if claimed { break }
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -1171,4 +1321,28 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||
query.Exec()
|
||||
s.ChannelMessageSend(m.ChannelID, "OK")
|
||||
}
|
||||
|
||||
if strings.HasPrefix(m.Content, "pp!candy") {
|
||||
s.ChannelMessageSend(m.ChannelID, "Collected candy: " + fmt.Sprint(checkUserCandy(m.Author.ID)))
|
||||
}
|
||||
|
||||
if strings.HasPrefix(m.Content, "pp!checkuser") {
|
||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprint(checkUser(m.Author.ID)))
|
||||
}
|
||||
|
||||
if strings.HasPrefix(m.Content, "pp!rank") {
|
||||
rank, err := candyRank()
|
||||
if err != nil {
|
||||
s.ChannelMessageSend(m.ChannelID, err.Error())
|
||||
return
|
||||
}
|
||||
ms := &discordgo.MessageSend{
|
||||
Embed: &discordgo.MessageEmbed{
|
||||
Title: "Candy ranking",
|
||||
Description: rank,
|
||||
},
|
||||
AllowedMentions: &discordgo.MessageAllowedMentions{},
|
||||
}
|
||||
s.ChannelMessageSendComplex(m.ChannelID, ms)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue