go-cryptodog

module
Version: v0.0.0-...-b1dd1d8 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2020 License: MIT

README

godog

go-cryptodog

license

go-cryptodog is a general-purpose Golang API for writing programs that interact with Cryptodog.

This software has not been audited, and probably never will be. Use at your own risk.

Basic example
package main

import (
	"fmt"

	"github.com/Cryptodog/go-cryptodog/dog"
)

func main() {
	d := dog.New()

	// Sets long-term storage system to a local folder
	//
	// %USERROFILE%\AppData\Local\DemoBot\ on Windows
	// $HOME/.local/share/DemoBot/ on Unix-like systems
	//
	// Completely optional. if d.DB is not set, it will default to an in-memory store.
	d.DB = dog.FolderStore("DemoBot")

	// Alternatively:
	// d.DB = dog.Disk("/full/path/")

	// Want to connect via Tor/Tor Browser's process? (Note: won't work when compiled to webassembly.)
	// d.Proxy = "127.0.0.1:9150"

	d.On(dog.Connected, func(e dog.Event) {
		fmt.Println("Connected!")
		d.JoinRoom("elysium", "DemoBot")
	})

	d.On(dog.RoomJoined, func(e dog.Event) {
		fmt.Println("Joined room", e.Room)
	})

	d.On(dog.NicknameInUse, func(e dog.Event) {
		fmt.Println("Nickname is in use.")
		d.Disconnect()
	})

	// If this happens, the bot will automatically try to reconnect.
	d.On(dog.Disconnected, func(e dog.Event) {
		fmt.Println("Disconnected :(")
	})

	d.On(dog.GroupMessage, func(event dog.Event) {
		if event.Body == "hello" {
			d.GMf(event.Room, "Hello, %s! How are you today?", event.User)
		}

		if event.Body == "begone" {
			d.GM(event.Room, "sure thing!")

			// Causes d.Run() to return nil (graceful exit)
			d.Disconnect()
		}
	})

	// Blocks until error is returned.
	if err := d.Run(); err != nil {
		fmt.Println(err)
	}
}

Directories

Path Synopsis
cmd
Package multiparty implements the Cryptodog Multiparty Protocol as used in Cryptodog version 2.5.0, and previously, Cryptocat 2.
Package multiparty implements the Cryptodog Multiparty Protocol as used in Cryptodog version 2.5.0, and previously, Cryptocat 2.

Jump to

Keyboard shortcuts

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