Code Monkey home page Code Monkey logo

degenquote-bot's Introduction

Quote-Bot

A Telegram Bot to store quotes.

Installation

Clone the git repository and install the npm modules:

$ git clone https://github.com/realChesta/degenquote-bot.git
$ cd degenquote-bot
$ npm install
$ npm start

For the GPT-2 features, you will need to install Tensorflow 1.15 (2.0 is not supported currently) and GPT-2-Simple and feed the trained checkpoint into src/gpt2/checkpoint/run1.

Configuration

Run the bot once to create an empty settings.json.

Alternatively, create it yourself. It should look like the following:

{
    "token": "MISSING_TOKEN",
    "quotes_per_page": 5,
    "admins": [],
    "actions": [],
    "enable_markov_for_clusters": [],
    "enable_gpt2_for_clusters": [],
    "markov_file": "markov.json",
    "python_name": "python3",
    "gpt3_key": "",
    "bot_handle": "my_tg_bot_handle_bot"
}
  • "token": your Telegram Bot API token
  • "quotes_per_page": how many quotes should be displayed per page with /list
  • "admins": the usernames of the users who should be able to manage the bot (can use /stop a.o.)
  • "actions": contains special configurable actions, see next section
  • "enable_markov_for_clusters": list of clusters in which the bot will respond with markov messages when replied to
  • "markov_file": the path to the Markov chain file
  • "python_name": name or path of the Python interpreter executable (for GPT-2)
  • "gpt3_key": the gpt-3 key for the openai-api
  • "bot_handle": the bot handle

Actions

Quote-Bot can react to regexes with messages you configure. To do this, simply add an action to the actions array in settings.json. It should have one of the following formats:

{
    "match": matchPredicate,  // see Match Predicates section below
    "probability": number, // optional
    "cluster": string, // optional; only run if the chat is in the given cluster
    "group": string, // optional; if given and multiple actions of the same group match, only the first will be executed
    "response": responseString | [responseType, responseValue]  // see Response Types section below
}

or

[matchText, probability, responseText]

// shorthand for:
// {
//   "match": {
//     "text": matchText
//   },
//   "probability": probability,
//   "response": ["text", responseText]
// }

Example:

"actions": [
    ["im sad", 1, "don't be sad, little one :)"],
    {
        "match": {
            "text": "he[ln]lo\\s+world", 
            "from": {
                "first_name": "^Bill$",
                "last_name": "^(Gates|Clinton)$"
            },
            "date": ["obj >= 1751117820"]
        },
        "probability": 0.5,
        "response": [
            "sticker",
            "1234ab"
        ]
    }
]

#### Match Predicates Match predicates are special values that will be compared to the raw message object delivered by the Telegram API as detailed here. A match predicate object is one of the following:

  • a string: matches if the predicate is a regex matching the input object's string representation (case-insensitive). Empty string matches all values
  • a number: matches if the predicate is equal to the input object's numeric representation (NaN is equal to NaN, +0 is equal to -0)
  • a boolean: matches if the predicate is equal to the input object's truthiness
  • null: matches if the input object is null
  • an object with string keys and matchPredicate values: matches if the input object is an object or an array and each entry matches the respective match predicate
  • a single-element tuple of the form [string]: matches if the JavaScript expression evaluates to a truthy value given that the input object is stored in a parameter obj (example: ["obj === 1"] matches if the input object is equal to 1)

Response Types

  • ["text", message]: reply with text
  • ["sticker", stickerid]: reply with a sticker
  • ["image", imageurl]: reply with an image from the internet
  • ["video", videourl]: reply with a video from the internet
  • "markov": reply with a markov chain message
  • "gpt2": reply with a GPT-2 message

Usage

Run the bot using npm:

$ cd degenquote-bot
$ npm start

degenquote-bot's People

Contributors

bvoq avatar fyodordev avatar n2d4 avatar realchesta avatar sgitkene avatar

Watchers

 avatar

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.