bot

package
v0.0.0-...-8a3180e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

Bot

Libraries for bots on the interwebs

Auth

Copypasta for auth config

export TWITTERTOKEN=""
export TWITTERTOKENSECRET=""
export TWITTERCONSUMERKEY=""
export TWITTERCONSUMERKEYSECRET=""

Example Bot

package main

import (
	"os"

	"github.com/ChimeraCoder/anaconda"
	"github.com/kris-nova/logger"
	"github.com/kris-nova/novaarchive/bot"
)

func main() {
	logger.BitwiseLevel = logger.LogEverything
	logger.Info("Starting bot...")
	robot := bot.NewTwitterBot(bot.NewTwitterBotCredentialsFromEnvironmentalVariables())
	robot.AddCommand("/lubbi")
	logger.Info("Setting command /lubbi...")
	robot.SetBufferSizeGBytes(1)
	logger.Info("Setting buffer 1Gb...")
	robot.SetSendTweet(func(api *anaconda.TwitterApi, tweet anaconda.Tweet) error {
		logger.Always("Found tweet: %s", tweet.IdStr)
		//
		// Your logic here
		//
		return nil
	})
	logger.Info("Setting SendTweet...")
	err := robot.Run()
	if err != nil {
		logger.Critical(err.Error())
		os.Exit(1)
	}
	logger.Info("Running bot...")
	for {
		err := robot.NextError()
		logger.Critical(err.Error())
	}
}

Documentation

Index

Constants

View Source
const DefaultBufferSizeBytes int64 = 1024 * 1024 * 1024 * 2

DefaultBufferSizeBytes is the default buffer size to use 1024 * 1024 * 1024 * 2 = 2Gb (<-- This is huge)

Variables

This section is empty.

Functions

This section is empty.

Types

type SendTweet

type SendTweet func(api *anaconda.TwitterApi, tweet anaconda.Tweet) error

SendTweet is the function type that will be executed for each TwitterBot instance

type TwitterBot

type TwitterBot struct {
	// contains filtered or unexported fields
}

TwitterBot is used to listen for strings on Twitter and respond by calling an associated SendTweet function

func NewTwitterBot

func NewTwitterBot(c *TwitterBotCredentials) *TwitterBot

NewTwitterBot is used to build a new TwitterBot

func (*TwitterBot) AddKey

func (t *TwitterBot) AddKey(key string)

AddCommand is used

func (*TwitterBot) AddSlashKey

func (t *TwitterBot) AddSlashKey(key string)

AddSlashKey is used to take a string "meeps" and search Twitter for "/meeps" add a command string without the slash.

func (*TwitterBot) Login

func (t *TwitterBot) Login() (*anaconda.User, error)

func (*TwitterBot) NextError

func (t *TwitterBot) NextError() error

NextError is just like a Next() function and will just pop the next error of the queue

Note: Not calling this message is dangerous as eventually the buffer will fill up, and messages will be dropped

func (*TwitterBot) Run

func (t *TwitterBot) Run() error

Run will start the bot concurrently, and return an error if the bot cannot start

func (*TwitterBot) SetBufferSizeBytes

func (t *TwitterBot) SetBufferSizeBytes(i int64)

SetBufferSizeGBytes will set the buffer size in B

func (*TwitterBot) SetBufferSizeGBytes

func (t *TwitterBot) SetBufferSizeGBytes(i int64)

SetBufferSizeGBytes will set the buffer size in Gb

func (*TwitterBot) SetSendTweet

func (t *TwitterBot) SetSendTweet(s SendTweet)

SetSendTweet will set a bot's SendTweet function

type TwitterBotCredentials

type TwitterBotCredentials struct {
	// contains filtered or unexported fields
}

TwitterBotCredentials is just an unexported wrapper for Twitter auth material

func NewTwitterBotCredentials

func NewTwitterBotCredentials(accessToken, accessSecret, consumerKey, consumerSecret string) *TwitterBotCredentials

NewTwitterBotCredentials returns a package safe auth struct

func NewTwitterBotCredentialsFromEnvironmentalVariables

func NewTwitterBotCredentialsFromEnvironmentalVariables() *TwitterBotCredentials

NewTwitterBotCredentialsFromEnvironmentalVariables will read from the associated environmental variables regardless if they are set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL