bot

package
v0.0.0-...-67b6ef9 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: MIT Imports: 17 Imported by: 1

README

B# Bot

Official Server

Using the B# bot, you can run B# code within Discord!

Official Discord Server: https://discord.gg/ecyFpQWFE4

Main Commands

Use /run to run code, /create to create tags, and /edit to edit tags.

Tags can be imported using

[IMPORT "<tag id>.bsp"]

Other Commands

Images can be added to tags using /image, and descriptions can be added using /description. View a tag's info and stats using /info and a tag's source using /source.

Database

Tags can store data in between uses using the database system. There are 4 commands:

Usage Description
[DB SET key value] Sets a key in the database to a value
[DB GET key] Returns the value of that key in the database
[DB EXISTS key] Returns "true" if the key exists, "false" if it doesn't
[DB USE id] Uses another tag's database. ⚠ NOTE: Other tags' databases are read-only

Buttons

The BUTTON function creates a button object, which is just a MAP{STRING}STRING. It accepts the ID of the button and it's Label as the first and second parameters respectively.

The BUTTONS function accepts input. It accepts a 2-dimensional array of BUTTON objects. Each element in the array is a row of buttons. The return value is the ID of the button pressed.

The user can be requested to press a button as such:

[PRINT 
  [BUTTONS
    [ARRAY
      [ARRAY
        [BUTTON "Click Me!" "clicked"]
      ]
    ]
  ]
]

It will print clicked (the ID of the button) when the button is clicked.

A grid of buttons can be generated as such:

[DEFINE btns [MAKE MAP{STRING}STRING{}{}]]
[DEFINE i 0]
[WHILE [COMPARE [VAR i] < 3]
  [DEFINE j 0]
  [DEFINE row [MAKE MAP{STRING}STRING{}]]
  [WHILE [COMPARE [VAR j] < 3]
    # Add btn
    [APPEND [VAR row] [BUTTON "🔲" [CONCAT [STRING [VAR i]] "," [STRING [VAR j]]]]]

    [DEFINE j [MATH [VAR j] + 1]]
  ]
  [APPEND [VAR btns] [VAR row]]
  [DEFINE i [MATH [VAR i] + 1]]
]

[PRINT 
  [BUTTONS 
    [VAR btns]
  ]
]

It will print out the position of the button ont he grid when a button is pressed.

Button Styling

The button styling functions accept a Button object and return it too. They can be chained together or done seperately. For example

[DISABLE [COLOR [BUTTON "Green!" "green"] 3]]

is the same as

[DEFINE btn [BUTTON "Green!" "green"]]
[COLOR [VAR btn] 3]
[DISABLE [VAR btn]]

[VAR btn]

Buttons can be enabled using ENABLE and DISABLE.

Button colors can be set using the COLOR function. The following button colors are available:

ID Color
1 Primary
2 Secondary
3 Danger
4 Success

Additional Tags

The following tags are available in the bot in addition to the builtin tags:

Tag Description
[USERID] Returns the User ID of the user running the tag
[INPUT prompt] Prompts the user to provide input, and returns the provided input
[MULTIPLAYER enabled] If enabled, allows multiple people to respond to buttons and INPUT

Documentation

Index

Constants

View Source
const ItemsPerPage = 10
View Source
const MaxTime = time.Second * 150

Variables

View Source
var Exts = []*ir.Extension{
	{
		Name:    "DB",
		Params:  []types.Type{types.IDENT, types.STRING, types.VARIADIC},
		RetType: types.STRING,
	},
	{
		Name:    "USERID",
		Params:  []types.Type{},
		RetType: types.STRING,
	},
	{
		Name:    "INPUT",
		Params:  []types.Type{types.STRING},
		RetType: types.STRING,
	},
	{
		Name:    "MULTIPLAYER",
		Params:  []types.Type{types.BOOL},
		RetType: types.NULL,
	},
	{
		Name:    "BUTTON",
		Params:  []types.Type{types.STRING, types.STRING},
		RetType: types.NewMapType(types.STRING, types.STRING),
	},
	{
		Name:    "BUTTONS",
		Params:  []types.Type{types.NewArrayType(types.NewArrayType(types.NewMapType(types.STRING, types.STRING)))},
		RetType: types.STRING,
	},
	{
		Name:    "DISABLE",
		Params:  []types.Type{types.NewMapType(types.STRING, types.STRING)},
		RetType: types.NewMapType(types.STRING, types.STRING),
	},
	{
		Name:    "ENABLE",
		Params:  []types.Type{types.NewMapType(types.STRING, types.STRING)},
		RetType: types.NewMapType(types.STRING, types.STRING),
	},
	{
		Name:    "COLOR",
		Params:  []types.Type{types.NewMapType(types.STRING, types.STRING), types.INT},
		RetType: types.NewMapType(types.STRING, types.STRING),
	},
}

Functions

func BuildCmd

func BuildCmd(b *Bot) sevcord.SlashCommandObject

func CreateCmd

func CreateCmd(b *Bot) sevcord.SlashCommandObject

func DescriptionCmd

func DescriptionCmd(b *Bot) sevcord.SlashCommandObject

func EditCmd

func EditCmd(b *Bot) sevcord.SlashCommandObject

func Error

func Error(ctx sevcord.Ctx, err error) bool

func ErrorMessage

func ErrorMessage(ctx sevcord.Ctx, msg string)

func ImageCmd

func ImageCmd(b *Bot) sevcord.SlashCommandObject

func InfoCmd

func InfoCmd(b *Bot) sevcord.SlashCommandObject

func LbCmd

func LbCmd(b *Bot) sevcord.SlashCommandObject

func NewExtensionCtx

func NewExtensionCtx(id string, dat *db.Data, ctx sevcord.Ctx) *extensionCtx

func RunCmd

func RunCmd(b *Bot) sevcord.SlashCommandObject

func SourceCmd

func SourceCmd(b *Bot) sevcord.SlashCommandObject

Types

type Bot

type Bot struct {
	*sync.RWMutex
	*db.DB
	// contains filtered or unexported fields
}

func NewBot

func NewBot(path string, token string) (*Bot, error)

func (*Bot) Autocomplete

func (b *Bot) Autocomplete(ctx sevcord.Ctx, val any) []sevcord.Choice

func (*Bot) BuildCode

func (b *Bot) BuildCode(filename string, src string, ctx sevcord.Ctx) (*ir.IR, error)

func (*Bot) BuildCodeCmd

func (b *Bot) BuildCodeCmd(ctx sevcord.Ctx, args []any)

func (*Bot) BuildFileCmd

func (b *Bot) BuildFileCmd(ctx sevcord.Ctx, args []any)

func (*Bot) BuildTagCmd

func (b *Bot) BuildTagCmd(ctx sevcord.Ctx, args []any)

func (*Bot) Close

func (b *Bot) Close()

func (*Bot) CompileCode

func (b *Bot) CompileCode(filename, src string, ctx sevcord.Ctx) (string, error)

func (*Bot) CreateCmd

func (b *Bot) CreateCmd(src string, id, name string, ctx sevcord.Ctx)

func (*Bot) CreateCodeCmd

func (b *Bot) CreateCodeCmd(ctx sevcord.Ctx, args []any)

func (*Bot) CreateFileCmd

func (b *Bot) CreateFileCmd(ctx sevcord.Ctx, args []any)

func (*Bot) DescriptionCmd

func (b *Bot) DescriptionCmd(ctx sevcord.Ctx, args []any)

func (*Bot) EditCmd

func (b *Bot) EditCmd(ctx sevcord.Ctx, src string, id string)

func (*Bot) EditCodeCmd

func (b *Bot) EditCodeCmd(ctx sevcord.Ctx, args []any)

func (*Bot) EditFileCmd

func (b *Bot) EditFileCmd(ctx sevcord.Ctx, args []any)

func (*Bot) ImageCmd

func (b *Bot) ImageCmd(ctx sevcord.Ctx, args []any)

func (*Bot) InfoCmd

func (b *Bot) InfoCmd(ctx sevcord.Ctx, args []any)

func (*Bot) LbUsedCmd

func (b *Bot) LbUsedCmd(ctx sevcord.Ctx, args []any)

func (*Bot) RunCode

func (b *Bot) RunCode(filename string, src string, ctx sevcord.Ctx, extensionCtx *extensionCtx) error

func (*Bot) RunCodeCmd

func (b *Bot) RunCodeCmd(ctx sevcord.Ctx, args []any)

func (*Bot) RunFileCmd

func (b *Bot) RunFileCmd(ctx sevcord.Ctx, vals []any)

func (*Bot) RunTagCmd

func (b *Bot) RunTagCmd(ctx sevcord.Ctx, vals []any)

func (*Bot) SourceCmd

func (b *Bot) SourceCmd(ctx sevcord.Ctx, args []any)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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