mirror of https://github.com/fluffle/goirc
!appendtopic and query for basetopic with !topic
This commit is contained in:
parent
ba455ac44f
commit
a44a71677b
5
auth.go
5
auth.go
|
@ -8,8 +8,8 @@ import (
|
||||||
"github.com/kless/goconfig/config"
|
"github.com/kless/goconfig/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var auth *config.Config
|
|
||||||
const authFile = "auth.conf"
|
const authFile = "auth.conf"
|
||||||
|
var auth *config.Config
|
||||||
|
|
||||||
func readAuth() {
|
func readAuth() {
|
||||||
var err os.Error;
|
var err os.Error;
|
||||||
|
@ -38,8 +38,7 @@ func addAccess(conn *irc.Conn, channel, nick, flags string) (string, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auth.AddOption(section, n.Host, nflags)
|
auth.AddOption(section, n.Host, nflags)
|
||||||
err := auth.WriteFile(authFile, 0644, "")
|
if err := auth.WriteFile(authFile, 0644, ""); err != nil {
|
||||||
if err != nil {
|
|
||||||
say(conn, channel, "Error while writing to %s", authFile)
|
say(conn, channel, "Error while writing to %s", authFile)
|
||||||
}
|
}
|
||||||
// config.WriteFile destroys the config, so
|
// config.WriteFile destroys the config, so
|
||||||
|
|
40
handler.go
40
handler.go
|
@ -18,6 +18,7 @@ var commands = map [string]func(*irc.Conn, string, string, string) {
|
||||||
"flags": flags,
|
"flags": flags,
|
||||||
"add": add,
|
"add": add,
|
||||||
"topic": topic,
|
"topic": topic,
|
||||||
|
"appendtopic": appendtopic,
|
||||||
}
|
}
|
||||||
|
|
||||||
const googleAPIKey = "ABQIAAAA6-N_jl4ETgtMf2M52JJ_WRQjQjNunkAJHIhTdFoxe8Di7fkkYhRRcys7ZxNbH3MIy_MKKcEO4-9_Ag"
|
const googleAPIKey = "ABQIAAAA6-N_jl4ETgtMf2M52JJ_WRQjQjNunkAJHIhTdFoxe8Di7fkkYhRRcys7ZxNbH3MIy_MKKcEO4-9_Ag"
|
||||||
|
@ -77,7 +78,11 @@ func command(conn *irc.Conn, nick, text, target string) {
|
||||||
|
|
||||||
func say(conn *irc.Conn, target, message string, a ...interface{}) {
|
func say(conn *irc.Conn, target, message string, a ...interface{}) {
|
||||||
text := strings.Replace(fmt.Sprintf(message, a...), "\n", " ", -1)
|
text := strings.Replace(fmt.Sprintf(message, a...), "\n", " ", -1)
|
||||||
conn.Privmsg(target, text)
|
if isChannel(target) {
|
||||||
|
conn.Privmsg(target, text)
|
||||||
|
} else {
|
||||||
|
conn.Notice(target, text)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func youtube(conn *irc.Conn, nick, video, channel string) {
|
func youtube(conn *irc.Conn, nick, video, channel string) {
|
||||||
|
@ -237,13 +242,34 @@ func flags(conn *irc.Conn, nick, args, channel string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func topic(conn *irc.Conn, nick, args, channel string) {
|
func topic(conn *irc.Conn, nick, args, channel string) {
|
||||||
if !isChannel(channel) {
|
if !isChannel(channel) || !hasAccess(conn, channel, nick, "t") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if hasAccess(conn, channel, nick, "t") {
|
section := conn.Network + " " + channel
|
||||||
if args != "" {
|
if args != "" {
|
||||||
conn.Topic(channel, args)
|
updateConf(section, "basetopic", args)
|
||||||
}
|
conn.Topic(channel, args)
|
||||||
// TODO: appendtopic, query for topic with blank args
|
} else {
|
||||||
|
basetopic, _ := conf.String(section, "basetopic")
|
||||||
|
say(conn, nick, "Basetopic: %s", basetopic)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func appendtopic(conn *irc.Conn, nick, args, channel string) {
|
||||||
|
if !isChannel(channel) || !hasAccess(conn, channel, nick, "t") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c := conn.GetChannel(channel)
|
||||||
|
if c == nil {
|
||||||
|
say(conn, channel, "Error while getting channel information for %s", channel)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
section := conn.Network + " " + channel
|
||||||
|
basetopic, _ := conf.String(section, "basetopic")
|
||||||
|
if !strings.HasPrefix(c.Topic, basetopic) {
|
||||||
|
basetopic = c.Topic
|
||||||
|
say(conn, nick, "New basetopic: %s", basetopic)
|
||||||
|
updateConf(section, "basetopic", basetopic)
|
||||||
|
}
|
||||||
|
conn.Topic(channel, basetopic + args)
|
||||||
|
}
|
||||||
|
|
25
rbot.go
25
rbot.go
|
@ -8,18 +8,13 @@ import (
|
||||||
"github.com/kless/goconfig/config"
|
"github.com/kless/goconfig/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const confFile = "rbot.conf"
|
||||||
var trigger string
|
var trigger string
|
||||||
var sections []string
|
var sections []string
|
||||||
var conf *config.Config
|
var conf *config.Config
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err os.Error;
|
readConf()
|
||||||
conf, err = config.ReadDefault("rbot.conf")
|
|
||||||
if (err != nil) {
|
|
||||||
fmt.Printf("Config error: %s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
trigger = readConfString("DEFAULT", "trigger")
|
trigger = readConfString("DEFAULT", "trigger")
|
||||||
readAuth()
|
readAuth()
|
||||||
|
|
||||||
|
@ -84,6 +79,14 @@ func autojoin(conn *irc.Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readConf() {
|
||||||
|
var err os.Error;
|
||||||
|
conf, err = config.ReadDefault("rbot.conf")
|
||||||
|
if (err != nil) {
|
||||||
|
fmt.Printf("Config error: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
func readConfString(section, option string) string {
|
func readConfString(section, option string) string {
|
||||||
value, err := conf.String(section, option)
|
value, err := conf.String(section, option)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -98,3 +101,11 @@ func readConfBool(section, option string) bool {
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
func updateConf(section, option, value string) {
|
||||||
|
conf.AddOption(section, option, value)
|
||||||
|
if err := conf.WriteFile(confFile, 0644, ""); err != nil {
|
||||||
|
panic("Error while writing to " + confFile)
|
||||||
|
}
|
||||||
|
// config.WriteFile destroys the config, so
|
||||||
|
readConf()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue