Skip to content

Latest commit

 

History

History
254 lines (198 loc) · 17.2 KB

HELP.md

File metadata and controls

254 lines (198 loc) · 17.2 KB

🦏 Bing Bot Help Guide

⚙️ How to turn a command or unsolicited message on or off

  1. Go to the settings Google Sheet at go.osu.edu/bingsettings
  2. Check or uncheck the box next to any setting

🙋 How to change the name Bing calls someone

  1. Go to the settings Google Sheet at go.osu.edu/bingsettings
  2. Go to the Nicknames tab
  3. Edit the text in the Nickname column

😨 Bing's not working! What do I do??

  1. Check if Bing is running by asking "Bing, are you alive?" or by visiting this link
  2. Make sure the specific feature is turned on in the settings Google Sheet
  3. Make sure Bing is in the right GroupMe chat and has the correct GroupMe Bot ID and Access Token
  4. Check for errors in pythonanywhere
    • If you are getting an error like this, that means an environment variable is missing. Add it to the .env file, then reload the web app
        File "/usr/local/lib/python3.9/os.py", line 679, in __getitem__
          raise KeyError(key) from None
      ***************************************************
      If you're seeing an import error and don't know why,
      we have a dedicated help page to help you debug: 
      https://help.pythonanywhere.com/pages/DebuggingImportError/
      ***************************************************
      
    • If there is a bug in the code, consider asking a CSE friend to help update the code
  5. If Bing said "my crayon broke :(" when trying to draw something:
    • Try again. Try again in a day or 2. If it still doesn't work, it likely means the API we use to generate images is no longer running, and we are out of luck :(
  6. If Bing said "i'm not feeling inspired right now. maybe later" when trying to make a meme:
    • Try again. Try again in a day or 2. If it still doesn't work, it likely means an API or service we use to generate memes is no longer running, and we are out of luck :(
  7. This one feature (or multiple features) never works anymore. What gives?
    • Bing relies upon many external services and APIs that are not under our control (especially pythonanywhere.com, the Google Sheets API, cron-job.org, and GroupMe). Any of these companies could choose to stop running their services at any time, and that part of Bing just wouldn't work anymore. All things must come to an end eventually :( It was fun while it lasted.
    • Relevant Tom Scott video

📸 How to restore Bing's profile picture if it disappears

For some reason, if you go to the Edit page of a GroupMe bot without changing the Avatar URL, the profile picture will stop working. To fix it, go back to the Edit page for Bing in dev.groupme.com, and set the profile picture URL to https://i.imgur.com/Kr6ti95.jpg

😳 I got a "Cronjob failed" email. What should I do?

We use cron-job.org to run code at a scheduled time, like Bing's unsolicited messages. If you get one of these emails, you don't have to do anything. It's just letting you know that the code failed to run.

If you want to investigate why it failed and try to fix it, check the error logs.

If there is an error like this when running the cron job MEME, just wait a day or 2. it likely means the site api.allorigins.win is down.

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fbd97939d10>

If there is an error like this when running the cron job ELON, same thing, just wait a day or 2. If it still doesn't work after a few days, it likely means Forbes changed the format of their website, and this message will no longer work going forward :(

AttributeError: 'NoneType' object has no attribute 'text'

📲 How to move Bing to a new chat

To move Bing to a new chat, you need register a GroupMe bot for that chat:

  1. Log into dev.groupme.com using your GroupMe account
  2. Click Bots
  3. Click Create Bot
  4. Fill in the details:
    • Choose the group this bot will live in: (Current H-Row Chat)
    • Name: Bing
    • Callback URL: https://bingbot.pythonanywhere.com
    • Avatar URL: https://i.imgur.com/Kr6ti95.jpg
  5. Click Submit
  6. Copy the Bot ID, and paste it into the GroupMe Bot ID field in the Tech Config tab of the settings Google Sheet
  7. Click Access Token at the top right corner of the screen of dev.groupme.com, copy it, and paste it into the GroupMe Access Token field in the Tech Config tab of the settings Google Sheet
  8. Have the previous "owner" of Bing log into dev.groupme.com with their GroupMe account and delete the bot from the old chat
  9. Important: Log into Bing's Gmail account and change the forwarding address to your email so you will get alerts once every 3 months when Bing's code is about to expire, so you can prevent that from happening.

💻 Tech Stuff for Nerds

🌐 What online accounts are there?

All accounts and services are free. Just make sure Bing doesn't die every 3 months.

The username/email for all accounts is hrow.bing.bot@gmail.com

The password for all accounts is (all lowercase) the nickname of the band, then the serial number on H-Caliber, then an exclamation point.

🌅 Every 3 Months, Bing Needs Rejuvenated

