mirror of
https://github.com/Bios-Marcel/cordless.git
synced 2024-06-23 09:17:04 +00:00
Fix small bugs, replace deprecated usages and sort imports
This commit is contained in:
parent
98dac29cb0
commit
3a350a9e4f
|
@ -2,10 +2,11 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Bios-Marcel/cordless/config"
|
|
||||||
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/cordless/config"
|
||||||
|
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command represents a command that is executable by the user.
|
// Command represents a command that is executable by the user.
|
||||||
|
|
|
@ -2,10 +2,10 @@ package commandimpls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Bios-Marcel/cordless/commands"
|
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/cordless/commands"
|
||||||
"github.com/Bios-Marcel/cordless/config"
|
"github.com/Bios-Marcel/cordless/config"
|
||||||
"github.com/Bios-Marcel/cordless/ui"
|
"github.com/Bios-Marcel/cordless/ui"
|
||||||
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
||||||
|
|
|
@ -3,14 +3,16 @@ package commandimpls
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/discordgo"
|
||||||
|
|
||||||
"github.com/Bios-Marcel/cordless/config"
|
"github.com/Bios-Marcel/cordless/config"
|
||||||
"github.com/Bios-Marcel/cordless/ui"
|
"github.com/Bios-Marcel/cordless/ui"
|
||||||
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
||||||
"github.com/Bios-Marcel/cordless/util/files"
|
"github.com/Bios-Marcel/cordless/util/files"
|
||||||
"github.com/Bios-Marcel/discordgo"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"path"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const fileSendDocumentation = `[::b]NAME
|
const fileSendDocumentation = `[::b]NAME
|
||||||
|
|
|
@ -2,11 +2,13 @@ package commandimpls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Bios-Marcel/cordless/commands"
|
|
||||||
"github.com/Bios-Marcel/discordemojimap"
|
|
||||||
"github.com/Bios-Marcel/discordgo"
|
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/discordemojimap"
|
||||||
|
"github.com/Bios-Marcel/discordgo"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/cordless/commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NickSetCmd struct {
|
type NickSetCmd struct {
|
||||||
|
|
|
@ -183,7 +183,7 @@ func (cmd *TFADisableCmd) Execute(writer io.Writer, parameters []string) {
|
||||||
config.UpdateCurrentToken(cmd.session.Token)
|
config.UpdateCurrentToken(cmd.session.Token)
|
||||||
configError := config.PersistConfig()
|
configError := config.PersistConfig()
|
||||||
if configError != nil {
|
if configError != nil {
|
||||||
commands.PrintError(writer, "Error updating access token in configuration. You might have to log in again.", disableError.Error())
|
commands.PrintError(writer, "Error updating access token in configuration. You might have to log in again.", configError.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package commandimpls
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Bios-Marcel/discordemojimap"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -11,10 +10,13 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/discordemojimap"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/discordgo"
|
||||||
|
|
||||||
"github.com/Bios-Marcel/cordless/config"
|
"github.com/Bios-Marcel/cordless/config"
|
||||||
"github.com/Bios-Marcel/cordless/ui"
|
"github.com/Bios-Marcel/cordless/ui"
|
||||||
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
||||||
"github.com/Bios-Marcel/discordgo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -2,8 +2,9 @@ package commandimpls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Bios-Marcel/cordless/version"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/cordless/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const versionDocumentation = `[::b]NAME
|
const versionDocumentation = `[::b]NAME
|
||||||
|
|
|
@ -11,8 +11,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
//AppName is the name representing the application.
|
|
||||||
AppName = "Cordless"
|
|
||||||
//AppNameLowercase is the representative name, but lowercase.
|
//AppNameLowercase is the representative name, but lowercase.
|
||||||
//It us used for filepaths and such.
|
//It us used for filepaths and such.
|
||||||
AppNameLowercase = "cordless"
|
AppNameLowercase = "cordless"
|
||||||
|
|
|
@ -69,9 +69,6 @@ func generateGuilds(start, amount int) []*discordgo.UserGuild {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadGuilds(t *testing.T) {
|
func TestLoadGuilds(t *testing.T) {
|
||||||
type args struct {
|
|
||||||
guildLoader GuildLoader
|
|
||||||
}
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
guildLoader GuildLoader
|
guildLoader GuildLoader
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package scripting
|
package scripting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Bios-Marcel/discordgo"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Engine describes a type that is capable of handling events from the main
|
// Engine describes a type that is capable of handling events from the main
|
||||||
|
|
|
@ -5,10 +5,11 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/Bios-Marcel/cordless/config"
|
|
||||||
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
|
||||||
"github.com/Bios-Marcel/tview"
|
"github.com/Bios-Marcel/tview"
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/cordless/config"
|
||||||
|
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkVT() bool {
|
func checkVT() bool {
|
||||||
|
|
|
@ -208,7 +208,7 @@ func EventToString(event *tcell.EventKey) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
m := []string{}
|
var m []string
|
||||||
if event.Modifiers()&tcell.ModCtrl != 0 {
|
if event.Modifiers()&tcell.ModCtrl != 0 {
|
||||||
m = append(m, "Ctrl")
|
m = append(m, "Ctrl")
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func entryToEscapeSequence(table *ttyTable, entry chroma.StyleEntry) string {
|
||||||
|
|
||||||
func findClosest(table *ttyTable, seeking chroma.Colour) chroma.Colour {
|
func findClosest(table *ttyTable, seeking chroma.Colour) chroma.Colour {
|
||||||
closestColour := chroma.Colour(0)
|
closestColour := chroma.Colour(0)
|
||||||
closest := float64(math.MaxFloat64)
|
closest := math.MaxFloat64
|
||||||
for colour := range table.foreground {
|
for colour := range table.foreground {
|
||||||
distance := colour.Distance(seeking)
|
distance := colour.Distance(seeking)
|
||||||
if distance < closest {
|
if distance < closest {
|
||||||
|
|
|
@ -84,7 +84,7 @@ func TestAreDatesTheSameDay(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarshalDuration(t *testing.T) {
|
func TestMarshalDuration(t *testing.T) {
|
||||||
var duration Duration = Duration(6 * time.Second)
|
duration := Duration(6 * time.Second)
|
||||||
resultBytes, err := json.Marshal(duration)
|
resultBytes, err := json.Marshal(duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error marshalling duration: %s", err)
|
t.Errorf("error marshalling duration: %s", err)
|
||||||
|
|
|
@ -6,9 +6,10 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Bios-Marcel/cordless/config"
|
|
||||||
"github.com/Bios-Marcel/tview"
|
"github.com/Bios-Marcel/tview"
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/cordless/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -196,7 +196,7 @@ func createChannelNode(channel *discordgo.Channel) *tview.TreeNode {
|
||||||
// Adds a padlock prefix if the channel if not readable by the everyone group
|
// Adds a padlock prefix if the channel if not readable by the everyone group
|
||||||
if config.Current.IndicateChannelAccessRestriction {
|
if config.Current.IndicateChannelAccessRestriction {
|
||||||
for _, permission := range channel.PermissionOverwrites {
|
for _, permission := range channel.PermissionOverwrites {
|
||||||
if permission.Type == "role" && permission.ID == channel.GuildID && permission.Deny&discordgo.PermissionReadMessages == discordgo.PermissionReadMessages {
|
if permission.Type == "role" && permission.ID == channel.GuildID && permission.Deny&discordgo.PermissionViewChannel == discordgo.PermissionViewChannel {
|
||||||
prefixes += tviewutil.Escape("\U0001F512")
|
prefixes += tviewutil.Escape("\U0001F512")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ func TestChannelTree(t *testing.T) {
|
||||||
{
|
{
|
||||||
ID: "R1",
|
ID: "R1",
|
||||||
Type: "role",
|
Type: "role",
|
||||||
Deny: discordgo.PermissionReadMessages,
|
Deny: discordgo.PermissionViewChannel,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ func TestChannelTree(t *testing.T) {
|
||||||
r1 := &discordgo.Role{
|
r1 := &discordgo.Role{
|
||||||
ID: "R1",
|
ID: "R1",
|
||||||
Name: "Rollo",
|
Name: "Rollo",
|
||||||
Permissions: discordgo.PermissionReadMessages,
|
Permissions: discordgo.PermissionViewChannel,
|
||||||
}
|
}
|
||||||
state.RoleAdd("G1", r1)
|
state.RoleAdd("G1", r1)
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,11 @@ package ui
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/discordgo"
|
||||||
|
|
||||||
"github.com/Bios-Marcel/cordless/config"
|
"github.com/Bios-Marcel/cordless/config"
|
||||||
_ "github.com/Bios-Marcel/cordless/syntax"
|
_ "github.com/Bios-Marcel/cordless/syntax"
|
||||||
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
||||||
"github.com/Bios-Marcel/discordgo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseBoldAndUnderline(t *testing.T) {
|
func TestParseBoldAndUnderline(t *testing.T) {
|
||||||
|
|
|
@ -4,12 +4,13 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
|
||||||
"github.com/Bios-Marcel/cordless/util/text"
|
|
||||||
"github.com/Bios-Marcel/discordgo"
|
"github.com/Bios-Marcel/discordgo"
|
||||||
"github.com/Bios-Marcel/tview"
|
"github.com/Bios-Marcel/tview"
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
|
||||||
|
"github.com/Bios-Marcel/cordless/ui/tviewutil"
|
||||||
|
"github.com/Bios-Marcel/cordless/util/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
const splashText = `
|
const splashText = `
|
||||||
|
|
10
ui/window.go
10
ui/window.go
|
@ -712,7 +712,15 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
|
||||||
if currentText == "" {
|
if currentText == "" {
|
||||||
go window.session.ChannelFileSend(targetChannel.ID, "img.png", dataChannel)
|
go window.session.ChannelFileSend(targetChannel.ID, "img.png", dataChannel)
|
||||||
} else {
|
} else {
|
||||||
go window.session.ChannelFileSendWithMessage(targetChannel.ID, currentText, "img.png", dataChannel)
|
messageData := &discordgo.MessageSend{
|
||||||
|
Content: currentText,
|
||||||
|
File: &discordgo.File{
|
||||||
|
Name: "img.png",
|
||||||
|
ContentType: "image/png",
|
||||||
|
Reader: dataChannel,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
go window.session.ChannelMessageSendComplex(targetChannel.ID, messageData)
|
||||||
window.messageInput.SetText("")
|
window.messageInput.SetText("")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -31,7 +31,7 @@ func ScoreAndSortRoles(searchTerm string, searchables []*discordgo.Role) []*disc
|
||||||
|
|
||||||
// Convert the results into an array.
|
// Convert the results into an array.
|
||||||
sortedItems := make([]*discordgo.Role, 0, len(scoredItems))
|
sortedItems := make([]*discordgo.Role, 0, len(scoredItems))
|
||||||
for key, _ := range scoredItems {
|
for key := range scoredItems {
|
||||||
sortedItems = append(sortedItems, key)
|
sortedItems = append(sortedItems, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ func ScoreAndSortMembers(searchTerm string, searchables []*discordgo.Member) []*
|
||||||
|
|
||||||
// Convert the results into an array.
|
// Convert the results into an array.
|
||||||
sortedItems := make([]*discordgo.Member, 0, len(scoredItems))
|
sortedItems := make([]*discordgo.Member, 0, len(scoredItems))
|
||||||
for key, _ := range scoredItems {
|
for key := range scoredItems {
|
||||||
sortedItems = append(sortedItems, key)
|
sortedItems = append(sortedItems, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ func ScoreAndSortUsers(searchTerm string, searchables []*discordgo.User) []*disc
|
||||||
|
|
||||||
// Convert the results into an array.
|
// Convert the results into an array.
|
||||||
sortedItems := make([]*discordgo.User, 0, len(scoredItems))
|
sortedItems := make([]*discordgo.User, 0, len(scoredItems))
|
||||||
for key, _ := range scoredItems {
|
for key := range scoredItems {
|
||||||
sortedItems = append(sortedItems, key)
|
sortedItems = append(sortedItems, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ func ScoreAndSortEmoji(searchTerm string, unicodeEmoji []string, customEmoji []*
|
||||||
|
|
||||||
// Convert the results into an array.
|
// Convert the results into an array.
|
||||||
sortedItems := make([]string, 0, len(scoredItems))
|
sortedItems := make([]string, 0, len(scoredItems))
|
||||||
for key, _ := range scoredItems {
|
for key := range scoredItems {
|
||||||
sortedItems = append(sortedItems, key)
|
sortedItems = append(sortedItems, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ func ScoreAndSortChannels(searchTerm string, searchables []*discordgo.Channel) [
|
||||||
|
|
||||||
// Convert the results into an array.
|
// Convert the results into an array.
|
||||||
sortedItems := make([]*discordgo.Channel, 0, len(scoredItems))
|
sortedItems := make([]*discordgo.Channel, 0, len(scoredItems))
|
||||||
for key, _ := range scoredItems {
|
for key := range scoredItems {
|
||||||
sortedItems = append(sortedItems, key)
|
sortedItems = append(sortedItems, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package text
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
"github.com/mdp/qrterminal/v3"
|
"github.com/mdp/qrterminal/v3"
|
||||||
"rsc.io/qr"
|
"rsc.io/qr"
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package version
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/go-github/v29/github"
|
"github.com/google/go-github/v29/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user