Skip to content

Commit

Permalink
mod:修改包规范和命名
Browse files Browse the repository at this point in the history
  • Loading branch information
dezhiShen authored and dezhiShen committed Oct 22, 2023
1 parent 0bbc7c9 commit cde4188
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 157 deletions.
81 changes: 81 additions & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package api

import (
"github.com/dezhishen/satori-sdk-go/pkg/client"
"github.com/dezhishen/satori-sdk-go/pkg/config"
)

type SatoriApi interface {
SatoriChannelApi
SatoriGuildApi
SatoriGuildMemberApi
SatoriGuildRoleApi
SatoriLoginApi
SatoriMessageApi
SatoriReactionApi
SatoriUserApi
}

type SatoriApiImpl struct {
SatoriChannelApi
SatoriGuildApi
SatoriGuildMemberApi
SatoriGuildRoleApi
SatoriLoginApi
SatoriMessageApi
SatoriReactionApi
SatoriUserApi
}

func NewSatorApiByConfig(conf config.SatoriConfig) (SatoriApi, error) {
client, err := client.NewApiTemplate(conf.Api)
if err != nil {
return nil, err
}

channelApi, err := newSatoriChannelApi(client)
if err != nil {
return nil, err
}

guildApi, err := newSatoriGuildApi(client)
if err != nil {
return nil, err
}

guildMemberApi, err := newSatoriGuildMemberApi(client)
if err != nil {
return nil, err
}

guildRoleApi, err := newSatoriGuildRoleApi(client)
if err != nil {
return nil, err
}
loginApi, err := newSatoriLoginApi(client)
if err != nil {
return nil, err
}
messageApi, err := newSatoriMessageApi(client)
if err != nil {
return nil, err
}
reactionApi, err := newSatoriReactionApi(client)
if err != nil {
return nil, err
}
userApi, err := newSatoriUserApi(client)
if err != nil {
return nil, err
}
return &SatoriApiImpl{
channelApi,
guildApi,
guildMemberApi,
guildRoleApi,
loginApi,
messageApi,
reactionApi,
userApi,
}, nil
}
33 changes: 17 additions & 16 deletions pkg/resource/channel/api.go → pkg/api/channel.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
package channel
package api

import (
"github.com/dezhishen/satori-sdk-go/pkg/client"
"github.com/dezhishen/satori-sdk-go/pkg/resource/channel"
)

type SatoriChannelApi interface {
ChannelGet(channel_id string) (*Channel, error)
ChannelList(guild_id string, next string) (*ChannelList, error)
ChannelCreate(guild_id string, data Channel) (*Channel, error)
ChannelUpdate(channel_id string, data Channel) error
ChannelGet(channel_id string) (*channel.Channel, error)
ChannelList(guild_id string, next string) (*channel.ChannelList, error)
ChannelCreate(guild_id string, data channel.Channel) (*channel.Channel, error)
ChannelUpdate(channel_id string, data channel.Channel) error
ChannelDelete(channel_id string) error
UserChannelCreate(user_id string) (*Channel, error)
UserChannelCreate(user_id string) (*channel.Channel, error)
}

type satoriChannelApiImpl struct {
cli client.ApiTemplate
}

