Giter Site home page Giter Site logo

skeletonxf / reddit-configurable-reply-bot Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 122 KB

Configurable Rust bot (with Lua) to provide comment replies on reddit

License: GNU Affero General Public License v3.0

Lua 47.30% Rust 49.98% Shell 2.71%
reddit rawr rust lua

reddit-configurable-reply-bot's Introduction

reddit-configurable-reply-bot

WARNING: The core idea of configuring a reddit bot in Lua remains, but rawr is unmaintained so this code base needs major changes before use.

A Rust bot for writing reddit bots in Lua.

This repository contains a Rust bot to interact with reddit. The Rust code is highly configurable from a Lua script to control the reply behaviour, though the Rust code may not be high quality as I am still learning Rust. The bot scans a whitelisted list of subreddits, and only attempts to reply to a comment if it has not replied to it before. The behavior.lua script handles the logic of replying on this more abstract level of dealing with a single comment or post, and calling reply if wanted.

The Rust code defines a number of globals for the Lua script:

  • author - the reddit username that made this comment/post
  • comment - the comment body if the Lua script is running on a comment
  • link - the link url if the Lua script is running on a post
  • post - the post body if the Lua script is running on a post
  • title - the title of a post if the Lua script is running on a post
  • contains(string, substring) -> boolean - a function that checks for a substring in a string
  • containsIgnoreCase(string, substring) -> boolean - the same as contains but case insensitive
  • matchesRegex(string, regex) -> boolean - a function that checks if the supplied string matches the regex (Rust regex not Lua regex)
  • toLowercase(string) -> string - a function that returns the lowercase version of a string (this is Unicode aware unlike Lua)
  • reply(string) - replies to the post/comment (after replying the bot will not invoke your Lua script on this post/comment again, if you want to reply multiple times you need to do so in one pass and not wait to be reran)

Example bot that replies to 'ping' with 'pong' anywhere it sees it (this would be your behaviour.lua script).

local message = comment or post
if contains(message, 'ping') then
  reply('pong')
end

That was easy :)

Also you should look over the Reddit bottiquette before making your bot. This example would surely get your bot banned for spam and is only illustrative.

This repo also contains the legacy python script for the same behavior in the python legacy branch. The python script is no longer maintained.

While also being a configurable reply bot, the behaviour.lua script here is used to continue on the goal from the Python project of responding to comments containing specific words on /r/Demisexuality. The definition list is very much a work in progress and is still growing.

Running

The Rust bot should run from a call to cargo run in the root directory. You will need to create an authentication.json file from the example authentication.json.example in order for the bot to connect to a reddit account to post from. The subreddits.json file contains an array of subreddits for the bot to scan and reply in.

Credit

When I first made the Python version of this bot I mainly chose Python because I could not find a tutorial in any other language. I have come a long way since then, but could not have made the switch without the help of this online book.

License

Reddit Configurable Reply Bot / Reddit Sexuality Definition Bot is free software: you can redistribute it and/or modify it under the terms of the GNU General Affero Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The AGPL is quite restrictive, it requires source code to be made available even if you run your bot from a server to rather than distributing a binary for others to run. Github offers free hosting and you can get started by forking this repository.

(The now unmaintained python version of this project was licensed under the MIT license)

Known issues

  • Bot attempts to reply to archived content which fails and causes a crash. Because this fails the content is never added to the database of replies, and therefore the bot will crash every time it reaches the content.

reddit-configurable-reply-bot's People

Contributors

skeletonxf avatar

Watchers

 avatar  avatar  avatar

reddit-configurable-reply-bot's Issues

No longer compiles

Unfortunately this crate's dependency rawr which was unmaintained even before this crate was written no longer compiles at all due to ancient OpenSSL dependencies. I tried updating rawr's dependency on hyper to the latest version, but rawr also depends on an unmaintained serde_codegen which depends on an unmaintained syntex_syntax which I cannot get to compile.

I could maybe fix the hyper breakages if I looked into it enough but I've never used hyper myself and I do not understand what serde_codegen was even doing so I think removing that dependency may be beyond me. It seems to be exclusively used in rawr's responses module to preprocess rust files when building?

I suppose this is a lesson in don't write something new using something that's already dead.

At the time of writing this bot creation system rawr was the only high level reddit library I could find. From a cursory look at crates.io there appear to be some new libraries around that are in a working state.

I think if I ever pick this up again, or if someone else wants to, then the best course of action is removing this crate's dependency on rawr and replacing it with a different reddit library entirely. This should be somewhat straightforward because the only file in this crate with substantial depdendencies on rawr is reddit.rs

I am also aware that rlua is looking for maintainers...

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.