-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
183 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2022-2023 Kesuaheli | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package info | ||
|
||
import ( | ||
"cake4everybot/data/lang" | ||
"cake4everybot/event/command/util" | ||
"cake4everybot/status" | ||
"fmt" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
const ( | ||
// Prefix for translation key, i.e.: | ||
// key := tp+"base" // => info | ||
tp = "discord.command.info." | ||
) | ||
|
||
// The Chat (slash) command of the info package. Simply prints a | ||
// little infomation about the bot. | ||
type Chat struct { | ||
util.InteractionUtil | ||
|
||
ID string | ||
} | ||
|
||
// AppCmd (ApplicationCommand) returns the definition of the chat | ||
// command | ||
func (cmd Chat) AppCmd() *discordgo.ApplicationCommand { | ||
return &discordgo.ApplicationCommand{ | ||
Name: lang.GetDefault(tp + "base"), | ||
NameLocalizations: util.TranslateLocalization(tp + "base"), | ||
Description: lang.GetDefault(tp + "base.description"), | ||
DescriptionLocalizations: util.TranslateLocalization(tp + "base.description"), | ||
} | ||
} | ||
|
||
// CmdHandler returns the functionality of a command | ||
func (cmd Chat) CmdHandler() func(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
|
||
return func(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
cmd.InteractionUtil = util.InteractionUtil{Session: s, Interaction: i} | ||
|
||
e := &discordgo.MessageEmbed{ | ||
Title: lang.GetDefault(tp + "title"), | ||
Color: 0x00FF00, | ||
} | ||
util.AddEmbedField(e, | ||
lang.Get(tp+"start_time", lang.FallbackLang()), | ||
fmt.Sprintf("<t:%d:R>", status.GetStartTime().Unix()), | ||
true, | ||
) | ||
util.AddEmbedField(e, | ||
lang.Get(tp+"latency", lang.FallbackLang()), | ||
fmt.Sprintf("%dms", s.LastHeartbeatAck.Sub(s.LastHeartbeatSent).Milliseconds()), | ||
true, | ||
) | ||
util.AddEmbedField(e, | ||
lang.Get(tp+"version", lang.FallbackLang()), | ||
fmt.Sprintf("v%s", viper.GetString("version")), | ||
false, | ||
) | ||
util.SetEmbedFooter(s, tp+"display", e) | ||
|
||
cmd.ReplyEmbed(e) | ||
} | ||
} | ||
|
||
// SetID sets the registered command ID for internal uses after uploading to discord | ||
func (cmd *Chat) SetID(id string) { | ||
cmd.ID = id | ||
} | ||
|
||
// GetID gets the registered command ID | ||
func (cmd Chat) GetID() string { | ||
return cmd.ID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022-2023 Kesuaheli | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package status | ||
|
||
import "time" | ||
|
||
// The point in time where the bot starts | ||
var startTime time.Time | ||
|
||
func init() { | ||
startTime = time.Now() | ||
} | ||
|
||
// GetStartTime returns the time were the bot stared | ||
func GetStartTime() time.Time { | ||
return startTime | ||
} | ||
|
||
// GetUptime returns the duration since the bot stared | ||
func GetUptime() time.Duration { | ||
return time.Since(startTime) | ||
} |