Git Product home page Git Product logo

tweetcord's Introduction

✨States

Yuuzi's GitHub stats

Top Langs

🔧Technologies & Tools

tweetcord's People

Contributors

me846 avatar yuuzi261 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

me846 fusefairy

tweetcord's Issues

Display a list of registered users

I'm using Tweetcord! Thanks for the convenient repository!

I tried to make the bot display the list of registered users only on the server where the command was executed.

Additional code

cogs/ListUsers.py

import discord
from discord import app_commands
from discord.ext import commands
import sqlite3
import os

class ListUsersCog(commands.Cog):

    def __init__(self, bot):
        self.bot = bot

    @app_commands.command(
        name='list_users',
        description='Lists registered Twitter usernames and their associated channels'
    )
    @commands.has_permissions(administrator=True)
    async def list_users(self, itn: discord.Interaction):
        
        server_id = itn.guild_id

        db_path = os.path.join(os.getenv('DATA_PATH', ''), 'tracked_accounts.db')
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()

        cursor.execute("""
            SELECT user.username, channel.id
            FROM user
            JOIN notification
            ON user.id = notification.user_id
            JOIN channel
            ON notification.channel_id = channel.id
            WHERE notification.server_id = ?
        """, (str(server_id),))
        user_channel_data = cursor.fetchall()

        conn.close()

        formatted_data = [f"{i+1}. ```{username}``` <#{channel_id}>" for i, (username, channel_id) in enumerate(user_channel_data)]

        embed = discord.Embed(
            title=f'Notice Add List ',
            description='\n'.join(formatted_data),
            color=0x778899
        )

        await itn.response.send_message(embed=embed)




async def setup(bot):
    await bot.add_cog(ListUsersCog(bot))

Modified code

notification.py add to changed 63line

add

  • @add_group.command(name='notifier')
server_id = str(itn.guild_id)
mention_str = mention.mention if mention else ''

changed

cursor.execute('INSERT INTO notification (user_id, channel_id, role_id) VALUES (?, ?, ?)', (str(new_user.id), str(channel.id), roleID))

to

cursor.execute('INSERT INTO notification (user_id, channel_id, role_id, mention, server_id) VALUES (?, ?, ?, ?, ?)', (str(new_user.id), str(channel.id), roleID, mention_str, server_id))

init_db,py
・notification table add server_id. mention

I posted it because it was a personally convenient feature! It's okay to use it!

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.