Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
*.pyc
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ The official source code for the Lab Manager Discord Bot.


## Config
You should set your `Discord Token`, `MongoDB` connection URL and any applicable channel ID's in the `main.py` file. There are also other optional configurations in almost all other files. In the case that you want to use the statuspage.io integration, make sure to set your `API token`, `page id` & `metric id` in the `cogs/api.py` file.
Create a file called `.env` in the main directory
Then add the following to the file
```
TOKEN: (your token)
MONGO_CONNECTION_URL: (the url)
## Optional
STATUS_API_TOKEN: (the statuspage.io API token)
PAGE_ID: (the page ID)
SMETRIC_ID: (the status metric ID)
BMETRIC_ID: (the bot metric ID)
```
You should also change any applicable channel ID's in the `main.py` file. There are also other optional configurations in almost all other files.
The last four lines are optional for a statuspage.io integration

## Setup
```shell
Expand Down
15 changes: 9 additions & 6 deletions cogs/api.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from discord.ext import commands, tasks
import http.client, urllib.request, urllib.parse, urllib.error, time, requests

api_key = ''
page_id = ''
smetric_id = ''
bmetric_id = ''
import os
api_key = os.getenv('STATUS_API_TOKEN')
page_id = os.getenv('PAGE_ID')
smetric_id = os.getenv('SMETRIC_ID')
bmetric_id = os.getenv('BMETRIC_ID')
api_base = 'api.statuspage.io'

class API(commands.Cog):
def __init__(self, bot):
"""Initilize. This function posts latency to the statuspage.io API."""
self.bot = bot
self.postapi.start()
if api_key and page_id and smetric_id and bmetric_id:
self.postapi.start()
else:
print("statuspage.io not configured! Not using the API")

@tasks.loop(minutes=1)
async def postapi(self):
Expand Down
5 changes: 4 additions & 1 deletion cogs/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def __init__(self, bot):
self.bot = bot

@commands.command(name="faq")
@commands.has_role(608714147378626570)
async def faq(self,ctx):
role=ctx.guild.get_role(608714147378626570)
if role not in ctx.author.roles:
Expand All @@ -32,6 +33,7 @@ async def faq(self,ctx):


@commands.command(name="bots")
@commands.has_role(608714147378626570)
async def bots(self,ctx):
role=ctx.guild.get_role(608714147378626570)
if role not in ctx.author.roles:
Expand All @@ -56,12 +58,13 @@ async def bots(self,ctx):


@commands.command(name="rules")
@commands.has_role(608714147378626570)
async def rules(self,ctx):
role=ctx.guild.get_role(608714147378626570)
if role not in ctx.author.roles:
return
desc="""
Before you do anything, we strongly suggest you familirize yourself with the rules and information listed below.
Before you do anything, we strongly suggest you familiarize yourself with the rules and information listed below.

**Website:** [discordlabs.org](https://discordlabs.org)
Bot List: [bots.discordlabs.org](https://bots.discordlabs.org)
Expand Down
3 changes: 3 additions & 0 deletions cogs/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async def botStatusUpdate(self):
offline=0
kicked=0
olist=""
#The start of pain (WHO CODES LIKE THIS)
for bot in mydoc:
try:
b = None
Expand Down Expand Up @@ -236,6 +237,8 @@ async def botStatusUpdate(self):
embed=discord.Embed(title="Data Update Ended",description=F"Total Bots: {len(mydoc)}\n\nOnline Bots: {online}\nAway Bots: {away}\nDND Bots: {dnd}\nKicked Bots: {kicked}\n\n**Offline Bots:** {offline}\nOffline Bots: {olist}",color=self.bot.embed)
await m.edit(embed=embed)
await asyncio.sleep(30) # task runs every .5 mins
# The fact that someone wrote this is sad.

#print("Stats Update Done")
#print(F"Total Bots: {len(mydoc)}\n\nOnline Bots: {online}\nAway Bots: {away}\nDND Bots: {dnd}\nKicked Bots: {kicked}\n\n**Offline Bots:** {offline}\nOffline Bots: {olist}")
except:
Expand Down
65 changes: 33 additions & 32 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@
from pymongo import MongoClient as mcl
import os
import sys

TOKEN = "TOKEN"

cogs = [
'cogs.api',
'cogs.info',
'cogs.ticket',
'cogs.update'
]
from dotenv import load_dotenv
load_dotenv()

class Bot(commands.AutoShardedBot):
def __init__(self):
super().__init__(command_prefix="?", case_insensitve=True)
super().__init__(intents=discord.Intents.all(),command_prefix=commands.when_mentioned_or('!'),help_command=None,activity=discord.Activity(name=' Over Discord Labs.', type=discord.ActivityType.watching),case_insensitive=True)

self.check = ":white_check_mark:"
self.x = ":x:"
self.devs = [
365958975201738764 # Anish
]



async def on_command_error(self,ctx, error):
if ctx.command.has_error_handler():
return
if isinstance(error,commands.MissingPermissions):
ctx.reply(error.message)
elif isinstance(error,commands.CheckAnyFailure):
ctx.reply(error.message)
elif isinstance(error,commands.MissingRole):
ctx.reply(error.message)
else:
ctx.reply("An error occured")
async def on_ready(self):
print(f"Bot is online!")

activity = discord.Activity(name=' Over Discord Labs.', type=discord.ActivityType.watching)
await bot.change_presence(activity=activity)
print('Intilized successfully.')
print('Bot Started')
#MongoDB Stuff
self.client = mcl('MONGODB CONNECTION URL')
self.client = mcl(os.getenv('MONGO_CONNECTION_URL'))
self.db=self.client['main']
self.b = self.db['bots']
self.a = self.db['ads']
Expand Down Expand Up @@ -67,31 +68,31 @@ async def on_ready(self):



for cog in cogs:
try:
bot.load_extension(cog)
print(f"Loaded {cog}")
except Exception as e:
print(e)

for file in os.listdir('cogs'):
if file.endswith('.py'):
try:
print(f"Loading {file}")
self.load_extension(f'cogs.{file[:-3]}')
except Exception as e:
print(e,file=sys.error)
bot = Bot()
bot.remove_command('help')


@bot.command()
@commands.check(lambda x: x.author.id in bot.devs)
async def restart(ctx):
if not ctx.author.id in bot.devs:
return
await ctx.send(F"Restarting. This may take a little! Please be patient with me.")
await bot.change_presence(status = discord.Status.dnd, activity = discord.Game("RESTARTING BOT!"))
os.execv(sys.executable, ['python3.6'] + sys.argv)
os.execv(sys.executable, [sys.executable]+sys.argv)
@bot.command()
@commands.check(lambda x: x.author.id in bot.devs)
async def reload(ctx, cog = None):
if not ctx.author.id in bot.devs:
return
if not cog:
return
for cg in bot.cogs.keys():
bot.reload_extension(cg)

try:
bot.reload_extension(cog)
await ctx.send(F"{bot.check} Successfully reloaded **{cog}**!")
except Exception as e:
await ctx.send(f"{bot.x} Oh no! There was an error reloading **{cog}**!\n**({e})**")
bot.run(TOKEN)
bot.run(os.getenv("TOKEN"))