feat: add message delete/edit logging, improve where command

This commit is contained in:
Jack 2023-09-12 09:48:53 -04:00
parent d8fac24b70
commit 0d757c609d
No known key found for this signature in database
GPG Key ID: AFD9F14834097B8E
5 changed files with 190 additions and 44 deletions

View File

@ -24,48 +24,48 @@ import (
type Location map[string][]float64
var LOCATIONS = Location{
"^(kern|kern kafe|kern cafe|kern center|r\\.w\\. kern center|rw kern center|admissions|financial aid|finaid)$": []float64{42.325490, -72.530425},
"^(bridge|bridge cafe|the bridge)$": []float64{42.32560055268511, -72.53171782489403},
"^(rcc|robert crown center|gym)$": []float64{42.3259021736783, -72.53138568980566},
"^(library|harold f. johnson library center|mail room|post office|hampstore|hamp store|campus store|duplications|it|art gallery|hampshire college art gallery|sparc)$": []float64{42.325503815980404, -72.53234665636477},
"^(cole|the cole|cole science center|csc)$": []float64{42.325005132910455, -72.53264274547023},
"^(mixed nuts)$": []float64{42.32438520935449, -72.53314741618625},
"^(prescott)$": []float64{42.32370121438042, -72.53400755941487},
"^(prescott tavern)$": []float64{42.32330551141666, -72.53410313088433},
"^(c4d|center for design|lemelson building)$": []float64{42.323653164859145, -72.53277277596145},
"^(central records|casa)$": []float64{42.32400565840685, -72.53267685200223},
"^(arts barn|art barn|art)$": []float64{42.323484930985096, -72.53270230871183},
"^(jlc|jerome liebling center)$": []float64{42.32343637951593, -72.53186281901529},
"^(solar canopy)$": []float64{42.3231160046793, -72.5323111913881},
"^(music and dance building|mdb|music|dance)$": []float64{42.32296880488658, -72.53257385728799},
"^(ash|adele simmons hall)$": []float64{42.32286199484466, -72.53189407069387},
"^(carle|the carle|the eric carle museum|the eric carle museum of picture book art)$": []float64{42.32109682435725, -72.53332586596198},
"^(elc|early learning center)$": []float64{42.32130800774271, -72.53485513102083},
"^(multisport center|multisport|weight room|msc)$": []float64{42.32138500151223, -72.53614340300827},
"^(dakin student life center|dslc)$": []float64{42.32313128927387, -72.53022445236283},
"^(merrill student life center|mslc)$": []float64{42.32347857352905, -72.53034306624653},
"^(merrill pavillion|pavillion)$": []float64{42.323322471247494, -72.53030510980373},
"^(dakin|hell|dakin house)$": []float64{42.322597743840625, -72.53027825479788},
"^(merrill|merrill house)$": []float64{42.323732718386175, -72.52977892147766},
"^(dining commons|dc|saga)$": []float64{42.32319356233955, -72.52917576638322},
"^(yiddish book center|ybc)$": []float64{42.32175452980474, -72.5276151025249},
"^(franklin patterson hall|fph)$": []float64{42.324221538083805, -72.5306271019939},
"^(the yurt|yurt|radio)$": []float64{42.324071744881785, -72.53136719263956},
"^(enfield|enfield mods|enfield house)$": []float64{42.32646094303269, -72.52929170510444},
"^(wellness center)$": []float64{42.32709812095117, -72.5291661607627},
"^(spiritual life center|slc)$": []float64{42.32705614551552, -72.52973716786117},
"^(edh|emily dickinson hall|theatre|theater)$": []float64{42.327652942240896, -72.53062317253445},
"^(writing center)$": []float64{42.32780110830725, -72.53112929268784},
"^(greenwich|greenwich mods|greenwich house)$": []float64{42.32748781455265, -72.53192281696715},
"^(soccer|soccer field|hampshire college soccer field)$": []float64{42.32651025401564, -72.53454675256307},
"^(cultural center|cc|lebron-wiggins-pran cultural center|Lebrón-Wiggins-Pran Cultural Center)$": []float64{42.32487763771362, -72.5339769868106},
"^(basketball|basketball courts|basketball court|tennis courts|tennis court)$": []float64{42.32557748709811, -72.53720546848393},
"^(red barn|the red barn|barn)$": []float64{42.32642633315529, -72.52551730246282},
"^(the hitchcock center|hitchcock center|hitchcock center for the environment)$": []float64{42.32771760017527, -72.52570886249646},
"^(csa|farm|hampshire college farm center|hampshire college farm)$": []float64{42.32903799744424, -72.52573139895138},
"^(health services|hampshire college health services)$": []float64{42.32666929509394, -72.52524995366625},
"^(atkins|atkins farms country market)$": []float64{42.319355104827295, -72.52927125654328},
"^(res|the res|the reservoir|reservoir)$": []float64{42.317285834368995, -72.5406219720153},
"^(kern|\"kern kafe\"|\"kern cafe\"|\"kern center\"|\"r\\.w\\. kern center\"|\"rw kern center\"|admissions|\"financial aid\"|finaid)$": []float64{42.325490, -72.530425},
"^(bridge|\"bridge cafe\"|the bridge)$": []float64{42.32560055268511, -72.53171782489403},
"^(rcc|\"robert crown center\"|gym)$": []float64{42.3259021736783, -72.53138568980566},
"^(library|\"harold f. johnson library center\"|\"mail room\"|\"post office\"|hampstore|\"hamp store\"|\"campus store\"|duplications|it|\"art gallery\"|\"hampshire college art gallery\"|sparc)$": []float64{42.325503815980404, -72.53234665636477},
"^(cole|\"the cole\"|\"cole science center\"|csc)$": []float64{42.325005132910455, -72.53264274547023},
"^(\"mixed nuts\")$": []float64{42.32438520935449, -72.53314741618625},
"^(prescott)$": []float64{42.32370121438042, -72.53400755941487},
"^(\"prescott tavern\"|tavern)$": []float64{42.32330551141666, -72.53410313088433},
"^(c4d|\"center for design\"|\"lemelson building\")$": []float64{42.323653164859145, -72.53277277596145},
"^(\"central records\"|casa)$": []float64{42.32400565840685, -72.53267685200223},
"^(\"arts barn\"|\"art barn\"|art)$": []float64{42.323484930985096, -72.53270230871183},
"^(jlc|\"jerome liebling center\")$": []float64{42.32343637951593, -72.53186281901529},
"^(\"solar canopy\")$": []float64{42.3231160046793, -72.5323111913881},
"^(\"music and dance building\"|mdb|music|dance)$": []float64{42.32296880488658, -72.53257385728799},
"^(ash|\"adele simmons hall\")$": []float64{42.32286199484466, -72.53189407069387},
"^(carle|\"the carle\"|\"the eric carle museum\"|\"the eric carle museum of picture book art\")$": []float64{42.32109682435725, -72.53332586596198},
"^(elc|early learning center)$": []float64{42.32130800774271, -72.53485513102083},
"^(\"multisport center\"|multisport|weight room|msc)$": []float64{42.32138500151223, -72.53614340300827},
"^(\"dakin student life center\"|dslc)$": []float64{42.32313128927387, -72.53022445236283},
"^(\"merrill student life center\"|mslc)$": []float64{42.32347857352905, -72.53034306624653},
"^(\"merrill pavillion\"|pavillion)$": []float64{42.323322471247494, -72.53030510980373},
"^(dakin|hell|\"dakin house\")$": []float64{42.322597743840625, -72.53027825479788},
"^(merrill|\"merrill house\")$": []float64{42.323732718386175, -72.52977892147766},
"^(\"dining commons\"|dc|saga)$": []float64{42.32319356233955, -72.52917576638322},
"^(\"yiddish book center\"|ybc)$": []float64{42.32175452980474, -72.5276151025249},
"^(\"franklin patterson hall\"|fph)$": []float64{42.324221538083805, -72.5306271019939},
"^(\"the yurt\"|yurt|radio)$": []float64{42.324071744881785, -72.53136719263956},
"^(enfield|\"enfield mods\"|\"enfield house\")$": []float64{42.32646094303269, -72.52929170510444},
"^(\"wellness center\")$": []float64{42.32709812095117, -72.5291661607627},
"^(\"spiritual life center\"|slc)$": []float64{42.32705614551552, -72.52973716786117},
"^(edh|\"emily dickinson hall\"|theatre|theater)$": []float64{42.327652942240896, -72.53062317253445},
"^(\"writing center\")$": []float64{42.32780110830725, -72.53112929268784},
"^(greenwich|\"greenwich mods\"|\"greenwich house\")$": []float64{42.32748781455265, -72.53192281696715},
"^(soccer|\"soccer field\"|\"hampshire college soccer field\")$": []float64{42.32651025401564, -72.53454675256307},
"^(\"cultural center\"|cc|\"lebron-wiggins-pran cultural center\"|\"Lebrón-Wiggins-Pran Cultural Center\")$": []float64{42.32487763771362, -72.5339769868106},
"^(basketball|\"basketball courts\"|\"basketball court\"|\"tennis courts\"|\"tennis court\")$": []float64{42.32557748709811, -72.53720546848393},
"^(\"red barn\"|\"the red barn\"|barn)$": []float64{42.32642633315529, -72.52551730246282},
"^(\"the hitchcock center\"|\"hitchcock center\"|\"hitchcock center for the environment\")$": []float64{42.32771760017527, -72.52570886249646},
"^(csa|farm|\"hampshire college farm center\"|\"hampshire college farm\")$": []float64{42.32903799744424, -72.52573139895138},
"^(\"health services\"|\"hampshire college health services\")$": []float64{42.32666929509394, -72.52524995366625},
"^(atkins|\"atkins farms country market\")$": []float64{42.319355104827295, -72.52927125654328},
"^(res|\"the res\"|the reservoir|reservoir)$": []float64{42.317285834368995, -72.5406219720153},
}
type Where struct {
@ -103,8 +103,35 @@ func (c *Where) IsExecutableInDMChannels() bool {
func (c *Where) Exec(ctx shireikan.Context) error {
if len(ctx.GetArgs()) < 1 {
ctx.GetSession().ChannelMessageSend(ctx.GetChannel().ID, "Please specify a building.")
return nil
// return all buildings
e := embed.NewSuccessEmbed(ctx)
e.SetTitle("Buildings")
desc := ""
locs := []string{}
for regex := range LOCATIONS {
l := strings.TrimLeft(regex, "^(")
l = strings.TrimRight(l, ")$")
ls := strings.Split(l, "|")
for _, l := range ls {
locs = append(locs, l)
}
desc += fmt.Sprintf("`%s`, ", strings.Join(ls, "`, `"))
}
e.SetDescription(desc)
_, err := ctx.GetSession().ChannelMessageSendComplex(ctx.GetChannel().ID, &discordgo.MessageSend{
Embed: e.MessageEmbed,
Reference: ctx.GetMessage().Reference(),
})
return err
}
to := strings.ToLower(ctx.GetArgs().Get(0).AsString())

View File

@ -0,0 +1,49 @@
package listeners
import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/jackmerrill/hampbot/internal/utils/config"
)
type MessageDeleteListener struct{}
const CHANNEL_ID = "1150951087323496450"
func (l *MessageDeleteListener) Exec(s *discordgo.Session, e *discordgo.MessageDelete) {
var msg = discordgo.Message{}
fields := []*discordgo.MessageEmbedField{}
if m, ok := config.MessageLog[e.ID]; ok {
msg = m
fields = append(fields, &discordgo.MessageEmbedField{
Name: "Author",
Value: fmt.Sprintf("<@%s>", msg.Author.ID),
Inline: true,
})
} else {
msg.Content = "Unknown, untracked message."
msg.ChannelID = e.ChannelID
}
fields = append(fields, &discordgo.MessageEmbedField{
Name: "Channel",
Value: fmt.Sprintf("<#%s>", e.ChannelID),
Inline: true,
})
_, err := s.ChannelMessageSendComplex(CHANNEL_ID, &discordgo.MessageSend{
Content: "Message deleted",
Embed: &discordgo.MessageEmbed{
Title: "Message deleted",
Description: msg.Content,
Fields: fields,
Color: 0xff0000,
},
})
if err != nil {
panic(err)
}
}

View File

@ -0,0 +1,54 @@
package listeners
import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/jackmerrill/hampbot/internal/utils/config"
)
type MessageEditListener struct{}
func (l *MessageEditListener) Exec(s *discordgo.Session, e *discordgo.MessageUpdate) {
var old discordgo.Message
fields := []*discordgo.MessageEmbedField{
{
Name: "Author",
Value: fmt.Sprintf("<@%s>", e.Author.ID),
Inline: true,
},
{
Name: "Channel",
Value: fmt.Sprintf("<#%s>", e.ChannelID),
Inline: true,
},
}
if o, ok := config.MessageLog[e.ID]; ok {
old = o
fields = append(fields, &discordgo.MessageEmbedField{
Name: "Old",
Value: old.Content,
Inline: false,
})
}
fields = append(fields, &discordgo.MessageEmbedField{
Name: "New",
Value: e.Content,
Inline: false,
})
_, err := s.ChannelMessageSendComplex(CHANNEL_ID, &discordgo.MessageSend{
Embed: &discordgo.MessageEmbed{
Title: "Message edited",
Fields: fields,
Color: 0xffff00,
},
})
if err != nil {
panic(err)
}
}

View File

@ -37,6 +37,10 @@ var (
GroupStudentLife = "Student Life"
)
type LoggedMessages = map[string]discordgo.Message
var MessageLog LoggedMessages = make(LoggedMessages)
var Statuses = []discordgo.Activity{
{
Name: "with frogs",

12
main.go
View File

@ -11,6 +11,7 @@ import (
"github.com/jackmerrill/hampbot/internal/commands/fun"
studentlife "github.com/jackmerrill/hampbot/internal/commands/studentlife"
util "github.com/jackmerrill/hampbot/internal/commands/util"
"github.com/jackmerrill/hampbot/internal/listeners"
"github.com/jackmerrill/hampbot/internal/utils/config"
"github.com/jackmerrill/hampbot/internal/utils/embed"
"github.com/zekroTJA/shireikan"
@ -115,6 +116,17 @@ func main() {
}
}()
log.Info("Setting up listeners...")
deleteHandler := &listeners.MessageDeleteListener{}
editHandler := &listeners.MessageEditListener{}
session.AddHandler(func(s *discordgo.Session, e *discordgo.MessageCreate) {
config.MessageLog[e.ID] = *e.Message
})
session.AddHandler(deleteHandler.Exec)
session.AddHandler(editHandler.Exec)
handler.Setup(session)
log.Info("Bot is now running. Press CTRL-C to exit.")