Skip to content

One-Piece-Society/OPBOT

Repository files navigation

OPBOT - Another Python cogs-based discord bot

Overview

The following is a python based bot designed to help the UNSW OPSOC discord sever generate engagement and allow for members to get additional information about the OP universe.

Considerations

When designing the bot the following was considered.

  • Able to be run through an always-online server running docker
  • Low maintenance
  • Low processing power and networking bandwidth

Features

  • Help page with up-to-date spec
  • Random image generator (inc data)
  • Bot stats
  • Guess the character game
  • User profile
  • Auto verification tagger
  • Manual verification bypass
  • Verification logs + timestamps
  • RPG-style character collector
  • Search character feature

The Setup

  1. If API keys or config file does not exist create a new file named config.ini and insert the following

    [keys]
    DiscordAPI-Key=XXXX.XXXX.XXXX
    
    [verification]
    webhookCommand=Command!
    webhookBotID=1234567890
    targetChannelID=1234567890
    unverifiedRole=role1
    verifiedRole=role2
    errorStateChannel=1234567890
    
    [adminstration]
    level1OverRide=1234567890
    level2OverRideRole=role3
    
    [testing]
    isproduction=false
    disableAdmin=false
    DisableMultiplayer=false
  2. Start an instance of Docker

  3. Build script using docker

    docker build -t dockerfile .
    
  4. Run a script from Docker command

    docker run -dp dockerfile
    

Data logging and information

There is a comprehensive verification log with time stamps in the "admin.log" file, and "rpgData.log" is a secondary log for user info.

Google app script plugin module

To implement verification with google forms a webhook is used to read received messages. You can implement the code linked to a Google form here.

alt text

const POST_URL = {Webhook URL};

function onSubmit(e) {
  Utilities.sleep(30000);

  const response = e.response.getItemResponses();
  let items = [];
  let username = "";

  for (const responseAnswer of response) {
    const question = responseAnswer.getItem().getTitle();
    const answer = responseAnswer.getResponse();
    let parts = []

    try {
      parts = answer.match(/[\s\S]{1,1024}/g) || [];
    } catch (e) {
      parts = answer;
    }

    for (const [index, part] of Object.entries(parts)) {

      if (question == "Discord Tag (e.g. abcde#1234)") {
        username = part;
      }
    }
  }

  const options = {
    "method": "post",
    "headers": {
      "Content-Type": "application/json",
    },
    "payload": JSON.stringify({
      "content": "Auth!verifyUserWebServer1.1 " + username
    })
  };

  UrlFetchApp.fetch(POST_URL, options);
};

Maintaining functionality

  1. Generate Python module requirements with

    pipreqs ./ --force
    

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages