Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
Fix bugs And can change reply
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaototi committed Nov 7, 2023
1 parent 289ca3d commit 2b496b6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ guild:
lang: japanese
model: gpt-3.5-turbo
timeout: 120
reply: 3
user_blacklist:
- "0000000000000000000"
2 changes: 1 addition & 1 deletion lib/cmds/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func splitMsg(msg *string, guild *config.Guild) (string, int, float64, float64,
var prm, filter, cmodel bool

modelstr = guild.Model
repnum, topnum, tmpnum = 1, 1, 1
repnum, topnum, tmpnum = config.CurrentConfig.Guild.Reply, 1, 1
prm, filter, cmodel = true, false, false

str := strings.Split(*msg, " ")
Expand Down
22 changes: 20 additions & 2 deletions lib/cmds/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ func ConfigUsage(session *discordgo.Session, orgMsg *discordgo.MessageCreate, gu
})
msg.Fields = append(msg.Fields, &discordgo.MessageEmbedField{
Name: "model <model name>",
Value: config.Lang[guild.Lang].Usage.Config.Lang,
Value: config.Lang[guild.Lang].Usage.Config.Model,
})
msg.Fields = append(msg.Fields, &discordgo.MessageEmbedField{
Name: "timeout <int>",
Value: config.Lang[guild.Lang].Usage.Config.TimeOut,
})
msg.Fields = append(msg.Fields, &discordgo.MessageEmbedField{
Name: "reply <int>",
Value: config.Lang[guild.Lang].Usage.Config.Reply,
})
ReplyEmbed(session, orgMsg, msg)
}

