mirror of
https://github.com/diamondburned/cchat-discord.git
synced 2025-03-23 18:39:19 +00:00
Initial commit
This commit is contained in:
commit
d93cf981a1
35
channel.go
Normal file
35
channel.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package discord
|
||||
|
||||
import (
|
||||
"github.com/diamondburned/arikawa/discord"
|
||||
"github.com/diamondburned/cchat"
|
||||
"github.com/diamondburned/cchat/text"
|
||||
)
|
||||
|
||||
type Channel struct {
|
||||
id discord.Snowflake
|
||||
guildID discord.Snowflake
|
||||
name string
|
||||
session *Session
|
||||
}
|
||||
|
||||
func NewChannel(s *Session, ch *discord.Channel) *Channel {
|
||||
return &Channel{
|
||||
id: ch.ID,
|
||||
guildID: ch.GuildID,
|
||||
name: ch.Name,
|
||||
session: s,
|
||||
}
|
||||
}
|
||||
|
||||
func (ch *Channel) ID() string {
|
||||
return ch.id.String()
|
||||
}
|
||||
|
||||
func (ch *Channel) Name() text.Rich {
|
||||
return text.Rich{Content: "#" + ch.name}
|
||||
}
|
||||
|
||||
func (ch *Channel) Nickname(labeler cchat.LabelContainer) error {
|
||||
|
||||
}
|
9
go.mod
Normal file
9
go.mod
Normal file
|
@ -0,0 +1,9 @@
|
|||
module github.com/diamondburned/cchat-discord
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/diamondburned/arikawa v0.9.4
|
||||
github.com/diamondburned/cchat v0.0.26
|
||||
github.com/pkg/errors v0.9.1
|
||||
)
|
18
go.sum
Normal file
18
go.sum
Normal file
|
@ -0,0 +1,18 @@
|
|||
github.com/diamondburned/arikawa v0.9.4 h1:Mrp0Vz9R2afbvhWS6m/oLIQy22/uxXb459LUv7qrZPA=
|
||||
github.com/diamondburned/arikawa v0.9.4/go.mod h1:nIhVIatzTQhPUa7NB8w4koG1RF9gYbpAr8Fj8sKq660=
|
||||
github.com/diamondburned/cchat v0.0.26 h1:QBt4d65uzUPJz3jF8b2pJ09Jz8LeBRyG2ol47FOy0g0=
|
||||
github.com/diamondburned/cchat v0.0.26/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||
github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY=
|
||||
github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI=
|
||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
37
guild.go
Normal file
37
guild.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package discord
|
||||
|
||||
import (
|
||||
"github.com/diamondburned/arikawa/discord"
|
||||
"github.com/diamondburned/cchat"
|
||||
"github.com/diamondburned/cchat/text"
|
||||
)
|
||||
|
||||
type Guild struct {
|
||||
id discord.Snowflake
|
||||
name string
|
||||
session *Session
|
||||
}
|
||||
|
||||
var (
|
||||
_ cchat.Server = (*Guild)(nil)
|
||||
)
|
||||
|
||||
func NewGuild(s *Session, g *discord.Guild) *Guild {
|
||||
return &Guild{
|
||||
id: g.ID,
|
||||
name: g.Name,
|
||||
session: s,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Guild) ID() string {
|
||||
return g.id.String()
|
||||
}
|
||||
|
||||
func (g *Guild) Name() text.Rich {
|
||||
return text.Rich{Content: g.name}
|
||||
}
|
||||
|
||||
func (g *Guild) Guilds(container cchat.ServersContainer) error {
|
||||
return nil
|
||||
}
|
108
service.go
Normal file
108
service.go
Normal file
|
@ -0,0 +1,108 @@
|
|||
package discord
|
||||
|
||||
import (
|
||||
"github.com/diamondburned/arikawa/state"
|
||||
"github.com/diamondburned/cchat"
|
||||
"github.com/diamondburned/cchat/text"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Service struct{}
|
||||
|
||||
var (
|
||||
_ cchat.Service = (*Service)(nil)
|
||||
_ cchat.Icon = (*Service)(nil)
|
||||
)
|
||||
|
||||
func (Service) Name() text.Rich {
|
||||
return text.Rich{Content: "Discord"}
|
||||
}
|
||||
|
||||
func (Service) Icon(iconer cchat.IconContainer) error {
|
||||
iconer.SetIcon("https://discord.com/assets/2c21aeda16de354ba5334551a883b481.png")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (Service) Authenticate() cchat.Authenticator {
|
||||
return Authenticator{}
|
||||
}
|
||||
|
||||
type Authenticator struct{}
|
||||
|
||||
var _ cchat.Authenticator = (*Authenticator)(nil)
|
||||
|
||||
func (Authenticator) AuthenticateForm() []cchat.AuthenticateEntry {
|
||||
// TODO: username, password and 2FA
|
||||
return []cchat.AuthenticateEntry{
|
||||
{
|
||||
Name: "Token",
|
||||
Secret: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (Authenticator) Authenticate(form []string) (cchat.Session, error) {
|
||||
s, err := state.New(form[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.Open(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Prefetch user.
|
||||
_, err = s.Me()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Failed to get current user")
|
||||
}
|
||||
|
||||
return &Session{
|
||||
State: s,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
*state.State
|
||||
}
|
||||
|
||||
func (s *Session) ID() string {
|
||||
u, _ := s.Store.Me()
|
||||
return u.ID.String()
|
||||
}
|
||||
|
||||
func (s *Session) Name() text.Rich {
|
||||
u, _ := s.Store.Me()
|
||||
return text.Rich{Content: u.Username + "#" + u.Discriminator}
|
||||
}
|
||||
|
||||
func (s *Session) Icon(iconer cchat.IconContainer) error {
|
||||
u, _ := s.Store.Me()
|
||||
iconer.SetIcon(u.AvatarURL())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Session) Servers(container cchat.ServersContainer) error {
|
||||
g, err := s.Guilds()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var servers = make([]cchat.Server, len(g))
|
||||
for i := range g {
|
||||
servers[i] = NewGuild(s, &g[i])
|
||||
}
|
||||
|
||||
container.SetServers(servers)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Session) Disconnect() error {
|
||||
return s.Close()
|
||||
}
|
||||
|
||||
func (s *Session) Save() (map[string]string, error) {
|
||||
return map[string]string{
|
||||
"token": s.Token,
|
||||
}, nil
|
||||
}
|
Loading…
Reference in a new issue