func NewSatoriChannelApi(cli client.ApiTemplate) (SatoriChannelApi, error) {
func newSatoriChannelApi(cli client.ApiTemplate) (SatoriChannelApi, error) {
return &satoriChannelApiImpl{
cli: cli,
}, nil
}

func (api *satoriChannelApiImpl) ChannelGet(channel_id string) (*Channel, error) {
var result *Channel
func (api *satoriChannelApiImpl) ChannelGet(channel_id string) (*channel.Channel, error) {
var result *channel.Channel
err := api.cli.PostByRequestForResult("/channel.get", map[string]string{
"channel_id": channel_id,
}, &result)
return result, err
}

func (api *satoriChannelApiImpl) ChannelList(guild_id string, next string) (*ChannelList, error) {
var result *ChannelList
func (api *satoriChannelApiImpl) ChannelList(guild_id string, next string) (*channel.ChannelList, error) {
var result *channel.ChannelList
err := api.cli.PostByRequestForResult("/channel.get", map[string]string{
"guild_id": guild_id,
"next": next,
}, &result)
return result, err
}

func (api *satoriChannelApiImpl) ChannelCreate(guild_id string, data Channel) (*Channel, error) {
var result *Channel
func (api *satoriChannelApiImpl) ChannelCreate(guild_id string, data channel.Channel) (*channel.Channel, error) {
var result *channel.Channel
err := api.cli.PostByRequestForResult("/channel.create", map[string]interface{}{
"guild_id": guild_id,
"data": data,
}, &result)
return result, err
}

func (api *satoriChannelApiImpl) ChannelUpdate(channel_id string, data Channel) error {
func (api *satoriChannelApiImpl) ChannelUpdate(channel_id string, data channel.Channel) error {
return api.cli.PostByRequest("/channel.update", map[string]interface{}{
"channel_id": channel_id,
"data": data,
Expand All @@ -62,8 +63,8 @@ func (api *satoriChannelApiImpl) ChannelDelete(channel_id string) error {
})
}

func (api *satoriChannelApiImpl) UserChannelCreate(user_id string) (*Channel, error) {
var result *Channel
func (api *satoriChannelApiImpl) UserChannelCreate(user_id string) (*channel.Channel, error) {
var result *channel.Channel
err := api.cli.PostByRequestForResult("/user.channel.create", map[string]interface{}{
"user_id": user_id,
}, &result)
Expand Down
17 changes: 9 additions & 8 deletions pkg/resource/guild/api.go → pkg/api/guild.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
package guild
package api

import (
"github.com/dezhishen/satori-sdk-go/pkg/client"
"github.com/dezhishen/satori-sdk-go/pkg/resource/guild"
)

type SatoriGuildApi interface {
GuildGet(guild_id string) (*Guild, error)
GuildList(next string) (*GuildList, error)
GuildGet(guild_id string) (*guild.Guild, error)
GuildList(next string) (*guild.GuildList, error)
HandleGuildRequest(message_id string, approve bool, comment string) error
}

type satoriGuildApiImpl struct {
cli client.ApiTemplate
}

func NewSatoriGuildApi(cli client.ApiTemplate) (SatoriGuildApi, error) {
func newSatoriGuildApi(cli client.ApiTemplate) (SatoriGuildApi, error) {
return &satoriGuildApiImpl{cli: cli}, nil
}

func (api *satoriGuildApiImpl) GuildGet(guild_id string) (*Guild, error) {
var result *Guild
func (api *satoriGuildApiImpl) GuildGet(guild_id string) (*guild.Guild, error) {
var result *guild.Guild
err := api.cli.PostByRequestForResult("/guild.get", map[string]string{
"guild_id": guild_id,
}, &result)
return result, err
}

func (api *satoriGuildApiImpl) GuildList(next string) (*GuildList, error) {
var result *GuildList
func (api *satoriGuildApiImpl) GuildList(next string) (*guild.GuildList, error) {
var result *guild.GuildList
err := api.cli.PostByRequestForResult("/guild.list", map[string]string{
"next": next,
}, &result)
Expand Down
17 changes: 9 additions & 8 deletions pkg/resource/guildmember/api.go → pkg/api/guildmember.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package guildmember
package api

import (
"github.com/dezhishen/satori-sdk-go/pkg/client"
"github.com/dezhishen/satori-sdk-go/pkg/resource/guildmember"
)

type SatoriGuildMemberApi interface {
GuildMemberGet(guild_id, user_id string) (*GuildMember, error)
GuildMemberList(guild_id, next string) (*GuildMemberList, error)
GuildMemberGet(guild_id, user_id string) (*guildmember.GuildMember, error)
GuildMemberList(guild_id, next string) (*guildmember.GuildMemberList, error)
GuildMemberKick(guild_id, user_id string, permanent bool) error
GuildMemberApprove(message_id string, approve bool, comment string) error
}
Expand All @@ -15,23 +16,23 @@ type satoriGuildMemberApiImpl struct {
cli client.ApiTemplate
}

func NewSatoriGuildMemberApi(cli client.ApiTemplate) (SatoriGuildMemberApi, error) {
func newSatoriGuildMemberApi(cli client.ApiTemplate) (SatoriGuildMemberApi, error) {
return &satoriGuildMemberApiImpl{
cli: cli,
}, nil

}

func (api *satoriGuildMemberApiImpl) GuildMemberGet(guild_id, user_id string) (*GuildMember, error) {
var result *GuildMember
func (api *satoriGuildMemberApiImpl) GuildMemberGet(guild_id, user_id string) (*guildmember.GuildMember, error) {
var result *guildmember.GuildMember
err := api.cli.PostByRequestForResult("/guild.member.get", map[string]string{
"guild_id": guild_id,
"user_id": user_id,
}, &result)
return result, err
}
func (api *satoriGuildMemberApiImpl) GuildMemberList(guild_id, next string) (*GuildMemberList, error) {
var result *GuildMemberList
func (api *satoriGuildMemberApiImpl) GuildMemberList(guild_id, next string) (*guildmember.GuildMemberList, error) {
var result *guildmember.GuildMemberList
err := api.cli.PostByRequestForResult("/guild.member.list", map[string]string{
"guild_id": guild_id,
"next": next,
Expand Down
21 changes: 11 additions & 10 deletions pkg/resource/guildrole/api.go → pkg/api/guildrole.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package guildrole
package api

import (
"github.com/dezhishen/satori-sdk-go/pkg/client"
"github.com/dezhishen/satori-sdk-go/pkg/resource/guildrole"
)

type SatoriGuildRoleApi interface {
GuildMemberRoleSet(guild_id, user_id, role_id string) error
GuildMemberRoleUnset(guild_id, user_id, role_id string) error
GuildRoleList(guild_id, next string) (*GuildRoleList, error)
GuildRoleCreate(guild_id string, role GuildRole) (*GuildRole, error)
GuildRoleUpdate(guild_id, role_id string, role GuildRole) error
GuildRoleList(guild_id, next string) (*guildrole.GuildRoleList, error)
GuildRoleCreate(guild_id string, role guildrole.GuildRole) (*guildrole.GuildRole, error)
GuildRoleUpdate(guild_id, role_id string, role guildrole.GuildRole) error
GuildRoleDelete(guild_id, role_id string) error
}

type satoriGuildRoleApiImpl struct {
cli client.ApiTemplate
}

func NewSatoriGuildRoleApi(cli client.ApiTemplate) (SatoriGuildRoleApi, error) {
func newSatoriGuildRoleApi(cli client.ApiTemplate) (SatoriGuildRoleApi, error) {
return &satoriGuildRoleApiImpl{
cli: cli,
}, nil
Expand All @@ -39,23 +40,23 @@ func (api *satoriGuildRoleApiImpl) GuildMemberRoleUnset(guild_id, user_id, role_
})
}

func (api *satoriGuildRoleApiImpl) GuildRoleList(guild_id, next string) (*GuildRoleList, error) {
var result *GuildRoleList
func (api *satoriGuildRoleApiImpl) GuildRoleList(guild_id, next string) (*guildrole.GuildRoleList, error) {
var result *guildrole.GuildRoleList
err := api.cli.PostByRequestForResult("/guild.role.list", map[string]string{
"guild_id": guild_id,
"next": next,
}, &result)
return result, err
}
func (api *satoriGuildRoleApiImpl) GuildRoleCreate(guild_id string, role GuildRole) (*GuildRole, error) {
var result *GuildRole
func (api *satoriGuildRoleApiImpl) GuildRoleCreate(guild_id string, role guildrole.GuildRole) (*guildrole.GuildRole, error) {
var result *guildrole.GuildRole
err := api.cli.PostByRequestForResult("/guild.role.create", map[string]interface{}{
"guild_id": guild_id,
"role": role,
}, &result)
return result, err
}
func (api *satoriGuildRoleApiImpl) GuildRoleUpdate(guild_id, role_id string, role GuildRole) error {
func (api *satoriGuildRoleApiImpl) GuildRoleUpdate(guild_id, role_id string, role guildrole.GuildRole) error {
return api.cli.PostByRequest("/guild.role.update", map[string]interface{}{
"guild_id": guild_id,
"role_id": role_id,
Expand Down
Loading

0 comments on commit cde4188

Please sign in to comment.