Giter Club home page Giter Club logo

graham_discord_bot's Introduction

Graham - Discord Bot for BANANO and NANO

GitHub release (latest) License CI

Graham is the most advanced, highest performing discord bot for any cryptocurrency ever. It is built for the BANANO and NANO cryptocurrencies.

The features of this bot include on-chain tipping, rains, favorites, wide-variety of statistics, giveaways, a suite of administration commands, and more.

Why do I want this?

Because Graham is awesome, with it you can:

  • Allow users to tip each other for quality content, etc.
  • Increase engagement in your discord server via features such as rains and giveaways
  • Help educate people on cryptocurrencies and the value they provide

Where can I see it in action?

Head to the BANANO Discord - you can see both the NANO and BANANO bots in action just by typing ?help and .help

How do I add it to my server?

Graham is currently not public, but it will be soon! In the meantime you can follow the instructions below to setup your own.

Setting up your own Graham

Requirements

Graham 4.0+ requires the following:

  • A unix environment (MacOS or Linux or WSL)
  • Python 3.7+
  • PostgreSQL or SQLite3
  • A Redis Server/Database
  • A NANO or BANANO node - setting up a node. You will want to enable RPC and enable_control once your node is up and running. node configuration

It sounds like a lot, but it's actually quite simple.

On ubuntu 18.04 you can get everything you need with:

$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt install python3.7 python3.7-dev redis-server git
# And if you choose to use PostgreSQL over SQLite
$ sudo apt install postgresql

Installing these requirements is dependent on your operating system, you should be able to find out how to install them quickly with a simple google search, example: "How to intall python 3.7 on centos 7", "how to install python 3.7 on MacOS catalina"

Configuring the bot

There are 3 different "groups" of settings to configure the bot.

  1. Environment Sensitive variables are stored in the environment. There are two environment variables that are required to run the bot. You can put this in a file called .env in the same directory as the project.
# The ID of the wallet the bot will use
# This is returned to you when you use `wallet_create`
WALLET_ID=1234
# Bot Token
# See here for how to obtain one:
# https://www.writebots.com/discord-bot-token/
BOT_TOKEN=1234
  1. Command Line Arguments These are all required options, but they have typical defaults already specified. Use python3.7 bot.py --help to see the full list of options.

  2. YAML Configuration File A file fulled of optional settings, everything in the file is optional - typically these settings tweak the bot's behavior and various thresholds. You need to create the file config.yaml with the options you want, you can see all of the available options in config.yaml.example

PostgreSQL or SQLite?

You can use PostgreSQL or SQLite with Graham. SQLite is an easier to setup and a more portable solution (easier to copy the database to different machines, etc.), but it's potentially more prone to corruption, less performant, etc.

Using SQLite The bot will use SQLite by default and you don't have to configure anything.

Using Postgres

After postgres is installed

# Run psql as postgres user
$ sudo -u postgres psql

Run the following to create your database, changing mypassword, user_name, and database_name with whatever you want.

create role user_name with login password 'mypassword';
create database database_name;
grant all privileges on database database_name to user_name;
\q

Then add these to the .env, creating one if it doesn't already exist.

POSTGRES_DB=database_name
POSTGRES_USER=user_name
POSTGRES_PASSWORD=mypassword

You can also override the postgres host and port if desired with POSTGRES_HOST and POSTGRES_PORT

Setting up callback

Create a config.yaml if it doesn't already exist, ensure the following is added to it:

server:
  # The host/port of the bot's aiohttp server
  # Used for callbacks and APIs
  # Callback is at $host:$port/callback (e.g. 127.0.0.1:11337/callback)
  host: 127.0.0.1
  port: 11337

Then in your node configuration at ~/BananoData/config-node.toml or ~/Nano/config-node.toml add:

[node.httpcallback]
address = "::ffff:127.0.0.1"
port = 11337
target = "/callback"

Then your bot will notify users when they make a deposit.

Installing python dependencies

We're going to use a virtualenv as the environment our bot will run in.

# Create virtualenv
$ python3.7 -m pip install virtualenv
$ python3.7 -m virtualenv venv
$ source venv/bin/activate
# Install requirements
$ pip install -U -r requirements.txt

Running the bot

Once you have configured your .env file you can run the bot.

