Compare commits

...

14 Commits

Author SHA1 Message Date
skeletable aa7c3791ef radma 2022-10-02 00:48:19 +02:00
skeletable b91bcd202b chaos 2022-10-02 00:40:34 +02:00
skeletable ed5d06a63c add chaos candy 2022-10-02 00:28:40 +02:00
skeletable bea8b57a99 fix markov overflow 2022-10-02 00:09:36 +02:00
skeletable ef1fddfad6 nerf multipliers 2022-10-02 00:00:01 +02:00
skeletable af6576e69e fix crash 2022-10-01 23:58:23 +02:00
skeletable 2d88106ff4 remove debug messages 2022-10-01 23:53:18 +02:00
skeletable 0cc8bcf01f fix claiming i think 2022-10-01 23:51:59 +02:00
skeletable d5d1cc6c07 claimer 2022-10-01 23:13:00 +02:00
skeletable c9510f3c1f stuff 2022-10-01 23:01:05 +02:00
skeletable 9f5104fc35 stuff 2022-10-01 22:59:51 +02:00
skeletable c340084add stuff 2022-10-01 22:58:20 +02:00
skeletable bed154d794 cosmetic changes 2022-10-01 22:55:32 +02:00
skeletable ca9e5c9130 stuff 2022-10-01 22:18:50 +02:00
2 changed files with 135 additions and 102 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ games/us/**
*.code-workspace
blocklist.txt
markov.txt
inaba9000.exe
guilds.db

235
main.go
View File

@ -6,7 +6,6 @@ import (
"database/sql"
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"math/rand"
@ -126,83 +125,93 @@ func getCandyPic() string {
func candy(s *discordgo.Session, channel string) {
candy1 := &discordgo.MessageEmbed{
Title: "Candy",
Color: 0,
Footer: &discordgo.MessageEmbedFooter{
Text: "candy1",
Title: "Candy",
Color: 0,
Footer: &discordgo.MessageEmbedFooter{
Text: "candy1",
},
Image: &discordgo.MessageEmbedImage{
URL: getCandyPic(),
Image: &discordgo.MessageEmbedImage{
URL: getCandyPic(),
},
}
candyRadmeal := &discordgo.MessageEmbed{
Title: "Candy",
Color: 0xff0000,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyRadmeal",
Title: "Candy",
Color: 0xff0000,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyRadmeal",
},
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/946859404819587162/946897683908542494/P10213-191951-1.jpg",
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/946859404819587162/946897683908542494/P10213-191951-1.jpg",
},
}
candyCaptain := &discordgo.MessageEmbed{
Title: "Captain Candy",
Color: 0xffe600,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyCaptain",
Title: "Captain Candy",
Color: 0xffe600,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyCaptain",
},
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1023225555820216440/unknown.png",
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1023225555820216440/unknown.png",
},
}
candyMilky := &discordgo.MessageEmbed{
Title: "Chocolate Inaba",
Color: 0x6df175,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyMilky",
Title: "Chocolate Inaba",
Color: 0x6df175,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyMilky",
},
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1023229123725893632/7c5085c86d4f230dc253c62b6266279f.jpg",
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1023229123725893632/7c5085c86d4f230dc253c62b6266279f.jpg",
},
}
candyMeta := &discordgo.MessageEmbed{
Title: "Macaroons",
Color: 0xa90000,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyMeta",
Title: "Macaroons",
Color: 0xa90000,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyMeta",
},
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1023271248903544972/macaroon.jpg",
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1023271248903544972/macaroon.jpg",
},
}
candyXorcon := &discordgo.MessageEmbed{
Title: "Xorconium Pills",
Color: 0x306AC0,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyXorcon",
Title: "Xorconium Pills",
Color: 0x306AC0,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyXorcon",
},
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1024326522389147718/Alpha_Xorcon.png",
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1024326522389147718/Alpha_Xorcon.png",
},
}
candyKornflake := &discordgo.MessageEmbed{
Title: "Candy Korn",
Color: 0xff5500,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyKornflake",
Title: "Candy Korn",
Color: 0xff5500,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyKornflake",
},
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1024436493495836762/kornflake.jpg",
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1024436493495836762/kornflake.jpg",
},
}
candyKiko := &discordgo.MessageEmbed{
Title: "Kikola Cubes",
Color: 0x8f32a8,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyKiko",
Title: "Kikola Cubes",
Color: 0x8f32a8,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyKiko",
},
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1024731407001591919/unknown.png",
Image: &discordgo.MessageEmbedImage{
URL: "https://cdn.discordapp.com/attachments/956628829735125042/1024731407001591919/unknown.png",
},
}
candyChaos := &discordgo.MessageEmbed{
Title: "Chaos Candy",
Description: getFortunes()[rand.Intn(len(getFortunes()))],
Color: 0x000000,
Footer: &discordgo.MessageEmbedFooter{
Text: "candyChaos",
IconURL: "",
ProxyIconURL: "",
},
}
@ -224,13 +233,15 @@ func candy(s *discordgo.Session, channel string) {
drop = candyKornflake
case 12, 13:
drop = candyKiko
case 39:
drop = candyChaos
default:
drop = candy1
}
ms := &discordgo.MessageSend{
Content: "🍬 ***Some candy has appeared! React to this message to claim it.*** 🍬",
Embed: drop,
Content: "🍬 ***Some candy has appeared! React to this message to claim it.*** 🍬",
Embed: drop,
}
s.ChannelMessageSendComplex(channel, ms)
@ -470,6 +481,9 @@ func addCandy(userID string, amount int) {
return
}
query, err := db.Prepare(`UPDATE users SET candy = candy + ? WHERE userID = ?`)
if err != nil {
fmt.Println(err.Error())
}
_, err = query.Exec(amount, userID)
if err != nil {
fmt.Println(err.Error())
@ -483,6 +497,9 @@ func addBuff(userID string, amount int) {
return
}
query, err := db.Prepare(`UPDATE users SET buff = buff + ? WHERE userID = ?`)
if err != nil {
fmt.Println(err.Error())
}
_, err = query.Exec(amount, userID)
if err != nil {
fmt.Println(err.Error())
@ -636,11 +653,12 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
var claimed bool
var tickrate time.Duration
const maxtickrate = 5000 * time.Millisecond
var claimer string
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
tickrate = 200 * time.Millisecond
claimed = false
for i := 0; i < 720; i++ {
reactions, err := s.MessageReactions(m.ChannelID, m.Reference().MessageID, "🍬", 2, "", "")
@ -649,20 +667,31 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
i -= 1
continue
}
if len(reactions) == 0 {
continue
}
if reactions[0].ID == s.State.User.ID {
if len(reactions) <= 1 {
time.Sleep(tickrate)
if tickrate < maxtickrate && i % 5 == 0 {
if tickrate < maxtickrate && i%5 == 0 {
tickrate += 20 * time.Millisecond
}
continue
}
for n, i := range reactions {
if i.ID == s.State.User.ID {
reactions[n] = reactions[len(reactions)-1]
}
}
if len(reactions) == 0 {
time.Sleep(tickrate)
if tickrate < maxtickrate && i%5 == 0 {
tickrate += 20 * time.Millisecond
}
continue
}
claimer = reactions[0].ID
var candyvalue int
bufftype := "none"
buffvalue := 0
var candystr string
maxcandy, _ := topUserCandy()
switch m.Embeds[0].Footer.Text {
case "candyMilky":
candyvalue = 500
@ -681,38 +710,55 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
candyvalue = 200
case "candyKiko":
candyvalue = 500
case "candyChaos":
candyvalue = rand.Intn(maxcandy*2) - maxcandy
default:
candyvalue = 100
}
maxcandy, _ := topUserCandy()
multiplier := "(1x)"
if checkUserCandy(reactions[0].ID) < (maxcandy/4) {
multiplier = "(4x)"
candyvalue = candyvalue * 4
} else if checkUserCandy(reactions[0].ID) < (maxcandy/2) {
multiplier = "(2x)"
candyvalue = candyvalue * 2
}
if !math.Signbit(float64(candyvalue)) {
multiplier := 1
usercandy := checkUserCandy(reactions[0].ID)
if !math.Signbit(float64(candyvalue)) && m.Embeds[0].Footer.Text != "candyChaos" {
if checkUserCandy(claimer) < maxcandy {
if usercandy == 0 {
multiplier = maxcandy / 100
} else {
multiplier = maxcandy / usercandy
}
}
if multiplier > 10 {
multiplier = 10
}
candyvalue *= multiplier
candystr = "+" + fmt.Sprint(candyvalue)
} else { candystr = fmt.Sprint(candyvalue) }
msg := reactions[0].Username + " has claimed the candy! (" + candystr + " 🍬) " + multiplier
} else if m.Embeds[0].Footer.Text != "candyChaos" {
candystr = fmt.Sprint(candyvalue)
} else {
multiplier = rand.Intn(21) - 10
candyvalue *= multiplier
if !math.Signbit(float64(candyvalue)) {
candystr = "+" + fmt.Sprint(candyvalue)
} else {
candystr = fmt.Sprint(candyvalue)
}
}
msg := reactions[0].Username + " has claimed the candy! (" + candystr + " 🍬) (" + fmt.Sprint(multiplier) + "x)"
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)
if !checkUser(claimer) {
addUser(claimer, candyvalue, buffvalue)
} else {
addCandy(reactions[0].ID, candyvalue)
addBuff(reactions[0].ID, buffvalue)
addCandy(claimer, candyvalue)
addBuff(claimer, buffvalue)
}
s.ChannelMessageSend(m.ChannelID, msg)
s.ChannelMessageSend(m.ChannelID, "`DEBUG: " + fmt.Sprint(tickrate) + "`")
claimed = true
if claimed { break }
if claimed {
break
}
}
return
}
@ -1089,7 +1135,14 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
}
if strings.HasPrefix(m.Content, "pp!radma") {
s.ChannelMessageSend(m.ChannelID, "https://cdn.discordapp.com/attachments/946859404819587162/946897683908542494/P10213-191951-1.jpg")
radmeons := []string{
"https://cdn.discordapp.com/attachments/946859404819587162/946897683908542494/P10213-191951-1.jpg",
"https://cdn.discordapp.com/attachments/946459086554275883/1025901158335774800/radmaAmberTurd.jpg",
"https://cdn.discordapp.com/attachments/946459086554275883/1025901158658748519/radmaSpecialOPs.jpg",
"https://cdn.discordapp.com/attachments/946459086554275883/1025901159053021225/radmaWonka.jpg",
"https://cdn.discordapp.com/attachments/946459086554275883/1025901159313047552/Radma_rectal.png",
}
s.ChannelMessageSend(m.ChannelID, radmeons[rand.Intn(len(radmeons))])
}
if strings.HasPrefix(m.Content, "pp!fortune") {
@ -1144,30 +1197,8 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
return
}
if fi.Size() > 1000000 {
fout, err := os.Create("markov-copy.txt")
if err != nil {
print(err.Error())
return
}
defer fout.Close()
_, err = f.Seek(int64(len(m.Content)), io.SeekStart)
if err != nil {
print("DEBUG: Seeking error: " + err.Error() + "\n")
}
bytes_copied, err := io.Copy(fout, f)
if err != nil {
print("DEBUG: Byte copying error: " + err.Error() + "\n")
return
}
print("DEBUG: bytes copied: %d", bytes_copied)
if err := os.Remove("markov.txt"); err != nil {
print("DEBUG: error removing markov.txt: " + err.Error() + "\n")
return
}
if err := os.Rename("markov-copy.txt", "markov.txt"); err != nil {
print(err.Error())
return
if err := os.Truncate("markov.txt", 0); err != nil {
fmt.Println("Failed to truncate: " + err.Error())
}
}
_, err = f.WriteString(m.Content + "\n")
@ -1273,7 +1304,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
}
if strings.HasPrefix(m.Content, "pp!candy") {
s.ChannelMessageSend(m.ChannelID, "Collected candy: " + fmt.Sprint(checkUserCandy(m.Author.ID)))
s.ChannelMessageSend(m.ChannelID, "Collected candy: "+fmt.Sprint(checkUserCandy(m.Author.ID)))
}
if strings.HasPrefix(m.Content, "pp!checkuser") {
@ -1287,7 +1318,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
return
}
ms := &discordgo.MessageSend{
Embed: &discordgo.MessageEmbed{
Embed: &discordgo.MessageEmbed{
Title: "Candy ranking",
Description: rank,
},