diff --git a/discordbot/CONTRIBUTING.md b/discordbot/CONTRIBUTING.md new file mode 100644 index 00000000000..1d923e4599a --- /dev/null +++ b/discordbot/CONTRIBUTING.md @@ -0,0 +1,17 @@ +## Code Structure and Contributing + +UNDER DEVELOPMENT! + +The file system is built in the following way: +- Each command is one file with the essential functions for the command and is named COMMANDNAME.py. +- Each context is a directory and has a menu file named CONTEXT_menu.py. +- The menu file works by controlling every command in the context and it contains the menu command. +- discordbot.py can loads every menu file from each context. +- The settings shall be in the config_discordbot.py file (example: API keys). + +If a function is often used by multiple files then add them to the helpers.py file. Please try to use the _view files +from the GST to get the data for the commands if possible. + +Feel free to contribute to the discord bot, add more contexts, commands or just do other improvements. To see the +current prioritize of the development see the TODO list in the discord bot project +(https://github.com/GamestonkTerminal/GamestonkTerminal/projects/4). diff --git a/discordbot/README.md b/discordbot/README.md index 19896b3d17a..31c7f23c45c 100644 --- a/discordbot/README.md +++ b/discordbot/README.md @@ -1,97 +1,105 @@ -# DiscordBot -Implementation of a discord bot, which is WORK IN PROGRESS +# Discord Bot - WORK IN PROGRESS - -
-

- - Logo - + +

Table of Contents

+
    +
  1. Install Requirements
  2. +
  3. Registering Applications
  4. + +
  5. Discord Configs
  6. +
  7. Run Locally
  8. +
  9. Contributing
  10. +
  11. Bugs
  12. +
-## Set Up -### Step 1: Getting a discord bot -Go to https://discord.com/developers/applications and click on "New Application" (See Picture 1) -Enter a name for example "Gamestonk Terminal Discord Bot" -Picture 1: -Logo -Then go to the bot page: -Logo -Then press "Add Bot": -Logo -Now go to your applications "OAuth2" Tab: +## Install Requirements -Logo -Then copy your Client ID: -Logo -Then invite your bot to your discord server by replacing the ENTERCLIENTID with your copied client ID in this url: https://discord.com/oauth2/authorize?client_id=ENTERCLIENTID&scope=bot (You can also do it on via this link generator https://discordapi.com/permissions.html where you can select the proper permissions) -After clicking the link you'll see something similar to this: -Logo -Register your app here. Choose “OAuth 2 authorization without a callback URL”. Registering is free for all open source projects and if your discord bot uses fewer than 1,250 uploads per day. You will receive an client ID and client secret once you submit the form. +This tutorial assumes that you have successfully installed Gamestonk Terminal. -### Step 2: Get the scripts to run the GST Discord Bot - -(Note this assumes that you already have installed GST for more info about the installation: https://github.com/GamestonkTerminal/GamestonkTerminal#getting-started) - -Download the code from this repository. - -Then open the config_discordbot.py file and go back to https://discord.com/developers/applications/ and go to your bot page. There you'll have to copy the token -Logo - -Then change the settings in the config_discordbot.py. Make sure to add the proper filepath to the GamestonkTerminal folder. -Add your discord token and imgur id to your environment variables as "GT_DISCORD_BOT_TOKEN" & "GT_IMGUR_CLIENT_ID" or -change the string in the config. You can also change the command prefix, date format, debug mode and other parameters in the settings -part of the config file. - -From the config_discordbot.py file: +Next, go into the discordbot folder with `cd discordbot` and install the following packages: +``` +pip install discord +pip install discord_components +pip install pyimgur +``` + +## Registering Applications + +### DISCORD + +1. Login into your discord account in https://discord.com/developers/applications +2. On the "Applications" tab, select "New Application" and name it something like "GST Bot". This will create a new application. +3. For creating a bot, we need to go into the "GST Bot" application previously created, and on the "Bot" tab select "Add Bot". Note: On this same page you can manage the bot permissions with regards to the server it will be added. +4. Next we need to obtain the "Client ID". For that we choose the "OAuth2" tab and copy our "Client ID" under "Client". +5. At this stage the bot is created and we are ready to invite it to one of our servers. To do so we need to access: +https://discord.com/oauth2/authorize?client_id=CLIENTID&scope=bot, where **CLIENTID** is replaced by the value copied above. +6. If everything went well, you should see a window popup where the Bot that was just created asks to which of your own servers do you want to add it to. + +**NOTE:** If you haven't managed the bot permissions on the Bot tab previously you can do it via this link generator https://discordapi.com/permissions.html + +### IMGUR + +1. Login into your https://imgur.com account. Create one if you don't have it. +2. Access https://api.imgur.com/oauth2/addclient to create your application. +3. Select "OAuth 2 authorization without a callback URL" when creating such. +4. You will receive a client ID and client secret once you submit the form. + +**NOTE:** Registering is free for all open source projects and if your discord bot uses fewer than 1250 uploads per day. + +## Discord Configs + +In order to config the discord bot you will need to edit the [config_discordbot.py](gamestonk_terminal/config_discordbot.py) file. + +1. Edit the path to the terminal by changing the variable `GST_PATH`. E.g. ``` -# Path to the terminal GST_PATH = os.path.join("~", "Documents", "GamestonkTerminal") sys.path.append(GST_PATH) - -# https://discord.com/developers/applications/ -DISCORD_BOT_TOKEN = os.getenv("GT_DISCORD_BOT_TOKEN") or "REPLACE_ME" - -# https://apidocs.imgur.com -IMGUR_CLIENT_ID = os.getenv("GT_IMGUR_CLIENT_ID") or "REPLACE_ME" - -# Settings -COMMAND_PREFIX = "!" -DATE_FORMAT = "%Y-%m-%d" -COLOR = discord.Color.from_rgb(0, 206, 154) -MENU_TIMEOUT = 30 -DEBUG = True - -AUTHOR_NAME = "Gamestonk Terminal" -AUTHOR_ICON_URL = ( - "https://github.com/GamestonkTerminal/GamestonkTerminal/" - "blob/main/images/gst_logo_green_white_background.png?raw=true" -) ``` -### Step 3: -Activate your GST virtual environment and go to the place where your main.py file is located and run it. -Logo -You're finished! Go to your server and you should see the bot online!!! +2. Update `DISCORD_BOT_TOKEN` using discord bot CLIENT ID obtained previously in [discord](#discord). -## Code Structure and Contributing -The file system is built in the following way: -- Each command is one file with the essential functions for the command and is named COMMANDNAME.py. -- Each context is a directory and has a menu file named CONTEXT_menu.py. -- The menu file works by controlling every command in the context and it contains the menu command. -- discordbot.py can loads every menu file from each context. -- The settings shall be in the config_discordbot.py file (example: API keys). +2. Update `IMGUR_CLIENT_ID` using imgur application CLIENT ID obtained previously in [imgur](#imgur). -If a function is often used by multiple files then add them to the helpers.py file. Please try to use the _view files -from the GST to get the data for the commands if possible. +#### Advanced -Feel free to contribute to the discord bot, add more contexts, commands or just do other improvements. To see the -current prioritize of the development see the TODO list in the discord bot project -(https://github.com/GamestonkTerminal/GamestonkTerminal/projects/4). +Other parameters that can be configured are: -## What if something doesn't work? +- **DEBUG**: Shows a debug message on the terminal console of what's happening on the discord bot from the server side. +- **COMMAND_PREFIX**: Command prefix to be used when calling the bot from the discord server. +- **DATE_FORMAT**: Selects date format to be used as parameter on the discord bot. +- **COLOR**: Changes color of the bot messages replies on the discord server. +- **MENU_TIMEOUT**: Timeout in seconds to allow user to select options when a menu command is invoked from the discord bot. +- **AUTHOR_NAME**: Name of the discord bot in the server. +- **AUTHOR_ICON_URL**: Icon displayed on the discord bot replies on the server. -Make sure to follow the steps in the download guide. If an error occurs anyway then activate the debug mode in the -config file and see where the error occurs in your terminal. Join the GST discord and report your issue in the #bugs -channel. Otherwise, there's the possibility to open a GitHub issue or message northern-64bit. +## Run Locally +Just run the discord bot from this folder with: +``` +python discordbot.py +``` + +Now, you should be ready to invoke the discord bot from server using something like: + +``` +!stocks.dps TSLA +``` + +Screenshot 2021-10-18 at 00 21 30 + + +## Contributing + +See more in [CONTRIBUTING.md](discordbot/CONTRIBUTING.md). + +## Bugs + +If an error occurs, use `DEBUG=True` on the [config_discordbot.py](gamestonk_terminal/config_discordbot.py) file. + +Then, report what is the issue with the console output attached either by: +- [Opening an issue on github](https://github.com/GamestonkTerminal/GamestonkTerminal/issues/new/choose) +- Contacting either `DidierRLopes` (@SexyYear) or `northern-64bit` diff --git a/discordbot/images/image.png b/discordbot/images/image.png deleted file mode 100644 index 0980b2307c3..00000000000 Binary files a/discordbot/images/image.png and /dev/null differ diff --git a/discordbot/images/picture_1.png b/discordbot/images/picture_1.png deleted file mode 100644 index ee115226247..00000000000 Binary files a/discordbot/images/picture_1.png and /dev/null differ diff --git a/discordbot/images/picture_2.png b/discordbot/images/picture_2.png deleted file mode 100644 index b05938ee5e9..00000000000 Binary files a/discordbot/images/picture_2.png and /dev/null differ diff --git a/discordbot/images/picture_3.png b/discordbot/images/picture_3.png deleted file mode 100644 index 943ed9fa7da..00000000000 Binary files a/discordbot/images/picture_3.png and /dev/null differ diff --git a/discordbot/images/picture_4.png b/discordbot/images/picture_4.png deleted file mode 100644 index 918d7da0d68..00000000000 Binary files a/discordbot/images/picture_4.png and /dev/null differ diff --git a/discordbot/images/picture_5.png b/discordbot/images/picture_5.png deleted file mode 100644 index cdfe0cd61b2..00000000000 Binary files a/discordbot/images/picture_5.png and /dev/null differ diff --git a/discordbot/images/picture_6.png b/discordbot/images/picture_6.png deleted file mode 100644 index 383d5e08ed0..00000000000 Binary files a/discordbot/images/picture_6.png and /dev/null differ diff --git a/discordbot/images/picture_7.png b/discordbot/images/picture_7.png deleted file mode 100644 index a1050436b5f..00000000000 Binary files a/discordbot/images/picture_7.png and /dev/null differ