Expand All @@ -63,6 +67,10 @@ func ConfigCmd(session *discordgo.Session, orgMsg *discordgo.MessageCreate, guil
Name: "timeout",
Value: strconv.Itoa(guild.Timeout),
})
msg.Fields = append(msg.Fields, &discordgo.MessageEmbedField{
Name: "reply",
Value: strconv.Itoa(guild.Reply),
})
ReplyEmbed(session, orgMsg, msg)
return
}
Expand Down Expand Up @@ -105,6 +113,16 @@ func ConfigCmd(session *discordgo.Session, orgMsg *discordgo.MessageCreate, guil
}
key = config.Lang[guild.Lang].Config.Item.Timeout
item = timeout
case "reply":
reply := split[1]
guild.Reply, _ = strconv.Atoi(reply)
if guild.Reply < 1 {
ErrorReply(session, orgMsg, config.Lang[guild.Lang].Error.MustTimeoutDuration)
return
}
guild.Reply, _ = strconv.Atoi(reply)
key = config.Lang[guild.Lang].Config.Item.Reply
item = reply
default:
ConfigUsage(session, orgMsg, &guild, errors.New("item not found"))
return
Expand All @@ -122,7 +140,7 @@ func ConfigCmd(session *discordgo.Session, orgMsg *discordgo.MessageCreate, guil
session.MessageReactionAdd(orgMsg.ChannelID, orgMsg.ID, "👍")
msg := embed.NewEmbed(session, orgMsg)
msg.Title = config.Lang[guild.Lang].Config.Title
msg.Color = embed.ColorGPT3
msg.Color = embed.ColorSystem
msg.Fields = append(msg.Fields, &discordgo.MessageEmbedField{
Value: key + item + config.Lang[guild.Lang].Config.Announce,
})
Expand Down
4 changes: 3 additions & 1 deletion lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Guild struct {
Lang string
Model string
Timeout int
Reply int
}

const configFile = "./config.yml"
Expand Down Expand Up @@ -84,11 +85,12 @@ func SaveGuild(guild *Guild) error {
return err
}

if guild.Prefix != CurrentConfig.Guild.Prefix || guild.Model != CurrentConfig.Guild.Model || guild.Lang != CurrentConfig.Guild.Lang || guild.Timeout != CurrentConfig.Guild.Timeout {
if guild.Prefix != CurrentConfig.Guild.Prefix || guild.Model != CurrentConfig.Guild.Model || guild.Lang != CurrentConfig.Guild.Lang || guild.Timeout != CurrentConfig.Guild.Timeout || guild.Reply != CurrentConfig.Guild.Reply {
CurrentConfig.Guild.Prefix = guild.Prefix
CurrentConfig.Guild.Lang = guild.Lang
CurrentConfig.Guild.Model = guild.Model
CurrentConfig.Guild.Timeout = guild.Timeout
CurrentConfig.Guild.Reply = guild.Reply
}

newConfig := Config{
Expand Down
25 changes: 19 additions & 6 deletions lib/config/lang.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package config

import "strconv"

type Strings struct {
Lang string
CurrConf string
Expand Down Expand Up @@ -43,6 +45,7 @@ type itemstr struct {
Model string
Maxtoken string
Timeout string
Reply string
}

type replystr struct {
Expand Down Expand Up @@ -70,7 +73,9 @@ type configusagestr struct {
Desc string
Prefix string
Lang string
Model string
TimeOut string
Reply string
}

var (
Expand All @@ -85,9 +90,12 @@ func loadLang() {
Usage: usagestr{
Title: "使い方: ",
Config: configusagestr{
Desc: "各種設定を行います。\n設定項目と内容は以下をご確認ください。",
Prefix: "コマンドの接頭詞を指定します。\n現在の設定は`" + CurrentConfig.Guild.Prefix + "`です。",
Lang: "言語を指定します。現在の設定は`" + CurrentConfig.Guild.Lang + "`です。",
Desc: "各種設定を行います。\n設定項目と内容は以下をご確認ください。",
Prefix: "コマンドの接頭詞を指定します。\n現在の設定は`" + CurrentConfig.Guild.Prefix + "`です。",
Lang: "言語を指定します。\n現在の設定は`" + CurrentConfig.Guild.Lang + "`です。",
Model: "モデルを指定します。\n現在の設定は`" + CurrentConfig.Guild.Model + "`です。",
TimeOut: "タイムアウトまでの時間を指定します。\n現在の設定は、`" + strconv.Itoa(CurrentConfig.Guild.Timeout) + "`です。",
Reply: "返信を遡る回数を指定します。\n現在の設定は、`" + strconv.Itoa(CurrentConfig.Guild.Reply) + "`です。",
},
Cmd: cmdusagestr{
ChatTitle: "`" + CurrentConfig.Guild.Prefix + "chat`",
Expand All @@ -113,6 +121,7 @@ func loadLang() {
Model: "APIで使用するモデルを\"",
Maxtoken: "botが使用するトークンの最大値を\"",
Timeout: "タイムアウトの時間を\"",
Reply: "返信を遡る回数を\"",
},
},
Reply: replystr{
Expand Down Expand Up @@ -141,9 +150,12 @@ func loadLang() {
Usage: usagestr{
Title: "Usage: ",
Config: configusagestr{
Desc: "Do configuration.\nItem list is below.",
Prefix: "Specify command prefix.\nCurrent config is `" + CurrentConfig.Guild.Prefix + "`.",
Lang: "Specify language.\nCurrent config is `" + CurrentConfig.Guild.Lang + "`.",
Desc: "Do configuration.\nItem list is below.",
Prefix: "Specify command prefix.\nCurrent config is `" + CurrentConfig.Guild.Prefix + "`.",
Lang: "Specify language.\nCurrent config is `" + CurrentConfig.Guild.Lang + "`.",
Model: "S@ecify model.\nCurrent config is `" + CurrentConfig.Guild.Model + "`.",
TimeOut: "Specify timeout.\nCurrent config is `" + strconv.Itoa(CurrentConfig.Guild.Timeout) + "`.",
Reply: "Specify number of times to go back to reply.\nCurrent config is `" + strconv.Itoa(CurrentConfig.Guild.Reply) + "`.",
},
Cmd: cmdusagestr{
ChatTitle: "`" + CurrentConfig.Guild.Prefix + "chat`",
Expand All @@ -169,6 +181,7 @@ func loadLang() {
Maxtoken: "Max Tokens used by bot for \"",
Model: "Model used by API for\"",
Timeout: "The time until timeout for \"",
Reply: "Number of times to go back to reply\"",
},
},
Reply: replystr{
Expand Down

0 comments on commit 2b496b6

Please sign in to comment.