Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
zekroTJA committed Oct 17, 2020
2 parents 865a5db + c250b13 commit 8dd08dd
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 9 deletions.
15 changes: 9 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ module github.com/zekroTJA/shinpuru
go 1.13

require (
github.com/andybalholm/brotli v1.0.1 // indirect
github.com/blend/go-sdk v2.0.0+incompatible // indirect
github.com/bwmarrin/discordgo v0.22.0
github.com/bwmarrin/snowflake v0.3.0
github.com/dayvonjersen/sadbox v0.0.0-20120828195626-27893f92b8ce // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gabriel-vasile/mimetype v1.1.1
github.com/generaltso/vibrant v0.0.0-20200703055536-90f922bee78c
github.com/go-ini/ini v1.58.0 // indirect
github.com/go-ini/ini v1.62.0 // indirect
github.com/go-ozzo/ozzo-routing v2.1.4+incompatible // indirect
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/gddo v0.0.0-20200715224205-051695c33a3f // indirect
github.com/google/go-cmp v0.5.1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/klauspost/compress v1.11.1 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/makeworld-the-better-one/go-isemoji v1.1.0
github.com/mattn/go-sqlite3 v2.0.3+incompatible
Expand All @@ -29,14 +31,15 @@ require (
github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87
github.com/sahilm/fuzzy v0.1.0
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/valyala/fasthttp v1.15.1
github.com/valyala/fasthttp v1.16.0
github.com/wcharczuk/go-chart v2.0.1+incompatible
github.com/zekroTJA/ratelimit v0.0.0-20190321090824-219ca33049a5
github.com/zekroTJA/shireikan v0.3.1
github.com/zekroTJA/shireikan v0.3.3
github.com/zekroTJA/timedmap v1.2.0
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect
golang.org/x/image v0.0.0-20200801110659-972c09e46d76 // indirect
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed // indirect
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 // indirect
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 // indirect
golang.org/x/sys v0.0.0-20201017003518-b09fb700fbb7 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
gopkg.in/ini.v1 v1.58.0 // indirect
gopkg.in/yaml.v2 v2.3.0
Expand Down
24 changes: 24 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cloud.google.com/go v0.16.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4=
github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc=
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/blend/go-sdk v2.0.0+incompatible h1:FL9X/of4ZYO5D2JJNI4vHrbXPfuSDbUa7h8JP9+E92w=
github.com/blend/go-sdk v2.0.0+incompatible/go.mod h1:3GUb0YsHFNTJ6hsJTpzdmCUl05o8HisKjx5OAlzYKdw=
github.com/bradfitz/gomemcache v0.0.0-20170208213004-1952afaa557d/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
Expand All @@ -27,6 +29,8 @@ github.com/generaltso/vibrant v0.0.0-20200703055536-90f922bee78c h1:lSVqQVSCCCOz
github.com/generaltso/vibrant v0.0.0-20200703055536-90f922bee78c/go.mod h1:QmLK0QXa+OA/VI1WiQNTCuqWgzF16WxDcKqQ6MIPr6Q=
github.com/go-ini/ini v1.58.0 h1:cgk7et3XWr6o1NWWcEUEVao/AYecQQg50XXU+xOX0nM=
github.com/go-ini/ini v1.58.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-ini/ini v1.62.0 h1:7VJT/ZXjzqSrvtraFp4ONq80hTcRQth1c9ZnQ3uNQvU=
github.com/go-ini/ini v1.62.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-ozzo/ozzo-routing v2.1.4+incompatible h1:gQmNyAwMnBHr53Nma2gPTfVVc6i2BuAwCWPam2hIvKI=
github.com/go-ozzo/ozzo-routing v2.1.4+incompatible/go.mod h1:hvoxy5M9SJaY0viZvcCsODidtUm5CzRbYKEWuQpr+2A=
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
Expand Down Expand Up @@ -70,6 +74,8 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg=
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.11.1 h1:bPb7nMRdOZYDrpPMTA3EInUQrdgoBinqUuSwlGdKDdE=
github.com/klauspost/compress v1.11.1/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down Expand Up @@ -126,21 +132,32 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.15.1 h1:eRb5jzWhbCn/cGu3gNJMcOfPUfXgXCcQIOHjh9ajAS8=
github.com/valyala/fasthttp v1.15.1/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA=
github.com/valyala/fasthttp v1.16.0 h1:9zAqOYLl8Tuy3E5R6ckzGDJ1g8+pw15oQp2iL9Jl6gQ=
github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/wcharczuk/go-chart v2.0.1+incompatible h1:0pz39ZAycJFF7ju/1mepnk26RLVLBCWz1STcD3doU0A=
github.com/wcharczuk/go-chart v2.0.1+incompatible/go.mod h1:PF5tmL4EIx/7Wf+hEkpCqYi5He4u90sw+0+6FhrryuE=
github.com/zekroTJA/ratelimit v0.0.0-20190321090824-219ca33049a5 h1:EryoK8mdGm7qU0FZjxpt+7Bd9VGBmzsV880DQKq10W4=
github.com/zekroTJA/ratelimit v0.0.0-20190321090824-219ca33049a5/go.mod h1:5aXVBC8pKM3Tva/5YihZ0yOLD+ULDq5P73lpRuBSLNg=
github.com/zekroTJA/shireikan v0.3.1 h1:47yGg4JS+OH9pRAFd1lEyqxhe62TLzlcbavy89cE7rY=
github.com/zekroTJA/shireikan v0.3.1/go.mod h1:RwaE2svJ/dUzKIpw04gC0loA5rWAMU8eKKCRDnmck+4=
github.com/zekroTJA/shireikan v0.3.2 h1:rBJh2g/HDFQm8zAyA+f4lEpiPYLKIGUqjMsUGlV6+uc=
github.com/zekroTJA/shireikan v0.3.2/go.mod h1:RwaE2svJ/dUzKIpw04gC0loA5rWAMU8eKKCRDnmck+4=
github.com/zekroTJA/shireikan v0.3.3 h1:sJ5ZjRBb1XxVQy+z312OluV6ViS2SVgLu0M+0ufoerw=
github.com/zekroTJA/shireikan v0.3.3/go.mod h1:RwaE2svJ/dUzKIpw04gC0loA5rWAMU8eKKCRDnmck+4=
github.com/zekroTJA/timedmap v1.2.0 h1:6HqQF89K7oEYatCEuS7ylZSFkL8Yf7luJyBTbgAafyI=
github.com/zekroTJA/timedmap v1.2.0/go.mod h1:ktlw5aYhoXQvOvWFL9SzltGXn1bQgJXxZzHJK4wQvsI=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/image v0.0.0-20200801110659-972c09e46d76 h1:U7GPaoQyQmX+CBRWXKrvRzWTbd+slqeSh8uARsIyhAw=
golang.org/x/image v0.0.0-20200801110659-972c09e46d76/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM=
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -149,6 +166,8 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 h1:AeiKBIuRw3UomYXSbLy0Mc2dD
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 h1:5kGOVHlq0euqwzgTC9Vu15p6fV1Wi0ArVi8da2urnVg=
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/oauth2 v0.0.0-20170912212905-13449ad91cb2/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20170517211232-f52d1811a629/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -164,9 +183,14 @@ golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm8DvrYsvrBZdunYeIuQ=
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201017003518-b09fb700fbb7 h1:XtNJkfEjb4zR3q20BBBcYUykVOEMgZeIUOpBPfNYgxg=
golang.org/x/sys v0.0.0-20201017003518-b09fb700fbb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20170424234030-8be79e1e0910/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
16 changes: 13 additions & 3 deletions internal/commands/cmdlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func (c *CmdLock) getTargetChan(ctx shireikan.Context) (ch *discordgo.Channel, e
}

func (c *CmdLock) lock(target *discordgo.Channel, ctx shireikan.Context, db database.Database) error {
procMsg := util.SendEmbed(ctx.GetSession(), target.ID, ":clock4: Locking channel...", "", static.ColorEmbedGray)
if procMsg.Error() != nil {
return procMsg.Error()
}

encodedPerms, err := c.encodePermissionOverrides(target.PermissionOverwrites)
if err != nil {
return err
Expand Down Expand Up @@ -118,7 +123,7 @@ func (c *CmdLock) lock(target *discordgo.Channel, ctx shireikan.Context, db data

// The info message needs to be sent before all permissions are set
// to prevent occuring errors due to potential missing permissions.
err = util.SendEmbed(ctx.GetSession(), target.ID,
err = procMsg.Edit(
fmt.Sprintf("This channel is chat-locked by %s.\nYou may not be able to chat "+
"into this channel until the channel is unlocked again.", ctx.GetUser().Mention()),
"", static.ColorEmbedOrange).
Expand Down Expand Up @@ -168,6 +173,11 @@ func (c *CmdLock) lock(target *discordgo.Channel, ctx shireikan.Context, db data
}

func (c *CmdLock) unlock(target *discordgo.Channel, ctx shireikan.Context, db database.Database, executorID, encodedPerms string) error {
procMsg := util.SendEmbed(ctx.GetSession(), target.ID, ":clock4: Unlocking channel...", "", static.ColorEmbedGray)
if procMsg.Error() != nil {
return procMsg.Error()
}

permissionOverrides, err := c.decodePermissionOverrrides(encodedPerms)
if err != nil {
return err
Expand All @@ -185,14 +195,14 @@ func (c *CmdLock) unlock(target *discordgo.Channel, ctx shireikan.Context, db da
}

if failed > 0 {
return util.SendEmbed(ctx.GetSession(), target.ID,
return procMsg.Edit(
fmt.Sprintf("This channel is now unlocked. You can now chat here again.\n*(Unlocked by %s)*\n\n"+
"**Attention:** %d permission actions failed on reset!", ctx.GetUser().Mention(), failed),
"", static.ColorEmbedOrange).
Error()
}

return util.SendEmbed(ctx.GetSession(), target.ID,
return procMsg.Edit(
fmt.Sprintf("This channel is now unlocked. You can now chat here again.\n*(Unlocked by %s)*", ctx.GetUser().Mention()),
"", static.ColorEmbedGreen).
Error()
Expand Down
1 change: 1 addition & 0 deletions internal/core/middleware/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (m *PermissionsMiddleware) Handle(
if !ok {
msg, _ := ctx.ReplyEmbedError("You are not permitted to use this command!", "Missing Permission")
discordutil.DeleteMessageLater(ctx.GetSession(), msg, 8*time.Second)
return false, nil
}

return true, nil
Expand Down
25 changes: 25 additions & 0 deletions internal/util/embeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@ func (emb *EmbedMessage) Error() error {
return emb.err
}

// Edit updates the current embed message with
// the given content replacing the internal message
// and error of this embed instance.
func (emb *EmbedMessage) Edit(content string, title string, color int) *EmbedMessage {
newEmb := &discordgo.MessageEmbed{
Description: content,
Color: color,
}

newEmb.Title = title
if color == 0 {
newEmb.Color = static.ColorEmbedDefault
}

return emb.EditRaw(newEmb)
}

// EditRaw updates the current embed message with
// the given raw embed replacing the internal message
// and error of this embed instance.
func (emb *EmbedMessage) EditRaw(newEmb *discordgo.MessageEmbed) *EmbedMessage {
emb.Message, emb.err = emb.s.ChannelMessageEditEmbed(emb.ChannelID, emb.ID, newEmb)
return emb
}

// SendEmbed creates an discordgo.MessageEmbed from the passed
// content, title and color and sends it to the specified channel.
//
Expand Down

0 comments on commit 8dd08dd

Please sign in to comment.