Skip to content

jimscarver/rho-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#MacRhoLang @RHO-bot (complete google doc)

Chatbots have become a leading means of managing distributed systems. @RHO-bot in the CoLab discord chat allows us to interface to a rchain node (rhobot.net,soon to be on testnet) in a language we cooperatively define. We define macros of parameterized rholang snippets allowing them to be used like user defined commands, functions or variables generating code to be run on rchain. It employs discord identities to create toy private and public keys enabling demonstration of contracts running on rchain with simple command interface. E.g. testing voting contracts and getting community sentiment on discord without people needing to learn rholang:

newBallot: "colors",  Set("red", "green", "blue")

vote: “colors”, “green”

voteresults: “colors”

@RHO-bot is a work in progress being cooperatively constructed in the colab currently employing the cpp macro preprocessor and clang-format formatter for rholang on rchain with a discord.js chatbot.  @RHO-bot is running on rhobot.net. The source code is in github.

Built in commands

eval: <macrholang code>

Expands macros, if any, and then executes the resulting rholang code and posts result from the log in the channel. Macros are defined if the output includes [“#define $name”,aValue]

echo: <macrholang code>

Expands global macros (excluding personal macros such as private key) and posts the result to the channel.

define: $<name> <macrholang code>

define: $<name>($arg, …) <macrholang code including $args substitution>

e.g.

define: $Ballot rho:id:3qfh1fy7jwfcai7ceyorux4a18hzcn83n9xb6dramjf5gs7cw8fynf

define: $print($expression) new stdout(rho:io:stdout) in { stdout!($expression) }

find: <optional search regular expression>

deploy:

No arguments, deploys the tuple space of the last thing you evaluated on rchain.

propose:

No arguments. Proposes a block consisting of deploys from any user.

Private data data locker and user mailbox macro commands

makemylocker:

mylockerGet: *stdout

mylockerGet: “key”, *stdout

mylockerStore: “key”, “value”

mylockerUpdate: “key”, “value”

Mailbox macro commands

We communicate with other members through their write only public mailbox (inbox.rho). We can send messages that may include capabilities granting access rights such as the right to vote on a ballot.

send: “username”, “type”, “subtype”, data….

receive: “type”, subtype”, *stdout

peek: *stdout

peek: “type”, *stdout

peek: “type”, “subtype”, *stdout

Directories

$newDirectory($name)

$addUser($username,$directory)

Voting

newBallot: "colors",  Set("red", "green", "blue")

allowtovote: "jimscarver","colors"

allowgrouptovote: “colab”, “colors”

vote: "colors", "red"

voteresults: "colors"

Example using macros in Rholang code to share data and capabilities

Discord markup renders rholang wrong such that characters are missing and copied programs are broken unless in a code block started and ended with ```

We get the advantage of somewhat useful syntax highlighting if we start with ```scala

define: $share($username, $type, $subtype)

new return in (

  $peek($type, $subtype, *return) |

  for ( list &lt;- return) {

    $send($username, [$type, $subtype] ++ *list)

  }

}

Then I can invoke the macro as a command to share my colab directory admin capabilities:

share: "Emmanuel_mebyz", "directory", "colab"

Your rchain application

Build a Discord Bot

This is a quick and easy template for building your own Discord bot, this project relies on Discord.js, if you want to extend this bot, I suggest you look at the official Discord API documentation and the Discord.js README.

Before building your own bot, I highly advise checking if the bot you want to build already exists, the common places to find Discord bots are:

Getting Started

Step One
You need to create a new Discord Application in the developer console.

Step One Screenshot

Step Two
You need to create a Bot User for your application. Step Two Screenshot

Step Three
You need to add your Bot User's token as a parameter to client.login(), these will be used by the code to act on behalf of your registered application's bot.

If you want to avoid unneeded complexity, untick Require OAuth2 Code Grant.

Step Three Screenshot

Step Four
Generate your bot's OAuth2 URL and it can then be invited to any channel with just a click of a link.

Step Four Screenshot

Step Five
Remix this project, look through the code in server.js and add the custom commands you wish your bot to have and VIOLA, you're now the proud owner of your own Discord bot 🎉🎉🎉🎉

Go build something cool.

More about Discord

Discord is all-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone. Stop paying for TeamSpeak servers and hassling with Skype. Simplify your life.

More about Glitch

Glitch is the friendly community where you'll build the app of your dreams. Glitch lets you instantly create, remix, edit, and host an app, bot or site, and you can invite collaborators or helpers to simultaneously edit code with you.

Find out more about Glitch.

This project was built by Greg Worrall 🎉


\( ゜o゜)ノ Follow me on Twitter or GitHub.

About

MacRhoLang robot on discord

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published