The bot's config is held in a file called config.json
in the same folder as the bot. If no config file is found, a default/empty config will be written. At the very least, you should fill in the botOwner
field with your username. The rest of the configuration can be done by interacting with the bot.
import(
keybot/config
)
{
"botOwner": ""
}
const ConfigFile = "config.json"
c := config.ConfigJSON{}
// Create default config if none exists
if _, err := os.Stat(ConfigFile); os.IsNotExist(err) {
c.Write(ConfigFile)
}
c := config.ConfigJSON{}
c.Read("config.json")
After making changes to a ConfigJSON
interface, you can call the Write()
method, passing just the filename.
c := config.ConfigJSON{}
c.BotOwner = "dxb"
c.Write("config.json")
import(
"keybot/api"
)
user := api.Channel{Name: "dxb"}
user.SendMessage("Hello, dxb!")
team := api.Channel{Name: "crbot.public", Channel: "bots", IsTeam: true}
team.SendMessage("Hello everyone!")
members := map[string]string{
// "username": "role"
"cagingroyals": "admin",
}
t := api.Team{Name: "crbot.public"}
teamAdd := t.AddMembers(members)
if teamAdd.Error.Message != "" {
fmt.Println(teamAdd.Error.Message)
} else {
fmt.Println("Users successfully added to team '%s'.", t.Name)
}
The ListMembers()
method returns a map[string]string
with the key being the username and value being the role. This is the same as the input for AddMembers()
.
The following code snippet will send a message to user dxb
with a multiline code block containing all users in the team crbot.public
, one user per line in the format user: role
:
t := api.Team{Name: "crbot.public"}
crbotMembers := "```\n"
m := t.ListMembers()
for u, r := range m {
line := fmt.Sprintf("%s: %s\n", u, r)
crbotMembers += line
}
crbotMembers += "```"
u := api.Channel{Name: "dxb"}
u.SendMessage(crbotMembers)