Skip to content

Commit

Permalink
Merge branch 'dismod'
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinfuchs committed Feb 12, 2024
2 parents 1169365 + 0cdc4f3 commit 9040ec1
Show file tree
Hide file tree
Showing 69 changed files with 2,571 additions and 3,757 deletions.
2 changes: 0 additions & 2 deletions examples/backup/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions examples/backup/go.mod

This file was deleted.

8 changes: 0 additions & 8 deletions examples/backup/kite.toml

This file was deleted.

118 changes: 0 additions & 118 deletions examples/backup/plugin.go

This file was deleted.

2 changes: 1 addition & 1 deletion examples/counter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module github.com/merlinfuchs/kite/examples/counter
go 1.21.5

require github.com/merlinfuchs/kite/kite-sdk-go v0.0.0
require github.com/merlinfuchs/kite/kite-types v0.0.0
require github.com/merlinfuchs/kite/kite-types v0.0.0
19 changes: 11 additions & 8 deletions examples/counter/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ package main
import (
"strconv"

"github.com/merlinfuchs/dismod/distype"
kite "github.com/merlinfuchs/kite/kite-sdk-go"
"github.com/merlinfuchs/kite/kite-sdk-go/discord"
"github.com/merlinfuchs/kite/kite-sdk-go/kv"
"github.com/merlinfuchs/kite/kite-types/dismodel"

"github.com/merlinfuchs/kite/kite-types/event"
)

const resetMessage = "Wrong counter value! The counter has been reset."
var resetMessage = "Wrong counter value! The counter has been reset."

func main() {
kite.Event(event.DiscordMessageCreate, handleMessageCreateEvent)
}

func handleMessageCreateEvent(req event.Event) error {
msg := req.Data.(dismodel.MessageCreateEvent)
msg := req.Data.(distype.MessageCreateEvent)

if count, err := strconv.Atoi(msg.Content); err == nil {
if err := updateCounter(msg.ChannelID, count); err != nil {
Expand All @@ -28,22 +29,24 @@ func handleMessageCreateEvent(req event.Event) error {
return nil
}

func updateCounter(channelID string, count int) error {
func updateCounter(channelID distype.Snowflake, count int) error {
store := kv.New()

counter, err := store.Increase(channelID, 1)
counter, err := store.Increase(channelID.String(), 1)
if err != nil {
return err
}

if count != counter.Int() {
if _, err := store.Delete(channelID); err != nil {
if _, err := store.Delete(channelID.String()); err != nil {
return err
}

if _, err := discord.MessageCreate(dismodel.MessageCreateCall{
if _, err := discord.MessageCreate(distype.MessageCreateRequest{
ChannelID: channelID,
Content: resetMessage,
MessageCreateParams: distype.MessageCreateParams{
Content: &resetMessage,
},
}); err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions examples/ping/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ module github.com/merlinfuchs/kite/examples/ping
go 1.21.5

require github.com/merlinfuchs/kite/kite-sdk-go v0.0.0
require github.com/merlinfuchs/kite/kite-types v0.0.0

require github.com/merlinfuchs/kite/kite-types v0.0.0
26 changes: 15 additions & 11 deletions examples/ping/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"github.com/merlinfuchs/kite/kite-sdk-go/config"
"github.com/merlinfuchs/kite/kite-sdk-go/discord"
"github.com/merlinfuchs/kite/kite-sdk-go/log"
"github.com/merlinfuchs/kite/kite-types/dismodel"

"github.com/merlinfuchs/dismod/distype"
"github.com/merlinfuchs/kite/kite-types/event"
"github.com/merlinfuchs/kite/kite-types/manifest"
)
Expand All @@ -24,14 +25,16 @@ func main() {
})

kite.Event(event.DiscordMessageCreate, func(req event.Event) error {
msg := req.Data.(dismodel.MessageCreateEvent)
msg := req.Data.(distype.MessageCreateEvent)

if msg.Content == "!ping" {
pingResponse := config.String("ping_response")

_, err := discord.MessageCreate(dismodel.MessageCreateCall{
_, err := discord.MessageCreate(distype.MessageCreateRequest{
ChannelID: msg.ChannelID,
Content: pingResponse,
MessageCreateParams: distype.MessageCreateParams{
Content: &pingResponse,
},
})
if err != nil {
log.Error("Failed to send message: " + err.Error())
Expand All @@ -42,14 +45,15 @@ func main() {
return nil
})

kite.Command("ping", func(i dismodel.Interaction, options []dismodel.ApplicationCommandOptionData) error {
pingResponse := config.String("ping_response")
kite.Command("ping", func(i distype.Interaction, options []distype.ApplicationCommandOption) error {
// pingResponse := config.String("ping_response")

_, err := discord.InteractionResponseCreate(dismodel.InteractionResponseCreateCall{
ID: i.ID,
Token: i.Token,
Data: dismodel.InteractionResponseData{
Content: pingResponse,
_, err := discord.InteractionResponseCreate(distype.InteractionResponseCreateRequest{
InteractionID: i.ID,
InteractionToken: i.Token,
InteractionResponse: distype.InteractionResponse{
Type: distype.InteractionResponseTypeChannelMessageWithSource,
Data: &distype.InteractionMessageResponse{}, // TODO
},
})
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
go 1.21.5

use (
./examples/backup
./examples/counter
./examples/ping
./kite-sdk-go
Expand Down
4 changes: 2 additions & 2 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/flatbuffers v2.0.8+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
Expand All @@ -71,8 +72,6 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksP
github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU=
github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
Expand Down Expand Up @@ -148,6 +147,7 @@ golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
Expand Down
Loading

0 comments on commit 9040ec1

Please sign in to comment.