Coder Social home page Coder Social logo

eibex / reaction-light Goto Github PK

View Code? Open in Web Editor NEW
120.0 10.0 63.0 610 KB

Easy to use self-hosted reaction role Discord bot written in Python.

License: MIT License

Python 99.83% Dockerfile 0.17%
discord discord-bot python bot role-management role reaction reactions self-hosting discord-server

reaction-light's Introduction

eibex

Heya, I'm Eibe, a geek and tech passionate that enjoys programming as a hobby. Even though I'm usually extremely busy with work, I try to keep improving my programming skills and contribute to the open-source projects I use. I enjoy self-hosting things on VPS and home servers.

When I'm not busy with work, or when I feel like destroying my sleep schedule, I work on Reaction Light.

GitHub Stats

reaction-light's People

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reaction-light's Issues

Option to limit users to only select one reaction

Could be useful if certain roles need to be mutually exclusive and admins want to enforce this.
If the user already selected a reaction, but then selects another, the bot should remove their old reaction (and role) while adding their new role.

Bot doesn't start

Describe the bug

Unable to start the bot. ( I tried with 2 machines with fresh installations of the bot)

To Reproduce

Just try to run the bot with python3 bot.py

Expected behavior

Starting....

Screenshots

grafik

Server:

  • OS: Ubuntu 4.15.0-136-generic
  • Python version: Python 3.6.9
  • discord.py version: 1.6.0

Traceback

File "<fstring>", line 1
    ((await getchannel(system_channel)).mention if system_channel else 'none')
                     ^
SyntaxError: invalid syntax

Something went wrong :|

Screenshot_2021_0917_181344
Screenshot_2021_0917_181324

this happened when I typed "pip install dotenv" in shell (I use replit) I'm using my phone (Vivo 1604)
Please help me if you know whats wrong :)

Prevent users from using reactions from other servers

The bot can only use unicode emojis or reactions uploaded to the server it is being used on. If nitro users try to use reactions from other servers the bot should refuse to use them and warn the user instead of just returning errors after the creation process.

Bot not adding reactions

My bot isn't adding reactions.

So i tried to make a reaction message today and it all worked except when the bot tried to add the reactions, it had enough permissions to do so, its just the fact it outputted this error:

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\DiscordBotExport\FlickzReactions\reaction-light-master\bot.py", line 363, in on_message
    "I could not commit the changes to the database. Check"
AttributeError: 'int' object has no attribute 'mention'
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\DiscordBotExport\FlickzReactions\reaction-light-master\bot.py", line 363, in on_message
    "I could not commit the changes to the database. Check"
AttributeError: 'int' object has no attribute 'mention'
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\DiscordBotExport\FlickzReactions\reaction-light-master\bot.py", line 363, in on_message
    "I could not commit the changes to the database. Check"
AttributeError: 'int' object has no attribute 'mention'
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\DiscordBotExport\FlickzReactions\reaction-light-master\bot.py", line 363, in on_message
    "I could not commit the changes to the database. Check"
AttributeError: 'int' object has no attribute 'mention'
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\DiscordBotExport\FlickzReactions\reaction-light-master\bot.py", line 363, in on_message
    "I could not commit the changes to the database. Check"
AttributeError: 'int' object has no attribute 'mention'
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\DiscordBotExport\FlickzReactions\reaction-light-master\bot.py", line 363, in on_message
    "I could not commit the changes to the database. Check"
AttributeError: 'int' object has no attribute 'mention'
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\DiscordBotExport\FlickzReactions\reaction-light-master\bot.py", line 363, in on_message
    "I could not commit the changes to the database. Check"
AttributeError: 'int' object has no attribute 'mention'
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\DiscordBotExport\FlickzReactions\reaction-light-master\bot.py", line 363, in on_message
    "I could not commit the changes to the database. Check"
AttributeError: 'int' object has no attribute 'mention'
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\DiscordBotExport\FlickzReactions\reaction-light-master\bot.py", line 363, in on_message
    "I could not commit the changes to the database. Check"
AttributeError: 'int' object has no attribute 'mention'
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "C:\DiscordBotExport\FlickzReactions\reaction-light-master\bot.py", line 363, in on_message
    "I could not commit the changes to the database. Check"
AttributeError: 'int' object has no attribute 'mention'

It would mean a lot of you could help, thank you!

Replace hardcoded admin_a, b, c with a single list variable

Is your feature request related to a problem? Please describe.
I don't like the idea of manually adding more admins or using 0s in case you need less than 3.

It would be possible to have a single admin var in config.ini that is equal to all the admin role IDs separated by a comma.

configparser is not capable of reading lists from a var, but it is possible to use .split(",") on the string.

Then we could just make isadmin() check whether the ID is in the list or not.

Describe the solution you'd like
The real issue is making the bot update the old config.ini to the new one automagically so that hosters do not need to manually change the config file so that it matches the new Python file.

Describe alternatives you've considered
So far my ideas are:

  • Make a new python file with a "migration" class that is imported at the start of bot.py. This could be used for this update and future ones, but if a user skips two "migrations" I would imagine the bot could break.
  • Make a "migration" python file that users need to run manually (this will break the bot if a user just rl!update without reading the changelog though).
  • Make the bot tell the user to apply the necessary changes if an exception is raised when parsing config.ini. This won't work if systemchannel is not set though.

I will try to think of more ways to handle this, but if anyone has ideas please feel free to share them.

Notification on new role (guild)

Is your feature request related to a problem? Please describe.

An user will not see the change when an new role is added and new category will appear because many servers are too "large" (infinete scroll).

Describe the solution you'd like

An private message when the user choose one of roles with an custom message.
Ex. You have an new role added: @name, and new category access you can visit it here: #the-new-category

I don't have.

A clear and concise description of any alternative solutions or features you've considered.

None.

Multiple (2) roles per reaction?

Is there an easy way to allow the bot to give multiple roles for each reaction?

I will try to explain the reason for this;

By default a Discord server allows each user to all categories and channels. Perhaps there is too many, so they allow users to react for roles that hide categories/channels. Which is a better method than reacting to see them.

For these roles that hide (or restrict) access to categories/channels, there could be numerous of them. To keep these roles organized, there is 1 main role above all these roles, like a header. For example it might be called ----HIDDEN---- and every role below this header means that role is hiding/restricting view permissions for the corresponding category/channel.

There is also an issue I can see with this- when users un-react to get access back to categ/chan the bot doesn't know better to not take away this header (---HIDDEN---) role. So it would need to know not to touch that header role unless all reactions from the user have been removed/un-reacted.

Hope this makes sense.

One might say "Why not just give that role on join?" which is a fair point. But heres 2 reasons- the first being your bot that gives auto role on join might only be capable of giving 1 role. The other reason is that the whole point of these roles are for channel organization, so users having the header (---HIDDEN---) role without having any roles under it, would look out of place.

option for inverting reaction role function

Is your feature request related to a problem? Please describe.

Not related to a problem.

Describe the solution you'd like

When users click on a reaction, they lose a role, instead of getting it assigned. unclicking regains them the role.

Describe alternatives you've considered

Haven't been able to come up with any.

Support new lines with slash commands

Slash commands removed the ability to write messages with new lines in them while editing an existing message.

Functionality could be restored possibly by:

  • Using a special character to denote a new line (e.g. $newline$) -> I don't like this
  • Writing "extended_message" and/or "extended_description" in the message or description parameters and having the bot wait_for the contents in a follow up message (or messages if both "special" params are used)

Add support for others messages to be used as RL messages

Is your feature request related to a problem? Please describe.

- (See Describe the solution you'd like)

Describe the solution you'd like

I'd like to be able to use other users messages e.g. users or other bots messages as reaction messages instead of only being able to use the bots own messages as "role switchers". The use case for this is when you for example have multiple rule messages but only need reaction capability on one of them.

The solution I'm thinking is by adding an option in the RL creation process to use a existing message or create one using the bot.

Describe alternatives you've considered

Creating reaction light messages that have no emoji/role combinations attached to them. I've decided against using this due to the unnecessary DB-entries. I've also considered to just add a entry to the database manually but thought others might have the same use case.

Additional context

I can help implement it, just want to see it is something that is seem fit inside the scope of the project.

DB not self-cleaning after deleting servers

Describe the bug

The DB does not clean admin roles, message IDs and related reactions/roles if a server does not exist anymore.

To Reproduce

  1. Create a server
  2. Add an admin
  3. Add a reaction-role message
  4. Delete the server
  5. Restart the bot or wait 24 hours

Expected behavior
The DB cleans itself

missing brackets in database.py

Describe the bug

I was running this on my server, it was going smooth until I noticed this error in code.

rec

I would not like trespass here but to contribute, I would like to make the small change needed :)

Heroku

Make it hosted on heroku because it is a little tricky to set up

Add admin roles with a command

Depends on #17 being fixed.

Allow already existing admins to add new admin roles with a command and update the config.ini accordingly.

It should be able to accept role mentions and integer IDs alike. The need for integer IDs in this command is to add admin roles from a different server if necessary.

Bot doesnt start anymore after update

Describe the bug

Bot doesnt start after update

To Reproduce

Steps to reproduce the behavior:
python3 bot.py

Expected behavior

Bot Starts.

Screenshots

If applicable, add screenshots to help explain your problem.

Server:

  • OS: Debian 10
  • Python version: Python 3.8.10
  • discord.py version: ???

Traceback

Traceback (most recent call last):
  File "bot.py", line 27, in <module>
    import disnake
ModuleNotFoundError: No module named 'disnake'

localization

The bot response message can be set as an additional configuration file
Does it make it easier for users to perform localization work?

Allow to abort setup

Currently, once the setup of a new embed is started it must be completed or the bot must be shutdown.

How to auto delete the first role, when select a rol

Basically I want to know how to auto-delete the first role I config for the new members (In this case: "No-Verified") , I want when they just react with the emoji to the "Verified" role, the "No-Verified" role go away, can this be possible? I don't know how, thanks you so much.

Error in discord.py version 1.5.0

Describe the bug

Is there a chance to upgrade to discord.py 1.5.0
In version 1.3.4 it is ok

Server:

  • OS: MacOS
  • Python version: 3.8.5
  • discord.py version: 1.5.0

Traceback

Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/discord/client.py", line 333, in _run_event
    await coro(*args, **kwargs)
  File "/Users/erwinowak/Desktop/reaction-light-master/bot.py", line 521, in on_raw_reaction_add
    await member.add_roles(role)
AttributeError: 'NoneType' object has no attribute 'add_roles'

Support Slash Commands for the new Discord API

In light of discord.py discontinuation, it will be necessary to rewrite the bot in a new language or library that supports slash commands.

As mentioned in #59 (comment) there are a few discord.py forks that support slash commands. If none seem suitable and stable the rewrite target language will be Rust with the Serenity library.

I am not a Rust developer, it will therefore take time for me to learn the language and migrate the code.

Click on USE existing text in new installation ends in loop

I just installed the bot
added with the new command my first reactions

at the point use existing text or make new one
i choose the icon to use and existing, believing there is some default

now i cant proceed further, so i restarted the bot and tried the edit command
i have to enter a channel and always get the information

There are no reaction-role messages in that channel.

Refactor `message.py`