# get a list of options you can override
$ python bot.py --help
# Run bot
$ python bot.py

Installing as a service

You can run Graham as a system service if you want it to automatically start on boot.

With systemd (Linux)

Create the file /etc/systemd/system/graham.service

Add the following

[Unit]
Description=Graham Bot
After=network.target

[Service]
Type=simple
User=YOUR_LINUX_USER
Group=YOUR_LINUX_USER
WorkingDirectory=/home/YOUR_LINUX_USER/graham_discord_bot
EnvironmentFile=/home/YOUR_LINUX_USER/graham_discord_bot/.env
ExecStart=/home/YOUR_LINUX_USER/graham_discord_bot/venv/bin/python bot.py

[Install]
WantedBy=multi-user.target

Enable it to start on boot:

$ sudo systemctl enable graham

Start it:

$ sudo systemctl start graham

Check status:

$ sudo systemctl status graham

How do I upgrade from Graham 3.0 to Graham 4.0?

Upgrading is not officially supported or documented.

If you want to attempt to update while migrating data - install a fresh Graham 4.0 first

You can then reference the script in the v3_migrate folder.

The script MAY NOT fit your situation!

It should be used as a reference, and you should modify it as necessary.

graham_discord_bot's People

Contributors

artombado avatar bbedward avatar kirby1997 avatar majicgit avatar mconstant avatar plasmapower avatar renesq avatar slightlyskepticalpotat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graham_discord_bot's Issues

QOL Improve Copy and Pasting of address from .wfu command

https://github.com/bbedward/Graham_Nano_Tip_Bot/blob/master/bot.py#L1962

Instead of separating items {2} and {3} with a space I feel like they should be separated by a new line. Unless the Discord window is very large, these items are not displayed on the same line usually. This results in it being too easy to copy the space that follows the address as it is very small and hard to notice. This can be annoying when trying to copy and paste the address and forgetting.

annoying space

Add support for graphene based coins like STEEM and BTS

Hello,
Great work indeed. I appreciate the hard work done by you. I am looking for similar tip bot with STEEM coins since steem has large userbase on discord. I can help with the configuration of steem nodes and address creation. Might create a PR if you agree.

PS : did you know you can be rewarded by utopian.io for your open source work with STEEM ? Check out https://www.utopian.io and https://steemit.com/@utopian-io.
You can create a steem account for as low as $2.50 at https://www.swapsteem.online

Change Giveaway's name to lottery

Giveaway is free, without any entry fee, so it should be called lottery because lotteries have an entry fee.

Or create a real giveaway by removing entry fee function.

Bot made me in 4.6k banano debt