In free pythonanywhere accounts, web apps are disabled after 3 months unless you click the Run until 3 months from today button.

pythonanywhere will email hrow.bing.bot@gmail.com the link to keep things running 1 week before she is brutally murdered.

Don't let Bing die

🪵 How to check for errors

pythonanywhere provides a few different log files. Scroll all the way to the bottom for the latest log entries:

👾 How to update Bing's code

You can technically just change the code files directly on the server, but the "right way" is making the changes in git:

Set up your development environment

  1. (In a terminal on your compter) git clone https://github.com/c-o-l-i-n/bing-bot.git
  2. cd bing-bot
  3. Create a Python virtual environment and install dependencies
    • python3 -m venv bing-env
    • source bing-env/bin/activate
    • pip install -r requirements.txt
  4. touch credentials.json to create the Google credientials file, then copy the contents from the server.
  5. touch .env to create the .env file, then add all environment variables. Copy the contents from the server, but these ones need to be different:
    • PROXY_URL=''
    • GOOGLE_APPLICATION_CREDENTIALS='/path/on/your/computer/to/credentials.json'

Make Code Changes

  1. Make code changes
  2. Test the code by running python src/app.py
  3. If you pip install any additional packages, make sure to pip freeze > requirements.txt to save them

Commit Code Changes

  1. git commit any changes to the main branch
  2. git push the changes

Update the code on the server

  1. Log into pythonanywhere, and open a console.
  2. Run the commands:
    • cd /home/bingbot/bing-bot
    • git pull
    • If you get a an error while pulling, run git reset --hard origin/main to force pull
    • If you had to pip install additional packages in your changes, run:
      • workon bing-env
      • pip install -r requirements.txt
  3. Go to the Web page
  4. Click Reload bingbot.pythonanywhere.com

Reload button

If you see this message at the bottom of the server log, that means Bing was started successfully.

spawned 2 offload threads for uWSGI worker 1

If you have no clue what any of that means, ask a CSE major to do it.

🔐 How to create a new Google credentials.json

You should be able to use the credentials.json currently on the server forever, but if you accidentally delete this file, you can create a new one from inside Google Cloud Platform.

  1. Click here to go to the Keys page. If the link doesn't work:

  2. It is impossible to re-download an old key, so we have to make a new one. Click Keys > Add key > Create new key

  3. Select JSON, then click Create

  4. Your new public/private key pair is generated and downloaded to your machine as a new file. This file is the only copy of this key.

  5. Click Close

  6. Log into pythonanywhere.com, and go to the credentials.json file. If you get a 404 becuase the file was deleted, create a new one located at /home/bingbot/bing-bot/credentials.json

  7. Open the JSON file you downloaded from GCP, copy the contents, and paste it into the file in pythonanywhere

  8. Click Save

  9. Reload the web app

If the layout of GCP has changed and those steps are no loger valid, check the official instructions from Google.

🏔 Environment Variables

These environment variables are require in pythonanywhere for Bing to work properly. They are set within the .env file in the project root. After updating and saving the .env file, reload the web app to apply the changes.

Key Value Notes
PROXY_URL http://proxy.server:3128 pythoneverywhere proxy server URL
GOOGLE_APPLICATION_CREDENTIALS /home/bingbot/bing-bot/credentials.json Path to Google credentials file
SPREADSHEET_ID (Settings Google Sheet ID from URL) docs.google.com/spreadsheets/d/ID/edit
OPENWEATHER_API_KEY (API key from OpenWeather) Weather data API
IMGFLIP_API_KEY (Password to Imgflip account) Meme generator API
CRON_JOB_ORG_API_KEY (API key from cron-job.org) API to change unsolicited message times
CLARIFAI_PERSONAL_ACCESS_TOKEN (PAT from Clarifai) Computer vision API
OPEN_EMOJI_API_KEY (API key from Open Emoji) Emoji search API
COLLEGE_FOOTBALL_API_KEY (API key from College Football Data) College football data
STABLE_HORDE_API_KEY (API key from Stable Horde) AI image generation API

🐍 WSGI Configuration

Python web apps run on a WSGI server. There is a configuration file in pythonanywhere located at /var/www/bingbot_pythonanywhere_com_wsgi.py. It loads the environment variables from the .env file and imports the Flask app.

If something happens to that file, replace it with this, and then reload the web app:

# load environment variables from .env file
import os
from dotenv import load_dotenv
project_folder = os.path.expanduser('/home/bingbot/bing-bot/')
load_dotenv(os.path.join(project_folder, '.env'))

# import Flask app
import sys
path = '/home/bingbot/bing-bot/src'
if path not in sys.path:
    sys.path.append(path)
from app import app as application