Git Product home page Git Product logo

torimies-rs's Introduction

torimies-rs

How the bot works

Users of the bot can create and remove vahti-entries that they have made. Vahti-entries are stored in the sqlite-database of the bot. The vahtis in the database are periodically checked for new matches on the tori.fi site using an undocumented api endpoint, and new matching listings are then sent to the vahti's creator.

Features

Available features-flags are

  • "tori"
  • "huutonet"
  • "discord" (both "discord-command" and "discord-delivery")
  • "discord-delivery"
  • "discord-command"
  • "telegram" (both "telegram-command" and "telegram-delivery")
  • "telegram-delivery"
  • "telegram-command"

Default features include all the features. Configure your instance according to your needs with cargo build --release --no-default-features --features LIST,OF,FEATURES Please not that the program does not compile if no site-support is configures (atleast one of features "tori" and "huutonet")

Hosting the bot

Discord:

If you do not have a discord application ready create one here. Create a bot user for the application if one doesn't already exist.

When you have your discord application ready, visit the following link to generate an invite link: https://discord.com/developers/applications/YourAppID/oauth2/url-generator. Replace "YourAppID" with the application id of your application.

The discord application invite link used should have the following scopes:

  • bot - required for the invite link to be a bot-invite link
  • applications.commands - required for the bot commands to be usable

Make sure to create the .env file if it does not exist and ensure that it contains all the necessary variables:

  • DATABASE_URL=database.sqlite (or another location)
  • DISCORD_TOKEN=YourToken (the token for your discord bot)
  • APPLICATION_ID=YourAppID (the discord application id)

Optional variables:

  • UPDATE_INTERVAL=time_in_seconds (the interval at which the bot updates vahtis, defaults to 60)
  • FUTURES_MAX_BUFFER_SIZE=integer (the argument given to buffer_unordered defining the amount of concurrent futures. Recommended amount is ~6*$(nproc) and a larger amount may cause problems, defaults to 10)

Telegram:

Create a bot with @BotFather set TELOXIDE_TOKEN value to the API-token.

Make sure to create the .env file if it does not exist and ensure that it contains all the necessary variables:

  • DATABASE_URL=database.sqlite (or another location)
  • TELOXIDE_TOKEN=YourToken (the token for your telegram bot)

Optional variables:

  • UPDATE_INTERVAL=time_in_seconds (the interval at which the bot updates vahtis, defaults to 60)
  • FUTURES_MAX_BUFFER_SIZE=integer (the argument given to buffer_unordered defining the amount of concurrent futures. Recommended amount is 50, raising it above that will most likely bring diminishing returns. Default value is 50)

With Docker

Bot can be started by running command docker-compose up -d.

Log viewing happens with command docker-compose logs.

docker-compose up -d --build rebuilds the Docker image and restarts the container with the new image.

Bot can be shut down with command docker-compose down.

Without Docker

Before starting the bot you must setup the sqlite-database. This can be done with the diesel tool, which is used in these instructions.

diesel can be installed using cargo install diesel_cli.

After installing the diesel tool the reset_db.sh script can be run to automatically set up the database, deleting any existing database.

The binary builds include a pre-initialized database.

Autodeploy

Use watchtower to pull automatically the latest image.

For databases setup before diesel-migration

If you have a database with pre-existing data, the diesel tool wont be able to apply the migrations.

In order to run the migrations I've written a simple script that temporarily gets rid of the initial_migration and then runs the migrations.

Please remember to change the DATABASE_URL to database.sqlite instead of sqlite:database.sqlite :)

Then see sqlx_migrate.sh

Running torimies-rs

If you are building from source run cargo run --release in the root of the repository.

If you are are using a binary build run ./torimies-rs.

Using the bot

The bot has two main commands implemented as application commands (slash-commands) and those are:

  • /vahti url Adds a new vahti with the specified url
  • /poistavahti url Removes the vahti with the specified url
  • /poistaesto Prompts you with a drop-down menu to select which seller you wish to unblock

One additional owner-restricted commmand is also included (this is not a slash-command):

  • !update_all_vahtis immediately updates all vahtis

Please keep in mind that the bot is still considered to be WIP. We will gladly accept any feedback/feature requests :), just file an issue and we'll look into it.

torimies-rs's People

Contributors

ahnl avatar chicken avatar drvilepis avatar eldemarkki avatar lajp avatar mixu78 avatar roytakanen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

torimies-rs's Issues

Flatten the curve

Figure out how to distribute the updates of Vahtis so that they are spread evenly to the whole duration of the update interval.
It's not optimal that the network (and cpu-usage) graph looks like this.
image

Regions broken

There seem to be some issues currently with correctly converting the tori.fi regions.
This causes users to receive tons of notifications.

Add verification for vahti urls.

At the moment, the search-urls provided by the users are not checked at all. Perhaps a mechanism that allows a vahti to only be placed for a search that has results would be a good solution...

Add command menu to @Torimies_bot in Telegram

I would love to see command menu on @Torimies_bot in Telegram like this:

image

This can be done by sending the following message to @Botfather (first run command /mybots, select your bot, choose edit bot and finally click edit commands):

start - Display start message
help - Display help message
vahti - Add new vahti with /vahti `[url]`
poistavahti - Remove a vahti with /poistavahti `[url]`

reset-db.sh not working on some machines

This is weird. Some machines require the --database-url while other machines can't stand it.

Perhaps something along the lines of sqlx database setup --database-url sqlite:database.sqlite || sqlx database setup could work

Optimization

If two or more users have a tracker for same keyword but different regions, then just request all entries for that keyword in the whole country and do the region filtering in the code. This would make the bot more scalable (at least a little bit) because the amount of requests can go down somewhat huge amounts due to specific keywords being used more often (Thinkpad) than others.

Write some tests

While the codebase is maturing and getting larger and more feature-full everyday it is starting to become more and more apparent than in order to guarantee the stability of the main branch and the codebase in general, we need to have a test-suite that must be run on every commit and pull-request.

In general it would make it easier for us maintainers to well maintain the repository and more difficult for everyone to "push bad code"

In addition to this, some kind of auto-formatting using cargo fmt would be nice too in order to maintain readability.

Add support for mobile-urls

The urls look similar to this: https://m.tori.fi/li?he=1&ca=18&sp=0&fmy=0&q=palvelin&cg=5030&w=118&c=5042&st=s&f=a&ps=&pe=

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.