image
I withdrew 7.5k (still didn't went through) few days ago.
Can you get me out of debt? Thanks
imalfect#7015
id: 852640730093453372

Update SQL utilities for postgres

It's kinda nice to be able to see how many transactions are sitting unprocessed and all the old sqlite utilities and scripts are now obsolete.

I think new ones would be best to be written in python and utilize the DB settings in settings.py

Make database asynchronous

This requires 2 things

  1. switching from sqlite to preferably postgres

  2. Using an asynchronous database adapter like asyncpg or aiopg. Maintaining peewee as ORM preferable if possible

No list of library dependencies

I have this issue.
File "bot.py", line 20, in <module> import wallet File "/home/gfosu1997/graham/wallet.py", line 2, in <module> import db File "/home/gfosu1997/graham/db.py", line 59, in <module> db = PooledPostgresqlExtDatabase(settings.database, user=settings.database_user, password=settings.database_pas sword, host='localhost', port=5432, max_connections=16) TypeError: 'NoneType' object is not callable
I'm thinking I probably have installed a different version of peewee from what you use to create this bot. A list of dependencies in the doc would really help myself and others or just adding the versions you have to the repo itself. I'm not sure if this repository is still being maintained but I would appreciate anyone who could get back to me on this.

Understanding the behavior of the bot

I have taken this codebase as the starting point for a Bitshares tipbot.

I am having some problems answering some questions about how the code behaves. Could I possibly tip you $10.00 per question? Alternatively, I could document the code so that other developers can understand how it functions. To faciliate this:

  1. What is your decision on using Common Python Standards to format the code. There is no sense in me contributing patches to the functions until we come to agreement on this?
  2. Would you accept the friend request from princepawn on Discord so we can discuss this there?

Redesign database schema for future

The database schema is sloppy and was hacked together as features were added.

Some things that need to be considered

  1. Old schema needs to be migratable to new schema

  2. Separate stats and accounts into their own tables. Accounts should be a one-to-one relationship with the users table and stats should be a one-to-many relationship - reason being in point #4

  3. Any ID from discord is an integer and those fields need to be changed to Integer fields. Discord IDs also need to be primary keys where applicable

  4. Server-specific stuff. For future scaling options we need to make stats server specific. Attaching a server ID to the new stats table should be sufficient.

Probably more stuff

Expand test coverage

Need to add test coverage for all parts of the codebase.

  • Test utilities
  • Test db
  • Test cogs
  • Test rpc
  • Test tasks/tx queue

Make the Bot "public"

By making the bot public, you would allow people to invite the bot to more Discord servers.
While spinning up a VM and a DB isn't "rocket science", it still is a significant barrier of entry for community managers who just want to find an easy solution to "tipping users for good content".

This would improve Nano's user adoption significantly.

triple tip worked, but only last tip got emojis.

i did .ban, saw no response emojis.
did .ban again, no response emojis.
did .ban a third time, only the third one got check marks.
but all three went through.

I deleted the posts since they were spam in the tahiti channel. I'm not sure if deleting them had anything to do with it, as I waited a while (2 minutes) before deleting them.

Make transaction processing more scalable

This has a couple of main components

  1. Moving RPC send and receive actions to a separate process. Investigate using persistent queues to communicate between processes. In current setup the secondary process should not interact with the database at all due to multi write limitations of sqlite. It should be strictly for work/send/receiving and should communicate the results back to the main process which would then update our database.

This would increase thoroughput quite dramatically due to limitations with python threading and the GIL

  1. Figure a way to separate work_generate from the send/receive action and distribute among multiple peers. This is a little tricky as there's so much activity the frontiers frequently change.

Usernames are not escaped (in tip notification)

Here is notification screenshot:

sample

It seems that user have ' in his name, which had not been encoded, and Discord received it as formatting char. Not sure how powerful is message formatting in Discord and what negative result can "smart" username lead to, but this is still kind of injection bug.

Websocket closed with 4014, cannot reconnect

I'm trying to run the bot on Ubuntu 20.04 and I can't get it to work.

python3.7 bot.py
INFO:root:Initializing database
INFO:root:Using SQLite database dev.db
INFO:tortoise:Tortoise-ORM startup
connections: {'default': {'engine': 'tortoise.backends.sqlite', 'credentials': {'journal_mode': 'WAL', 'journal_size_limit': 16384, 'file_path': 'dev.db'}}}
apps: {'db': {'models': ['db.models.user', 'db.models.account', 'db.models.stats', 'db.models.transaction', 'db.models.muted', 'db.models.favorite', 'db.models.giveaway'], 'default_connection': 'default'}}
INFO:root:Graham server running at 127.0.0.1:11337
INFO:discord.client:logging in using static token
INFO:root:Re-queue task started
INFO:discord.gateway:Shard ID None has sent the IDENTIFY payload.
INFO:discord.gateway:Websocket closed with 4014, cannot reconnect.

Active users? Feature add!

.banrandom & .brain both claim to send a tip to "active member(s)" Hpow do you know who ise an active member?

I have seen how on other servers there is a time limit to who is considered "active", and have myself been dropped from "active" status when I was didn't respond to the current conversation because it didn't involve me or anything I cared about.

Add a "Whos is active" command "Or other such meth0d to inform people they might not be considered active, anymore.

Single codebase for banano/nano

There's really no need for two separate codebases.

We can just add a setting for banano, then for banano we use different raw conversions and aliases, block explorers, etc

The arrest/mute type of functionality should be moved to Beatrice

Reformat code to be PEP-8 Compliant.

Hello, I noticed this is your first code in Python and Discord. It is very impressive. I don't know how you feel about this, but the standard coding guidelines for Python are outlined in PEP-8.

I was successful in reformatting the code automatically using autopep8 and this command line:

autopep8 --in-place --aggressive --aggressive

And then changing to the util directory and doing the same.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.