maimai

package module
v0.0.0-...-f113cdd Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2015 License: GPL-2.0 Imports: 15 Imported by: 0

README

maimai

Build Status Coverage Status

Overview

maimai is a library for writing and running bots for the euphoria.io chat service. It provides an interface for adding handlers, which are functions that process packets concurrently as they are received. This bot is currently NOT tested in an automated fashion and is pre-alpha. Use with caution, the maker is not responsible for any issues you should encounter.

Documentation

Index

Constants

View Source
const (
	PingReplyType = "ping-reply"
	PingEventType = "ping-event"

	SendType      = "send"
	SendEventType = "send-event"
	SendReplyType = "send-reply"

	NickType      = "nick"
	NickReplyType = "nick-reply"
	NickEventType = "nick-event"

	JoinEventType = "join-event"

	PartEventType = "part-event"

	AuthType = "auth"

	BounceEventType = "bounce-event"
)

These give named constants to the packet types.

Variables

This section is empty.

Functions

func DebugHandler

func DebugHandler(room *Room, input chan PacketEvent, cmdChan chan string)

func JoinEventHandler

func JoinEventHandler(room *Room, input chan PacketEvent, cmdChan chan string)

func LinkTitleHandler

func LinkTitleHandler(room *Room, input chan PacketEvent, cmdChan chan string)

LinkTitleHandler handles a send-event, looks for URLs, and replies with the title text of a link if a valid one is found.

func MessageLogHandler

func MessageLogHandler(room *Room, input chan PacketEvent, cmdChan chan string)

func NickChangeHandler

func NickChangeHandler(room *Room, input chan PacketEvent, cmdChan chan string)

func PartEventHandler

func PartEventHandler(room *Room, input chan PacketEvent, cmdChan chan string)

func PingCommandHandler

func PingCommandHandler(room *Room, input chan PacketEvent, cmdChan chan string)

PingCommandHandler handles a send-event, checks for a !ping, and replies.

func PingEventHandler

func PingEventHandler(room *Room, input chan PacketEvent, cmdChan chan string)

PingEventHandler processes a ping-event and replies with a ping-reply.

func ScritchCommandHandler

func ScritchCommandHandler(room *Room, input chan PacketEvent, cmdChan chan string)

func SeenCommandHandler

func SeenCommandHandler(room *Room, input chan PacketEvent, cmdChan chan string)

SeenCommandHandler handles a send-event, checks if !seen command was given, and responds. TODO : make seen record a time when a user joins a room or changes their nick

func SeenRecordHandler

func SeenRecordHandler(room *Room, input chan PacketEvent, cmdChan chan string)

SeenRecordHandler handles a send-event and records that the sender was seen.

func UptimeCommandHandler

func UptimeCommandHandler(room *Room, input chan PacketEvent, cmdChan chan string)

UptimeCommandHandler handlers a send-event and if the command is given replies with the time since the bot was started.

Types

type AuthCommand

type AuthCommand struct {
	Type     string `json:"type"`
	Passcode string `json:"passcode,omitempty"`
}

type BounceEvent

type BounceEvent struct {
	Reason      string   `json:"reason,omitempty"`
	AuthOptions []string `json:"auth_options,omitempty"`
	AgentID     string   `json:"agent_id,omitempty"`
	IP          string   `json:"ip,omitempty"`
}

type Handler

type Handler func(room *Room, input chan PacketEvent, cmdChan chan string)

Handler describes functions that process packets.

type Message

type Message struct {
	ID              string `json:"id"`
	Parent          string `json:"parent"`
	PreviousEditID  string `json:"previous_edit_id,omitempty"`
	Time            int64  `json:"time"`
	Sender          User   `json:"sender"`
	Content         string `json:"content"`
	EncryptionKeyID string `json:"encryption_key_id,omitempty"`
	Edited          int    `json:"edited,omitempty"`
	Deleted         int    `json:"deleted,omitempty"`
}

