Skip to content

CharlesYuan02/mary-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mary-bot

Introduction

A Discord bot I created in Go. Her name is Mary. After receiving my offer to work at Uber, I knew I had to learn Go right away, as my interviewer informed me that that was the primary language they used for back end development. I decided to learn some noSQL and MongoDB to implement a database-driven game so that people will actually interact with her (cuz my classmate said that Eve was "so useless").

Want to invite her to your server? Use this link.

Disclaimer: The images are from an old MMORPG named Elsword. I take no credit.

Getting Started

To get started, you'll need to sign up to become a Discord developer, create a bot (application), then get your token. You'll also need a MongoDB Database Cluster URI, which you can find under SECURITY -> Database Access -> Connect -> Connect your application. Remember to whitelist your IP Address or allow all IP addresses if you're hosting!

Prerequisites

github.com/bwmarrin/discordgo v0.26.1
github.com/joho/godotenv v1.4.0
go.mongodb.org/mongo-driver v1.11.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d

Local Deployment

Once you have your token, if you are deploying locally, create a .env file with the following:

MONGO_URI = "mongodb+srv://<username>:<password>@<clustername>.<something>.mongodb.net/?retryWrites=true&w=majority"
OWNER_ID = "yourDiscordUserID"
TOKEN = "yourtoken"

Then, you can run:

go run mary.go

Deployment on Google Cloud Virtual Machine

First, if you haven't already, you'll need to create a Google Cloud account and enable the Compute Engine API. Follow the first part of these instructions if you need help. After that, you will need to set up dependencies on your virtual machine (i.e. wget, git, Go, tmux):

$ sudo apt-get install wget
$ sudo apt-get install tmux
$ wget https://storage.googleapis.com/golang/go1.19.linux-amd64.tar.gz
$ sudo tar -xvf go1.19.linux-amd64.tar.gz
$ sudo mv go /usr/local
$ sudo apt install git

Then, clone the repo and find your GOPATH directory:

$ git clone https://github.com/Chubbyman2/mary-bot.git
$ pwd

Next, create a .env file with your environment variables:

$ cd mary-bot
$ sudo nano .env 
### Copy-paste your env vars into this file, CTRL + X, Enter to save

Afterwards, set up your go environment in a tmux session (see this tutorial for details).

$ tmux
$ export GOROOT=/usr/local/go
### Set GOPATH=[response from pwd], mine is /home/charlesyuan59
$ export GOPATH=/home/charlesyuan59
$ export PATH=$GOROOT/bin:$GOPATH/bin:$PATH

Finally, you can run Mary in the tmux session:

$ go run mary.go
### CTRL+B (hold), then D to exit out of tmux session

Additionally, here are some useful commands for tmux:

### Show tmux instances and their id numbers
$ tmux ls 
### Join tmux instance
$ tmux a -t [id]
### Kill tmux session
$ tmux kill-session

Built With

DiscordGo

DiscordGo is a Go package that provides low level bindings to the Discord chat client API. DiscordGo has nearly complete support for all of the Discord API endpoints, websocket interface, and voice interface. The backbone for this entire project.

MongoDB Go Driver

The MongoDB Go Driver allows me to store and retrieve data from a MongoDB noSQL database using Go. This is the backbone for the economy system.

Google Cloud + tmux

Google Cloud's Compute Engine provides me with a virtual machine instance that I can ssh into, download my dependencies, and host Mary from. I then used tmux to run the code in the background, so that when I close the secure shell window, Mary keeps running.

Update March 4, 2023

My GCP trial ran out, so I've switched to using Fly.io. I've also been working for the past two weeks on more economy functions. This includes trivia, inventory, shop, give (an item, not coins), buy, sell, and five different use commands. The help, trivia, inventory, shop, and profile commands are all sent as rich embeds now, too! Feel free to try them out.

Demo

Future Plans

StockInfo

Basically, I want to add a basic stock trading feature to Mary. No stops or limits, just buy and sell using the Yahoo Finance API. The implementation will be similar to what I did with trivia (API call) and inventory (portfolio of stocks). StockInfo will retrieve the current value of the stock along with other relevant information.

BuyStock, SellStock

Buy and sell a stock at the market price.

Portfolio

Portfolio will display the user's current stock porfolio, the value of each stock currently, the original purchase price, and the overall performance.

MaryPortfolio

A school project I am doing is a sentiment analysis stock trader, which I plan on turning into an API. I will let Mary have her own trading portfolio using the API for buy and sell suggestions.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Discord bot I made in Go. Her name is Mary.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages