Skip to content

ajyuan/Monitori

Repository files navigation

Mobile_Img

About

Hello, my name is Monitori!
I'm a sentiment analysis bot built for a social/messaging platform called Discord. My purpose is to increase user engagement while encouraging positivity and rewarding server members for saying nice things. I am currently hosted on a Raspberry Pi B+, althought I also have the built in functionality to run on Glitch.io. To support hosting on Raspberry Pi, I use VADER to perform efficient sentiment analysis.

Features

  • Message caching system for adaptive score calculation and more accurate sentiment analysis
  • Automatic garbage collection for inactive users to reduce memory usage
  • Dynamic credit system that rewards users based on the sentiment rating of their messages
  • Detailed leaderboard system (to remind members who the most positive users in the server are :p)
  • Dynamic message queue processing that analyze messages once the bot detects a conversation has ended
  • Built-in SQLite importing and exporting for easy backup and modification

How I work

To determine the sentiment of users, I internally cache all messages written a server and map them to their respective users. Massage caching is used to improve my sentiment analysis accuracy, since analyzing a series of messages in a single conversation at once will allow me to better determine a user's overall sentiment in a conversation, as opposed to analysis on a per message basis. Automatic message caching can be switched on and off using the $activate and $deactivate commands, respectively. If you would like me to run without automatic caching, you can set set autopayThreshold to 1 in config.json. While I store the majority of my database internally for fastest response time, I can also automatically back up to an SQL database and import/export my database in SQL in order to preserve data when the bot goes offline. You can read more about my settings in the configuration section.

When prompted or when I detect a conversation has ended, I determine a user's positivity using the VADER sentiment analysis library, which is a "lexicon and rule-based sentiment analysis tool specifically attuned to sentiments expressed in social media." You can read more about VADER here. This tool generates the total positive, neutral, and negative sentiment expressed by a given message, which I use to determine a user's overall impact on a server. You can read more about my internal structure in the files section.

Files

index.js: The main file for the discord bot. It handles the bots interaction with Discord, such as login, message handling, and disconnection.

userMap.js This file acts as the main database for storing information about each discord user. Information stored in here is global, meaning a user will have a global "sentiment" profile regardless of whichever server the user is currently in. It does the following operations:

  • Maps the ID of every Discord user to a User class, which stores important user information such as score history, points, and total messages.
  • Stores the bot's message cache, since messages must be mapped to each user.
  • Performs operations on users, such as analyzing message cache, calculating points and sentiment, and returning values.

guildMap.js This file contains the ranking system for each guild Monitori serves. Leaderboard is required to be a seperate data structure because, unlike userMap (which is a global database), leaderBoard must be server specific, (i.e., a user can be 1st place in one server but 5th place in another). It performs the following operations.

  • Creates update calls to userMap for memebers of a guild.
  • Sorts members of a guild by a given type, (ex. score or points).
  • Stores the bot's Guild classes, which cache generated leaderboards for more efficient sorting. If a new leaderboard is requested for a guild where a previous one had been generated, it may feed a previously sorted array to generate the leaderboard more efficiently, based on certain conditions.

export.js: This file is responsible for handling the SQL database. It handles importing and exporting users to/from users.sqlite and userMap.js. It is also responsible for automatically backing up userMap and data storage on shutdown.

config.json This file contains variables that allow you to configure the bot easily. You can read more about each variable in the configuration section.

Configuration

In order for Monitori to function, it must be provided a bot token. Create a .env file with token=<insert_token_here>. Config file options:

  • botid: This is the Monitori's user id. It's used for ignoring bot messages.
  • admin: This is the user id of the bot admin. Monitori will only accept certain commands if the sender's user ID matches this.
  • prefix: Sets the character that commands must be preceded by in ordered to be recognized as a command by Monitori. Default: "$"
  • filters: Any messages with these prefixes will be ignored. This is useful for ignoring bot commands, etc.
  • dynamicPoints: Enables or disables Monitori's seniment based point system, which rewards points dynamically based on the determined sentiment of a user's messages. Disable to have points rewarded purely on a message volume basis. (1pt awarded for every message sent).
  • awardThreshold: Used for Dynamic Points. Monitori will calculate the cumulative sentiment of queued messages and compare it to each award threshold to determine how many points to award per message. Each threshold is a lower bound. Note: This value must be given specified in sorted order, from least to greatest. This array must be the same size as awardAmount
  • awardAmount: Used for Dynamic Points. If a given user's message queue is lower bounded by a given award threshold, Monitori will use the index of that threshold to map to this array. Note: This array must be the same size as awardThreshold
  • autopayOnInactivityTime: Amount of time in seconds that Monitori will wait before declaring a conversation as over before analyzing cache for participants. Set to 0 to disable.
  • autopayThreshold: Monitori will automatically process all messages in a user's log after it reaches this number of messages. Higher threshold is recommended for more accurate seniment analysis. Lower threshold is recommended if you want to reduce memory usage. Set to 0 to disable (score must be manually calculated using $score or $refresh).
  • autobackupTime: Monitori will analyze the message cache and write user data to its SQL database every x minutes.
  • sortThreshold: This number defines the guild size at which Monitori will switch from Insertion Sort to Merge Sort for generating leaderboard.
  • onJoinDescription: This is the message that is sent when Monitori joins a guild

Notes

  • While Monitori is capable of analyzing text emoticons, it is not able to analyze emojis. Because of this, it is recommended to disable automatic emoticon to emoji conversion (located in Settings > Text & Images) for best results.

Support

Discord Server

About

A Discord sentiment analysis bot that encourages positivity and rewards server members for saying nice things :). Built using Node.js and Discord.js

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published