forked from Minecraft/canopeas
36 lines
779 B
Go
36 lines
779 B
Go
package discord
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func init() {
|
|
commands = append(commands, &command{
|
|
staffOnly: true,
|
|
name: "tweet",
|
|
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",
|
|
})
|
|
}
|