Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from flask import Flask
import random
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from threading import Thread

# Creating the api
app = Flask(__name__)
limiter = Limiter(app, key_func=get_remote_address)


f = open('data.base','r')
quotes = f.read().split(',')
f.close()
"""Opening and reading quotes"""

f = open('sug.base','w')#database to hold suggessions

@app.route('/')#main endpoint to get a quote (no rate limits)
def samuel():
return {"quote":quotes[random.randint(0,len(quotes))]}


@app.route('/submit/<data>')
@limiter.limit("20/minute")
def submit(data):
f.write(f"{data},")
return "200"

def run():
app.run(deubug=True)


def keep_alive():
server = Thread(target=run)
server.start()
25 changes: 20 additions & 5 deletions cogs/Fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from discord.ext import commands
from discord.ext.commands import command

import config

roasts = json.loads(
open('./main_resources/Assets/roast.json', encoding='utf-8').read())['roasts']
kills = json.loads(open('./main_resources/Assets/kill.json',
Expand All @@ -32,7 +34,8 @@ def __init__(self, bot):
async def gsearch(self, ctx: discord.ext.commands.Context, *, query):
"""Sends top google search result with page description"""
searchInput = "https://google.com/search?q=" + \
parse.quote(query) + "&num=2" # Query url for top 2 results
parse.quote(query) + \
"&num=2" # Query url for top 2 results
res = requests.get(searchInput) # Gets the google search results page
# Parses the google search results page
soup = BeautifulSoup(res.text, "html.parser")
Expand Down Expand Up @@ -155,7 +158,8 @@ async def beer(self, ctx, user: discord.Member = None, *, reason: commands.clean
f"I would love to give beer to the bot **{ctx.author.name}**, but I don't think it will respond to you :/")

beer_offer = f"**{user.name}**, you got a 🍺 offer from **{ctx.author.name}**"
beer_offer = beer_offer + f"\n\n**Reason:** {reason}" if reason else beer_offer
beer_offer = beer_offer + \
f"\n\n**Reason:** {reason}" if reason else beer_offer
msg = await ctx.send(beer_offer)

def reaction_check(m):
Expand All @@ -173,7 +177,8 @@ def reaction_check(m):
except discord.Forbidden:
# Yeah so, bot doesn't have reaction permission, drop the "offer" word
beer_offer = f"**{user.name}**, you got a 🍺 from **{ctx.author.name}**"
beer_offer = beer_offer + f"\n\n**Reason:** {reason}" if reason else beer_offer
beer_offer = beer_offer + \
f"\n\n**Reason:** {reason}" if reason else beer_offer
await msg.edit(content=beer_offer)

@commands.command(name="howhot", aliases=["hotcalc", "hot"])
Expand Down Expand Up @@ -206,7 +211,6 @@ async def f(self, ctx):
pass
finally:
await ctx.send(f"**{ctx.author.mention}** has paid their respects")


@commands.command(name="coinflip", aliases=["flip", "coin"])
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
Expand Down Expand Up @@ -321,9 +325,20 @@ async def insult(self, ctx):

@command(name="say", hidden=True)
@commands.cooldown(rate=1, per=5.0, type=commands.BucketType.user)
async def say(self, ctx:commands.Context, *, message:str):
async def say(self, ctx: commands.Context, *, message: str):
await ctx.send(message)

@command(name="quote", hidden=True)
@commands.cooldown(rate=1, per=5.0, type=commands.BucketType.user)
async def say(self, ctx: commands.Context):
r = requests.get("hosturl")#put host url here(website that repl gives)
await ctx.send(r.text)
@command(name="addquote", hidden=True)
@commands.cooldown(rate=1, per=5.0, type=commands.BucketType.user)
async def say(self, ctx: commands.Context,quote:str):
r = requests.get(f"hosturl/submit/{quote}")#put host url here(website that repl gives)
await ctx.send(r.text)


def setup(bot):
bot.add_cog(Fun(bot))
Expand Down
16 changes: 16 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
from dotenv import load_dotenv
load_dotenv()


def keys():
keys.TOKEN = os.getenv('TOKEN')
keys.CLIENT_ID = os.getenv('CLIENT_ID')
keys.SECRET = os.getenv('SECRET')
keys.TOTAL_GUILDS_API_URI = os.getenv('TOTAL_GUILDS_API_URI')
keys.MONGODB_URL = os.getenv('MONGODB_URL')
keys.PREFIX = os.getenv('PREFIX')


def cogs():
cogs.UNLOADED = ["Utilities.py", "Help.py"]
31 changes: 18 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import os
import discord
from discord.ext import commands, tasks
from dotenv import load_dotenv
import config

from main_resources.events import Events
from main_resources.functions import *
from main_resources.loops import Loops

# --------------------------------Variables--------------------------------#

load_dotenv() # Load env to initialize all dataset
keys = config.keys()

# The url for updating server count.
total_guilds_api_url = os.getenv('TOTAL_GUILDS_API_URI')
database = create_database_connection(os.getenv('MONGODB_URL'))
total_guilds_api_url = keys.TOTAL_GUILDS_API_URI
database = create_database_connection(keys.MONGODB_URL)
guilds_data = database['guilds_data']
guild_prefix_storage = create_guild_store(guilds_data)
disabled_commands_store = create_disabled_commands_store(guilds_data)
# ---------------------------------Prefix----------------------------------#

DEFAULT_PREFIX = os.getenv('PREFIX')
DEFAULT_PREFIX = keys.PREFIX


# Get prefix per server
Expand All @@ -34,8 +32,10 @@ def get_prefix(bot, message: discord.Message):

# -----------------------------------Bot-----------------------------------#

bot = commands.Bot(command_prefix=get_prefix, help_command=None, case_insensitive=True)
custom_statuses = [f'{DEFAULT_PREFIX}help', 'WhiteHatJr SEO', ' with wolf gupta', 'ChintuAI']
bot = commands.Bot(command_prefix=get_prefix,
help_command=None, case_insensitive=True)
custom_statuses = [f'{DEFAULT_PREFIX}help',
'WhiteHatJr SEO', ' with wolf gupta', 'ChintuAI']
check_class = before_invoke(disabled_commands_store)
bot.before_invoke(check_class.check_before_invoke)

Expand All @@ -47,7 +47,8 @@ async def on_ready():
clear_game.start()
print("Updating databases...")
update_guilds_data(bot, guilds_data, DEFAULT_PREFIX)
print(f'Logged in as {bot.user.name}#{bot.user.discriminator} ID = {bot.user.id}')
print(
f'Logged in as {bot.user.name}#{bot.user.discriminator} ID = {bot.user.id}')

# --------------------------------Task loops--------------------------------#

Expand All @@ -57,7 +58,8 @@ async def on_ready():

# --------------------------------Events--------------------------------#
events = Events(bot, database, total_guilds_api_url, guild_prefix_storage, disabled_commands_store, DEFAULT_PREFIX,
["help", "kick", "ban", "warn", "warninfo", "warns", "mute", "unmute", "clear"],
["help", "kick", "ban", "warn", "warninfo",
"warns", "mute", "unmute", "clear"],
ChintuAI=True)

bot.event(events.on_command_error)
Expand All @@ -83,8 +85,11 @@ def load_extensions(fun_bot, unloaded_cogs: list):

if __name__ == '__main__':
print("Loading extensions...")
load_extensions(bot, ["Utilities.py", "Help.py"])
cogsinf = config.cogs()
load_extensions(bot, cogsinf.UNLOADED)
bot.load_extension("cogs.Utilities")
bot.load_extension("cogs.Help")
print("Logging in...")
bot.run(os.getenv("TOKEN"))
import keepalive
keepalive.keep_alive()
bot.run(keys.TOKEN)