@@ -21,10 +21,10 @@ var mineTriggerMessages = []string{
2121 "<user> triggered a mine.\n Press F to pay respects." ,
2222 "<user> stepped on a mine and didn't have enough Explosion Resistance." ,
2323 "<user> found a hidden mine! Sadly, it blew up when they picked it up." ,
24- "<user> just won the Big Mine Lottery! Enjoy your ( role) prize." ,
25- "This channel was NOT safe. Goodbye <user>." ,
24+ "<user> just won the Big Mine Lottery! Enjoy your < role> prize." ,
25+ "This channel was NOT safe. <user> blew up, goodbye ." ,
2626 "R.I.P. <user>\n \n Spoke at the wrong time and place.\n \n <joinyear> - <curryear>" ,
27- "Mine detected. Oh wait - too late for <user>." ,
27+ "Mine detected. Oh wait, too late for <user>." ,
2828 "!mineexplode <user>" ,
2929 // Game references
3030 "Rocketboo missed the Ethereal and hit <user> instead!" ,
@@ -35,7 +35,7 @@ var mineTriggerMessages = []string{
3535type PlaceMinesQueryInput struct {
3636 Where string `short:"w" long:"where" default:""` // Channel id, or empty for whole guild
3737 Guild string `short:"g" long:"guild" default:""` // Guild id, for admin user
38- ChancePercentage float64 `short:"c" long:"chance" default:"5 .0"` // 5.0 = 5%
38+ ChancePercentage float64 `short:"c" long:"chance" default:"1 .0"` // 5.0 = 5%
3939 Amount int `short:"a" long:"amount" default:"10"` // Amount of mines
4040 Duration string `short:"d" long:"duration" default:"2m"` // 99h99m99s
4141 CustomMessage string `short:"m" long:"custom_message" default:""` // Custom message that replaces the default ones
@@ -48,7 +48,7 @@ func answerPlaceMines(ds *discordgo.Session, mc *discordgo.MessageCreate, ctx co
4848 return false
4949 }
5050
51- if len (existing ) >= minesMaxSetsPerGuild {
51+ if len (existing ) >= minesMaxSetsPerGuild && mc . Author . ID != adminID {
5252 ds .ChannelMessageSend (mc .ChannelID , "You have too many mine sets in this server!" )
5353 return false
5454 }
@@ -65,7 +65,7 @@ func answerPlaceMines(ds *discordgo.Session, mc *discordgo.MessageCreate, ctx co
6565 return false
6666 }
6767
68- if len (input .CustomMessage ) > minesMaxCustomMessageLength {
68+ if len (input .CustomMessage ) > minesMaxCustomMessageLength && mc . Author . ID != adminID {
6969 ds .ChannelMessageSend (mc .ChannelID , "That custom message is too long." )
7070 return false
7171 }
@@ -90,8 +90,34 @@ func answerPlaceMines(ds *discordgo.Session, mc *discordgo.MessageCreate, ctx co
9090 return true
9191}
9292
93+ type CheckMinesQueryInput struct {
94+ Guild string `short:"g" long:"guild" default:""` // Guild id, for admin user
95+ }
96+
9397func answerCheckMines (ds * discordgo.Session , mc * discordgo.MessageCreate , ctx context.Context ) bool {
94- mines , err := serverDS .getMinesByGuild (mc .GuildID )
98+ var input CheckMinesQueryInput
99+ err := parseCommandArgs (& input , mc .Content )
100+ if err != nil {
101+ ds .ChannelMessageSend (mc .ChannelID , "Wrong format error: " + err .Error ())
102+ return false
103+ }
104+ var guildID string
105+ var guildName string
106+
107+ if input .Guild != "" && mc .Author .ID == adminID {
108+ guildID = input .Guild
109+ guild , err := ds .Guild (guildID )
110+ if err != nil {
111+ ds .ChannelMessageSend (mc .ChannelID , "Could not find Guild: " + err .Error ())
112+ return false
113+ }
114+ guildName = guild .Name
115+ } else {
116+ guildID = mc .GuildID
117+ guildName = "this server"
118+ }
119+
120+ mines , err := serverDS .getMinesByGuild (guildID )
95121 if err != nil {
96122 adminNotifyIfErr ("answerCheckMines" , err , ds )
97123 return false
@@ -108,8 +134,8 @@ func answerCheckMines(ds *discordgo.Session, mc *discordgo.MessageCreate, ctx co
108134
109135 if m .ChannelID == "" {
110136 fmt .Fprintf (& b ,
111- "ID: %d, %d mines in this server with %.4f%% chance of exploding." ,
112- m .ID , m .Amount , percent )
137+ "ID: %d, %d mines in %s with %.4f%% chance of exploding." ,
138+ m .ID , m .Amount , guildName , percent )
113139 } else {
114140 fmt .Fprintf (& b ,
115141 "ID: %d, %d mines in channel <#%s> with %.4f%% chance of exploding." ,
@@ -191,7 +217,7 @@ func processMinesetTrigger(ds *discordgo.Session, mc *discordgo.MessageCreate, m
191217 }
192218
193219 // Normal mine logic
194- message := buildMineMessage (mc , mineset )
220+ message := buildMineMessage (ds , mc , mineset )
195221 _ , err = ds .ChannelMessageSend (mc .ChannelID , message )
196222 serverNotifyIfErr ("Mine message could not be sent" , err , mc .GuildID , ds )
197223 if err := ds .GuildMemberRoleAdd (mc .GuildID , mc .Author .ID , timeoutRole .ID ); err == nil {
@@ -200,15 +226,21 @@ func processMinesetTrigger(ds *discordgo.Session, mc *discordgo.MessageCreate, m
200226 }
201227}
202228
203- func buildMineMessage (mc * discordgo.MessageCreate , mineset * MineSet ) string {
229+ func buildMineMessage (ds * discordgo. Session , mc * discordgo.MessageCreate , mineset * MineSet ) string {
204230 var message string
205231 if strings .TrimSpace (mineset .CustomMessage ) != "" {
206232 message = mineset .CustomMessage
207233 } else {
208234 message = rngx .Pick (mineTriggerMessages )
209235 }
236+ // cheap replacements
210237 message = strings .Replace (message , "<user>" , mc .Author .Mention (), 1 )
211238 message = strings .Replace (message , "<joinyear>" , mc .Member .JoinedAt .Format ("2006" ), 1 )
212239 message = strings .Replace (message , "<curryear>" , time .Now ().Format ("2006" ), 1 )
240+ // more expensive replacements
241+ if strings .Contains (message , "<role>" ) {
242+ rolename := getTimeoutRoleName (ds , mc .GuildID )
243+ message = strings .Replace (message , "<role>" , rolename , 1 )
244+ }
213245 return message
214246}
0 commit comments