Refactor message.py:

  • Full rewrite /message new (better code and no more usage of //)
  • More functions to avoid repeated code between edit, reaction, and new (e.g. preparation of embeds to send)

The bot deletes reactionroles although the message still exists.

Bot deletes Reactionroles though the messages still exist

What happens is, that the bot starts deleting stored Reactionroles for messages that still exists, with the reason, that the message got deleted. In fact, the message didnt get deleted. Its still existing.

To Reproduce

This happened to me when restarting the bot multiple times, each restart made it delete 1 reactionrole. This happened locally, but when running on my Windows VPS 2019, it just did the same thing without any restarts.

Expected behavior

The Bot will delete the Rectionrole

Screenshots

None

Server:

  • OS: Windows 10 20H2 / Windows 10 2019 Server
  • Python version: 3.8.9
  • discord.py version: 1.6

Traceback

Theres no traceback since there isnt any error that came up in console.

Move to SQLite

Drop CSV and move to SQLite.

Seeing replies in #17 I thought it was better to separate the discussions in two threads.

This would most likely partially fix #13 as rlightfm would become redundant in its current state.

Furthermore, the creation of a migration script or command may be necessary.

Help! Slash Commands Not Registering

Pls help:

Slash Commands not registering in servers

Screenshots

in-dms
slash-in-server

Server & Bot:

  • OS: Windows 10
  • Python version: v3.8.2
  • discord.py version: v1.7.3

Traceback

No Error

Pls help me
I have never used disnake, but i have used discord.py and dislash.py

Update with a Discord command

Using a command such as rl!update could trigger a git pull and restart the bot.
#10 needs to be implemented before this is feasible.

A problem

I have this error: invalid Syntax

Windows compatibility

Describe the bug
On Windows systems the bot does not work because:

  • CSV files must be opened with encoding=“utf-8“ to handle emojis
  • lineterminator must be set to ”” to avoid blank rows between each row in CSVs

However, different methods to ensure cross-platform compatibility are necessary. Especially GNU/Linux compatibility must be maintained, since most bots are run on small VPS (ie GNU/Linux based).

To Reproduce
Run the bot on a non-unix system.

Expected behavior
Same behaviour as on other platforms.

Remove any need to rely on IDs (and developer mode)

With commit 4830607 it is no longer necessary to use channel IDs, making the bot much more straightforward to use.

However, the edit command still relies on the message ID to fetch the embed that needs to be modified.

A possible solution is not to ask for the message ID, and have the bot reply with a numbered list of messages (maybe including just the title?) and the user simply needs to input the number to select the message to be edited. If there is only one reaction role embed in that channel, then this process could be probably skipped and select the only existing embed automatically.

Add docker deployment

Move config.ini to files/config/config.ini and create a dockerfile to deploy the bot.
Have the whole files directory persistent.

config.ini.sample needs to be moved too. The sample is moved with git pull, while the original file needs to be moved with a script (probably make use of cogs.utils.schema).

Task launched multiple times

Describe the bug

randomly getting this error but bot still working, i guess just one time bot stopped working when i get this error.

Screenshots

image

Server:

  • OS: Windows Server 2012
  • Python version: 3.9
  • discord.py version: 1.6 - 1.7

Make botcolor configurable

Is your feature request related to a problem? Please describe.
Botcolor is currently hardcoded in bot.py.

Describe the solution you'd like
It should be configurable in config.ini and updatable via a command.

Discussion
Converting the string into an integer and then a hex. This can be done by using, for example, hex(int("0xFFFFFF", 16)). However, a method to translate inputs such as "white" into their hex counterpart would improve UX considerably. This could be achieved with a dict, but I'm afraid it would make the code even worse than it is now (#13).

If you have any ideas to share please do.

Rework ReactionRole ID generation

As mentioned in #27, the core.database method to assign a reaction role id needs a rework, along with possibly a change in the DB tables. A migration script would most likely be necessary in that case.

Allow per-guild binding of system channels

Allow to set a system channel for each guild (server) the bot is being used in for messages related to commands or errors arising from reaction-role messages hosted in a channel from a certain guild.

The config.ini system channel should be used as a fallback when not set.

My current idea entails:

  • adding a guild_id column to the messages database table
    • a migration function to fill this column in the already existing rows
  • creating a systemchannels database table with columns: guild_id and channel
  • adding the appropriate commands to bind guild system channels
  • adding the appropriate checks to clean the database if a channel/guild is deleted
  • modifying the system_notification function (currently in bot.py) to check if a system channel is set for a guild that was the source of a notification

Refactor bot.py (add cogs, cleaner code)

Even though the bot works flawlessly in its current state (except for the currently open enhancement-related issues), the code could use a lot of improvements.

Refactoring with better functions, classes, cogs, and general usage of discord.py is ideal.

We could also consider using SQLite instead of CSV files. Though this will add an extra dependency to the bot (and a complete remake of the bot's file manager (rlightfm)).

EDIT: Additionally, another hurdle of adopting SQLite is creating a script to transfer the data of CSV files in currently existing installations to the database so to minimise downtime to a simple bot restart.

EDIT: Striked parts done in #20

Getting several warnings and an error when trying to create a new reaction message.

Describe the problem you are running into

Mentioning the channel where I want to create the new reaction message causes several warning and an the attribute error to appear.

Server:

  • OS: Ubuntu 18.04.5
  • Python version: 3.8.7
  • discord.py version: 1.6.0

Traceback

Reaction Light ready!
bot.py:415: RuntimeWarning: coroutine 'getchannel' was never awaited
  bot_permissions = await getchannel(target_channel).permissions_for(
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Ignoring exception in on_message
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "bot.py", line 415, in on_message
    bot_permissions = await getchannel(target_channel).permissions_for(
AttributeError: 'coroutine' object has no attribute 'permissions_for'

Improve rl!systemchannel explanation

The current rl!systemchannel response when no arguments are passed should be improved:

  • Add two lines mentioning the current main and server channel (the server channel of the guild the message was sent in)

  • Better explain the difference between the main and server channels

Refactor error reporting

Refactor error reporting in all files so that every db interaction is not followed by isinstance to check for exceptions

Update Broke the bot

Describe the bug

Bot no longer starts after the latest update.

Steps to reproduce the behavior:

update to the current build and attempt to run the bot.

eg.
after updating open terminal and type:

cd /path/to/bot/
python3 bot.py

A clear and concise description of what you expected to happen.

I expected to bot to actually launch.

If applicable, add screenshots to help explain your problem.

https://imgur.com/ZjHoiIp.png

Server:

  • OS: Debian
  • Python version: 3.7.3
  • discord.py version: don't know how to check this but i tend to keep it up to date.

Traceback

Traceback (most recent call last):
  File "bot.py", line 37, in <module>
    from core import database, migration, activity
  File "/home/admin/reaction-light/core/__init__.py", line 2, in <module>
    from .activities import *
ModuleNotFoundError: No module named 'core.activities'

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.