forked from Minecraft/canopeas
35 lines
747 B
Go
35 lines
747 B
Go
|
package discord
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
commands["tweet"] = command{
|
||
|
staffOnly: true,
|
||
|
validate: func(cmd commandInit) bool {
|
||
|
return isStaff(cmd.message.Member.Roles, cmd.config.StaffRoles)
|
||
|
},
|
||
|
run: func(cmd commandInit) (string, error) {
|
||
|
args := strings.Fields(cmd.message.Content)
|
||
|
|
||
|
if len(args) < 2 {
|
||
|
return "This command requires a message to tweet", nil
|
||
|
}
|
||
|
|
||
|
message := strings.Join(args[1:], " ")
|
||
|
tweet, resp, err := cmd.twitterClient.Statuses.Update(message, nil)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
if resp.StatusCode%100 != 2 {
|
||
|
|
||
|
}
|
||
|
|
||
|
return fmt.Sprintf("https://twitter.com/%d/status/%d", tweet.User.ID, tweet.ID), nil
|
||
|
},
|
||
|
help: "Send a tweet from the BirbMC Twitter",
|
||
|
}
|
||
|
}
|