Message is a unit of data associated with a text message sent on the service.

func GetMessagePayload

func GetMessagePayload(packet *PacketEvent) *Message

type MsgLogEvent

type MsgLogEvent struct {
	Parent   string `json:"id"`
	UserID   string `json:"userID"`
	UserName string `json:"userName"`
	Time     int64  `json:"time"`
	Content  string `json:"content"`
}

type NickCommand

type NickCommand struct {
	Name string `json:"name"`
}

type NickEvent

type NickEvent NickReply

func GetNickEventPayload

func GetNickEventPayload(packet *PacketEvent) *NickEvent

type NickReply

type NickReply struct {
	SessionID string `json:"session_id"`
	ID        string `json:"id"`
	From      string `json:"from"`
	To        string `json:"to"`
}

type PacketEvent

type PacketEvent struct {
	ID    string          `json:"id"`
	Type  PacketType      `json:"type"`
	Data  json.RawMessage `json:"data,omitempty"`
	Error string          `json:"error,omitempty"`
}

PacketEvent is the skeleton of a packet, its payload is composed of another type or types.

func MakePacket

func MakePacket(ID string, msgType PacketType, payload interface{}) (*PacketEvent, error)

func (*PacketEvent) Payload

func (p *PacketEvent) Payload() (interface{}, error)

Payload unmarshals the packet payload into the proper Event type and returns it.

type PacketType

type PacketType string

PacketType indicates the type of a packet's payload.

type PingEvent

type PingEvent struct {
	Time int64 `json:"time"`
	Next int64 `json:"next"`
}

PingEvent encodes the server's information on when this ping occurred and when the next will.

type PingReply

type PingReply struct {
	UnixTime int64 `json:"time,omitempty"`
}

type PresenceEvent

type PresenceEvent struct {
	*User
	SessionID string `json:"session_id"`
}

func GetPresenceEventPayload

func GetPresenceEventPayload(packet *PacketEvent) *PresenceEvent

type Room

type Room struct {
	Logger *logrus.Logger
	// contains filtered or unexported fields
}

Room represents a connection to a euphoria room and associated data.

func NewRoom

func NewRoom(roomCfg *RoomConfig, room string, sr SenderReceiver, logger *logrus.Logger) (*Room, error)

NewRoom creates a new room with the given configurations.

func (*Room) Run

func (r *Room) Run()

Run provides a method for setup and the main loop that the bot will run with handlers.

func (*Room) SendAuth

func (r *Room) SendAuth()

Auth sends an authentication packet with the given password.

func (*Room) SendNick

func (r *Room) SendNick(nick string)

SendNick sends a nick-event, setting the bot's nickname in the room.

func (*Room) SendText

func (r *Room) SendText(text string, parent string)

SendText sends a text message to the euphoria room.

func (*Room) Stop

func (r *Room) Stop()

type RoomConfig

type RoomConfig struct {
	DBPath       string
	ErrorLogPath string
	Join         bool
	MsgLog       bool
	MsgPrefix    string
	Nick         string
	Password     string
}

RoomConfig stores configuration options specific to a Room.

type SendCommand

type SendCommand struct {
	Content string `json:"content"`
	Parent  string `json:"parent"`
}

type SendEvent

type SendEvent Message

SendEvent is a packet type that contains a Message only.

type SendReply

type SendReply SendEvent

type SenderReceiver

type SenderReceiver interface {
	// contains filtered or unexported methods
}

type User

type User struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	ServerID  string `json:"server_id"`
	ServerEra string `json:"server_era"`
}

User encodes the information about a user in the room. Name may be duplicated within a room

type WSSenderReceiver

type WSSenderReceiver struct {
	Room string
	// contains filtered or unexported fields
}

func NewWSSenderReceiver

func NewWSSenderReceiver(room string, logger *logrus.Logger) *WSSenderReceiver

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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