-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.go
93 lines (80 loc) · 3.75 KB
/
services.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package services
import (
"fmt"
)
//Service requires various methods for the rest of the command framework to function.
// A dummy service can be used if you're looking to import a particular feature absent a service.
type Service interface {
//Just bot things, yanno
Shutdown() //Shuts down the service as gracefully as possible
CmdPrefix() string //Returns the command prefix to use on this service
Login() (err error) //Login to the chat service
//Messages are the backbone of how the command framework responds to interactions and interacts with the service.
// For services only able to process text messages, you can use Message.String() to get a preformatted text when necessary.
// In the case of other concepts such as Discord's interaction events, use Message.Context to track the alternative type.
MsgEdit(msg *Message) (ret *Message, err error) //Edits any type of message
MsgRemove(msg *Message) (err error) //Removes a message
MsgSend(msg *Message, ref interface{}) (ret *Message, err error) //Sends any type of message
//Users are who can send and receive messages, and can be actioned upon through various commands.
GetUser(serverID, userID string) (ret *User, err error) //Returns the specified user
GetUserPerms(serverID, channelID, userID string) (ret *Perms, err error) //Returns the specified user's permission map
UserBan(user *User, reason string, rule int) (err error) //Bans a user for a given reason and/or rule
UserKick(user *User, reason string, rule int) (err error) //Kicks a user for a given reason and/or rule
//Servers are organizations of channels, and contain their own global settings and features.
GetServer(serverID string) (ret *Server, err error) //Returns the specified server
//Voice connections are crucial for things like music and voice assistants
VoiceJoin(serverID, channelID string, muted, deafened bool) (err error) //Joins a voice channel
VoiceLeave(serverID string) (err error) //Leaves the active voice channel
}
func Error(format string, replacements ...interface{}) error {
if len(replacements) > 0 {
return fmt.Errorf(format, replacements)
}
return fmt.Errorf(format)
}
type User struct {
ServerID string `json:"serverID,omitempty"`
UserID string `json:"userID,omitempty"`
Username string `json:"username,omitempty"`
Nickname string `json:"nickname,omitempty"`
Roles []*Role `json:"roles,omitempty"`
}
type Role struct {
RoleID string `json:"roleID,omitempty"`
Name string `json:"name,omitempty"`
}
type Perms struct {
Administrator bool `json:"administrator,omitempty"`
Kick bool `json:"kick,omitempty"`
Ban bool `json:"ban,omitempty"`
}
func (p *Perms) CanAdministrate() bool {
return p.Administrator
}
func (p *Perms) CanKick() bool {
return p.CanAdministrate() || p.Kick
}
func (p *Perms) CanBan() bool {
return p.CanAdministrate() || p.Ban
}
type Channel struct {
ServerID string `json:"serverID,omitempty"`
ChannelID string `json:"channelID,omitempty"`
}
type Server struct {
ServerID string `json:"serverID,omitempty"`
Name string `json:"name,omitempty"`
Region string `json:"region,omitempty"`
OwnerID string `json:"ownerID,omitempty"`
DefaultChannel string `json:"defaultChannelID,omitempty"`
VoiceStates []*VoiceState `json:"voiceStates,omitempty"`
}
type VoiceState struct {
ChannelID string `json:"channelID,omitempty"`
UserID string `json:"userID,omitempty"`
SessionID string `json:"sessionID,omitempty"`
Deaf bool `json:"deaf,omitempty"`
Mute bool `json:"mute,omitempty"`
SelfDeaf bool `json:"selfDeaf,omitempty"`
SelfMute bool `json:"selfMeaf,omitempty"`
}