CookieMod - v0.0.3.1 - Weather
This commit is contained in:
parent
0021b49484
commit
d6ae0214fd
|
@ -1,2 +1,3 @@
|
|||
db/
|
||||
data/
|
||||
data/
|
||||
backup/
|
|
@ -4,6 +4,12 @@
|
|||
|
||||
### Installation
|
||||
|
||||
#### Requirements
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Installation files explanation
|
||||
|
||||
|Path |Description |
|
||||
|
|
49
bot.go
49
bot.go
|
@ -14,8 +14,9 @@ import (
|
|||
)
|
||||
|
||||
type CookieConfig struct {
|
||||
Token string `json:"token"`
|
||||
GuildID string `json:"guild_id"`
|
||||
Token string `json:"token"`
|
||||
GuildID string `json:"guild_id"`
|
||||
OpenWeatherMapAPIKey string `json:"openweathermap_api_key"`
|
||||
}
|
||||
|
||||
type PermsConfig struct {
|
||||
|
@ -47,6 +48,7 @@ var (
|
|||
|
||||
func Init() CookieConfig {
|
||||
CheckInstallationFolder("db")
|
||||
CheckInstallationFolder("backup")
|
||||
CheckInstallationFolder("data")
|
||||
hasConfig, configFolder := FileExists("data/config.json")
|
||||
if hasConfig {
|
||||
|
@ -103,6 +105,7 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// session.
|
||||
session.AddHandler(messageCreate)
|
||||
|
||||
|
@ -128,25 +131,31 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||
return
|
||||
}
|
||||
|
||||
if m.Content == "!time" {
|
||||
now := time.Now()
|
||||
hour, min, sec := now.Hour(), now.Minute(), now.Second()
|
||||
hourStr := fmt.Sprint(int(hour))
|
||||
minStr := fmt.Sprint(int(min))
|
||||
secStr := fmt.Sprint(int(sec))
|
||||
if len(hourStr) < 2 {
|
||||
hourStr = "0" + hourStr
|
||||
if strings.HasPrefix(m.Content, botPrefix) {
|
||||
cmd := m.Content
|
||||
if strings.Contains(m.Content, " ") {
|
||||
// could be a command
|
||||
cmd = strings.Split(m.Content, " ")[0]
|
||||
}
|
||||
if len(minStr) < 2 {
|
||||
minStr = "0" + minStr
|
||||
switch strings.TrimPrefix(cmd, botPrefix) {
|
||||
case "time":
|
||||
now := time.Now()
|
||||
hour, min, sec := now.Hour(), now.Minute(), now.Second()
|
||||
hourStr := fmt.Sprint(int(hour))
|
||||
minStr := fmt.Sprint(int(min))
|
||||
secStr := fmt.Sprint(int(sec))
|
||||
if len(hourStr) < 2 {
|
||||
hourStr = "0" + hourStr
|
||||
}
|
||||
if len(minStr) < 2 {
|
||||
minStr = "0" + minStr
|
||||
}
|
||||
if len(secStr) < 2 {
|
||||
secStr = "0" + secStr
|
||||
}
|
||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Current time: %s:%s:%s.", hourStr, minStr, secStr))
|
||||
case "weather":
|
||||
fmt.Println(config.OpenWeatherMapAPIKey)
|
||||
}
|
||||
if len(secStr) < 2 {
|
||||
secStr = "0" + secStr
|
||||
}
|
||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Current time: %s:%s:%s.", hourStr, minStr, secStr))
|
||||
}
|
||||
|
||||
if m.Content == "pong" {
|
||||
s.ChannelMessageSend(m.ChannelID, "Ping!")
|
||||
}
|
||||
}
|
||||
|
|
28
util.go
28
util.go
|
@ -29,3 +29,31 @@ func SecretPrompt(prompt string) string {
|
|||
}
|
||||
return string(data)
|
||||
}
|
||||
|
||||
// !ban @ExampleUser "Spam"
|
||||
// !tempban @ExampleUser "Spam" 1h
|
||||
func ParseArgs(s string) []string {
|
||||
var args []string
|
||||
var currentArg string
|
||||
var insideQuotes bool
|
||||
for _, char := range s {
|
||||
switch char {
|
||||
case ' ':
|
||||
if !insideQuotes {
|
||||
if currentArg != "" {
|
||||
args = append(args, currentArg)
|
||||
currentArg = ""
|
||||
}
|
||||
continue
|
||||
}
|
||||
case '"':
|
||||
insideQuotes = !insideQuotes
|
||||
continue
|
||||
}
|
||||
currentArg += string(char)
|
||||
}
|
||||
if currentArg != "" {
|
||||
args = append(args, currentArg)
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue