botpy
This commit is contained in:
63
main.py
Normal file
63
main.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import discord
|
||||
import asyncio
|
||||
import os
|
||||
import config
|
||||
from discord.ext import commands, tasks
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
import time
|
||||
|
||||
intents = discord.Intents.all()
|
||||
token = config.TOKEN
|
||||
|
||||
class Bot(commands.Bot):
|
||||
def __init__(self):
|
||||
self.conwarn = sqlite3.connect("warn.db")
|
||||
self.conmsg = sqlite3.connect("message.db")
|
||||
self.confmsg = sqlite3.connect("channel.db")
|
||||
super().__init__(
|
||||
command_prefix=(config.PREFIX),
|
||||
intents=intents,
|
||||
)
|
||||
|
||||
async def status_up(self, name):
|
||||
await self.change_presence(activity=discord.CustomActivity(name=f"Uptime - {name}"))
|
||||
|
||||
async def ch(self, server_id):
|
||||
name = "logs"
|
||||
tog = 1
|
||||
rows = self.confmsg.execute("SELECT channel_id FROM channel WHERE name=? AND server_id=? AND tog=?",(name, server_id, tog))
|
||||
res = rows.fetchone()
|
||||
channel=" ".join(res)
|
||||
return channel
|
||||
|
||||
async def select(self, name, server_id, channel_id) -> None:
|
||||
rows = self.confmsg.execute("SELECT tog FROM channel WHERE name=? AND server_id=? AND channel_id=?", (name, server_id, channel_id,))
|
||||
res = rows.fetchone()
|
||||
if res == None:
|
||||
return "disabled"
|
||||
elif not None:
|
||||
return "enabled"
|
||||
|
||||
async def load(self):
|
||||
for filename in os.listdir('./c'):
|
||||
if filename.endswith('.py'):
|
||||
await self.load_extension(f'c.{filename[:-3]}')
|
||||
|
||||
async def on_ready(self):
|
||||
print('Bot is now working')
|
||||
|
||||
async def main(self):
|
||||
self.conwarn.execute("CREATE TABLE IF NOT EXISTS 'warn'('id' NOT NULL, 'user_id' varchar(20) NOT NULL, 'server_id' varchar(20) NOT NULL, 'reason' varchar(255) NOT NULL)")
|
||||
self.conwarn.execute("CREATE TABLE IF NOT EXISTS 'warnid'('number' int(1) NOT NULL, 'server_id' varchar(20) NOT NULL)")
|
||||
self.conwarn.execute("CREATE TABLE IF NOT EXISTS 'warnact'('number' int(1) NOT NULL, 'server_id' varchar(20) NOT NULL)")
|
||||
self.conwarn.commit()
|
||||
self.conmsg.execute("CREATE TABLE IF NOT EXISTS 'message'('id' NOT NULL, 'server_id' varchar(20) NOT NULL, 'messages' varchar(255) NOT NULL)")
|
||||
self.conmsg.commit()
|
||||
self.confmsg.execute("CREATE TABLE IF NOT EXISTS 'channel'('tog' int(1) NOT NULL, 'name' str(255) NOT NULL, 'server_id' varchar(20) NOT NULL,'channel_id' varchar(18) NOT NULL)")
|
||||
self.confmsg.commit()
|
||||
await self.load()
|
||||
await self.start(token=token)
|
||||
|
||||
bot = Bot()
|
||||
asyncio.run(bot.main())
|
||||
Reference in New Issue
Block a user