Cleaning up
This commit is contained in:
85
main.go
85
main.go
@ -23,6 +23,7 @@ var (
|
||||
ghostWritingEmoji = "📖"
|
||||
emf5Emoji = "🚥"
|
||||
ghostOrbsEmoji = "⚪"
|
||||
deleteEmoji = "❌"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -61,10 +62,17 @@ func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||
}
|
||||
|
||||
func readReactions(s *discordgo.Session, m *discordgo.MessageReactionAdd) {
|
||||
if _, ok := games[m.ChannelID]; !ok {
|
||||
if m.UserID == s.State.User.ID {
|
||||
return
|
||||
}
|
||||
if m.UserID == s.State.User.ID {
|
||||
if m.Emoji.Name == deleteEmoji {
|
||||
msg, _ := s.ChannelMessage(m.ChannelID, m.MessageID)
|
||||
if msg.Author.ID == s.State.User.ID {
|
||||
s.ChannelMessageDelete(m.ChannelID, m.MessageID)
|
||||
}
|
||||
return
|
||||
}
|
||||
if _, ok := games[m.ChannelID]; !ok {
|
||||
return
|
||||
}
|
||||
fmt.Println("Checking reaction from ", m.UserID)
|
||||
@ -109,7 +117,9 @@ func readReactions(s *discordgo.Session, m *discordgo.MessageReactionAdd) {
|
||||
}
|
||||
if len(g.Evidence) == 3 {
|
||||
s.GuildMemberNickname(m.GuildID, "@me", "")
|
||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%+v was a %+v", g.Ghost.GhostName, g.PossibleGhosts[0].GhostType))
|
||||
msg, _ := s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%+v was a %+v", g.Ghost.GhostName, g.PossibleGhosts[0].GhostType))
|
||||
s.MessageReactionAdd(m.ChannelID, g.PostID, deleteEmoji)
|
||||
s.MessageReactionAdd(m.ChannelID, msg.ID, deleteEmoji)
|
||||
}
|
||||
|
||||
games[m.ChannelID] = g
|
||||
@ -128,18 +138,19 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
}
|
||||
g := games[m.ChannelID]
|
||||
parts := strings.Split(m.Content, " ")
|
||||
if strings.HasPrefix(m.Content, "!map") {
|
||||
g.MapName = parts[1]
|
||||
}
|
||||
if strings.HasPrefix(m.Content, "!name") {
|
||||
g.Ghost.GhostName = strings.Join(parts[1:], " ")
|
||||
s.GuildMemberNickname(m.GuildID, "@me", g.Ghost.GhostName)
|
||||
}
|
||||
if strings.HasPrefix(m.Content, "!difficulty") {
|
||||
g.Difficulty = parts[1]
|
||||
}
|
||||
if strings.HasPrefix(m.Content, "!room") {
|
||||
if len(parts) == 2 {
|
||||
g.RoomID = parts[1]
|
||||
} else {
|
||||
if g.RoomID != "" {
|
||||
msg, _ := s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("The room code is `%+v`", g.RoomID))
|
||||
s.MessageReactionAdd(m.ChannelID, msg.ID, deleteEmoji)
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(m.Content, "!o") {
|
||||
if strings.Contains(m.Content, "emf") {
|
||||
@ -179,7 +190,45 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
g.Objective = append(g.Objective, NoDeaths)
|
||||
}
|
||||
}
|
||||
if len(g.Objective) == 3 {
|
||||
if strings.HasPrefix(m.Content, "!c") {
|
||||
if strings.Contains(m.Content, "emf") {
|
||||
g.CompleteObjective(EMF)
|
||||
}
|
||||
if strings.Contains(m.Content, "photo") {
|
||||
g.CompleteObjective(Photo)
|
||||
}
|
||||
if strings.Contains(m.Content, "event") {
|
||||
g.CompleteObjective(Event)
|
||||
}
|
||||
if strings.Contains(m.Content, "crucifix") {
|
||||
g.CompleteObjective(Crucifix)
|
||||
}
|
||||
if strings.Contains(m.Content, "motion") {
|
||||
g.CompleteObjective(Motion)
|
||||
}
|
||||
if strings.Contains(m.Content, "clean") {
|
||||
g.CompleteObjective(SmudgeCleanse)
|
||||
}
|
||||
if strings.Contains(m.Content, "hunt") {
|
||||
g.CompleteObjective(SmudgeHunt)
|
||||
}
|
||||
if strings.Contains(m.Content, "salt") {
|
||||
g.CompleteObjective(Salt)
|
||||
}
|
||||
if strings.Contains(m.Content, "candle") {
|
||||
g.CompleteObjective(Candle)
|
||||
}
|
||||
if strings.Contains(m.Content, "sanity") {
|
||||
g.CompleteObjective(LowSanity)
|
||||
}
|
||||
if strings.Contains(m.Content, "escape") {
|
||||
g.CompleteObjective(MemberEscape)
|
||||
}
|
||||
if strings.Contains(m.Content, "death") {
|
||||
g.CompleteObjective(NoDeaths)
|
||||
}
|
||||
}
|
||||
if len(g.Objective) == 3 && g.PostID == "" {
|
||||
post, _ := s.ChannelMessageSend(m.ChannelID, "The investigation begins! Click below to log evidence.")
|
||||
g.PossibleGhosts = append(g.PossibleGhosts, ghostTypes...)
|
||||
g.PostID = post.ID
|
||||
@ -193,3 +242,19 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
|
||||
games[m.ChannelID] = g
|
||||
}
|
||||
|
||||
func (g *Game) CompleteObjective(objective int) {
|
||||
var tasks []int
|
||||
ret := "Current objectives: ```"
|
||||
for _, v := range g.Objective {
|
||||
if v != objective {
|
||||
tasks = append(tasks, v)
|
||||
ret += fmt.Sprintf("%+v\n", objectiveToStr(v))
|
||||
}
|
||||
}
|
||||
ret += "```"
|
||||
msg, _ := dg.ChannelMessageSend(g.Identifier, ret)
|
||||
dg.MessageReactionAdd(g.Identifier, msg.ID, deleteEmoji)
|
||||
g.Objective = tasks
|
||||
games[g.Identifier] = *g
|
||||
}
|
||||
|
||||
52
types.go
52
types.go
@ -10,6 +10,25 @@ const (
|
||||
GhostOrbs // 5
|
||||
)
|
||||
|
||||
func evidenceToStr(tag int) string {
|
||||
switch tag {
|
||||
case 0:
|
||||
return "EMF5"
|
||||
case 1:
|
||||
return "Freezing Temps"
|
||||
case 2:
|
||||
return "Spirit Box"
|
||||
case 3:
|
||||
return "Ghost Writing"
|
||||
case 4:
|
||||
return "Fingerprints"
|
||||
case 5:
|
||||
return "Ghost Orbs"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// Bonus Objectives
|
||||
const (
|
||||
Photo = iota
|
||||
@ -26,15 +45,44 @@ const (
|
||||
NoDeaths
|
||||
)
|
||||
|
||||
func objectiveToStr(tag int) string {
|
||||
switch tag {
|
||||
case 0:
|
||||
return "Capture a photo of the ghost."
|
||||
case 1:
|
||||
return "Witness a ghost event."
|
||||
case 2:
|
||||
return "Get the ghost to walk through a motion sensor."
|
||||
case 3:
|
||||
return "Stop a hunt with a crucifix."
|
||||
case 4:
|
||||
return "Get an EMF reading."
|
||||
case 5:
|
||||
return "Cleanse the area around the ghost with a Smudge stick."
|
||||
case 6:
|
||||
return "Smudge the ghost during a hunt."
|
||||
case 7:
|
||||
return "Get the ghost to walk through salt."
|
||||
case 8:
|
||||
return "Get the ghost to blow out a candle."
|
||||
case 9:
|
||||
return "Get an average sanity of below 25%."
|
||||
case 10:
|
||||
return "Have a mamber of your team escape a ghost hunt."
|
||||
case 11:
|
||||
return "Complete the investigation with no deaths."
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// Game for Phasbot
|
||||
type Game struct {
|
||||
Identifier string
|
||||
PostID string
|
||||
MapName string
|
||||
Ghost Spookster
|
||||
PossibleGhosts []Spookster
|
||||
PossibleEvidence []int
|
||||
Difficulty string
|
||||
RoomID string
|
||||
Evidence []int
|
||||
Objective []int
|
||||
|
||||
Reference in New Issue
Block a user