Defxult / discordLevelingSystem

A library to implement a leveling system into a discord bot. Contains features such as XP, level, ranks, and role awards.
MIT License
91 stars 17 forks source link

Feature request of getting access to use database connection in an async loop #4

Closed DevInfinix closed 3 years ago

DevInfinix commented 3 years ago

Hi @Defxult! First of all, I would appreciate your contribution to this library. I did check out version 0.0.2 of the library. It is very nice. Thanks a lot for adding those features. But, I am facing some issues with it.


ISSUE

  • As I am using an SQLite connection for my database, I am not able to fetch the guild id for per-server configuration, i.e., level_up_channel_id (an optional parameter for the LevelUpAnnouncement class), if not in an async loop.
  • I need my code to work like this:
    cur = conn.cursor()
    predicate = cur.execute('SELECT * FROM config WHERE guild_id=?', (object.guild.id,))
    predicate = predicate.fetchone()
    if predicate[1]:
    level_up_channel = predicate[7] #predicate[7] here, is the level_up_channel_id stored in the db
    announcement = LevelUpAnnouncement(message = discord.Embed(title=f"<a:pepeclap:850247977943040001> CONGRATULATIONS!", description=f"{LevelUpAnnouncement.Member.mention} JUST LEVELED UP TO **LEVEL {LevelUpAnnouncement.LEVEL}**!", color = discord.Color.gold()) .set_thumbnail(url = LevelUpAnnouncement.Member.avatar_url) .set_footer(icon_url = LevelUpAnnouncement.Member.Guild.icon_url, text="MADE BY INFINIX#7276"), level_up_channel_id = level_up_channel)
  • If we get access to use the DiscordLevelingSystem.connect_to_database_file in an async func like on_message_event, we can easily fetch the guild's id by message.guild.id.
  • I am sorry if I am wrong because I am new to SQLite database.

Thanks.

Defxult commented 3 years ago

Each server does not have it's own configuration per say. Each server only has the details about each member pertaining to their level and xp. As for the LevelUpAnnouncement and it's level_up_channel_id , those are specific to each server that are set by you. As im typing this I discovered a bug where if a level_up_channel_id was set for one server but someone leveled up in another, an error would occur. I'll fix that today. The library was never made with the intention of multiserver use so that was never implemented (each server having their own configuration).

If you are looking to get information from the database file via SQL query from an on_message event, you can use method .sql_query_get to get the level and xp information for that server, but not the level up channel id. That could be changed, but that would require another massive breaking change, and a new .transfer method would have to be implemented. These are the limitations of not having a real database where things can be changed on the fly without issue.