Skip to content

Commit

Permalink
black added
Browse files Browse the repository at this point in the history
  • Loading branch information
soham4abc committed Jun 17, 2021
1 parent 41360a1 commit 1b151af
Show file tree
Hide file tree
Showing 8 changed files with 653 additions and 432 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Black Code Formatter
uses: lgeiger/black-action@v1.0.1
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
518 changes: 317 additions & 201 deletions main.py

Large diffs are not rendered by default.

240 changes: 135 additions & 105 deletions quiz.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ python-decouple==3.4
requests==2.25.1
wikipedia==1.4.0
pymongo==3.11.4
dnspython==1.16.0
dnspython==1.16.0
black==21.6b0
171 changes: 106 additions & 65 deletions scripts/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
from decouple import config
import discord


class Database:
"""
Class for all the database functions
"""

def __init__(self):
try:
self.cluster = pm.MongoClient("mongodb+srv://danger-ahead:"
+config('MONGO')+"@cluster0.z0zou.mongodb.net/test")
self.cluster = pm.MongoClient(
"mongodb+srv://danger-ahead:"
+ config("MONGO")
+ "@cluster0.z0zou.mongodb.net/test"
)

self.db = self.cluster["roBOT"]
self.collection = self.db["user_score"]
self.collection2 = self.db["servers"]
#prints the message after successfully initializing the connection with mongoDB
print('Running: Database module [database.py]')
# prints the message after successfully initializing the connection with mongoDB
print("Running: Database module [database.py]")
except:
print('Failed to run Database module [database.py]\n')
print("Failed to run Database module [database.py]\n")

async def score_up(self, message, client): #increases the score of the user
async def score_up(self, message, client): # increases the score of the user
score = -1
query = {"_id": message.author.id}
user = self.collection.find(query)
Expand All @@ -28,79 +33,104 @@ async def score_up(self, message, client): #increases the score of the user

if score > 0:
score = score + 1
self.collection.update_one({"_id":message.author.id}, {"$set":{"score":score}})
self.collection.update_one(
{"_id": message.author.id}, {"$set": {"score": score}}
)

if score%15 == 0: #user levels up every 15 points
user = self.collection2.find({"_id":message.guild.id})
if score % 15 == 0: # user levels up every 15 points
user = self.collection2.find({"_id": message.guild.id})
for result in user:
channell = result["channel"]

chanell = client.get_channel(channell)
embed = discord.Embed(title="Level UP!",
description=message.author.mention+', you\'re my level '
+str(int(score/15))+ ' friend now!',
color=discord.Color.blue())
embed = discord.Embed(
title="Level UP!",
description=message.author.mention
+ ", you're my level "
+ str(int(score / 15))
+ " friend now!",
color=discord.Color.blue(),
)
await chanell.send(embed=embed)
else:
#if the user has interacted for the 1st time, sets the user's score to 1
self.collection.insert_one({"_id":message.author.id, "score":1})
# if the user has interacted for the 1st time, sets the user's score to 1
self.collection.insert_one({"_id": message.author.id, "score": 1})

async def rank_query(self, message): #searches and messages rank of the user
async def rank_query(self, message): # searches and messages rank of the user
query = {"_id": message.author.id}
user = self.collection.find(query)
for result in user:
score = result["score"]
embed = discord.Embed(title="Friendship Stats!!",
description=message.author.mention+', you\'re my level '
+str(int(score/15))+ ' friend!',
color=discord.Color.blue())
embed = discord.Embed(
title="Friendship Stats!!",
description=message.author.mention
+ ", you're my level "
+ str(int(score / 15))
+ " friend!",
color=discord.Color.blue(),
)
await message.channel.send(embed=embed)
#sets the channel for roBOT's admin commands, also initializes the confess key with 0

# sets the channel for roBOT's admin commands, also initializes the confess key with 0
async def server_config(self, server, message):
channell = ''
channell = ""
query = {"_id": server}
user = self.collection2.find(query)
for result in user:
channell = result["channel"]

if channell != '':
await message.channel.send('I\'m already configured on <#'+str(channell)+'>')
if channell != "":
await message.channel.send(
"I'm already configured on <#" + str(channell) + ">"
)
else:
self.collection2.insert_one({"_id":server, "channel":message.channel.id,
"confess":0, "mod":0})
await message.channel.send('I just got configured!')

async def server_deconfig(self, server, message): #deletes the discord server's details
channell = ''
self.collection2.insert_one(
{"_id": server, "channel": message.channel.id, "confess": 0, "mod": 0}
)
await message.channel.send("I just got configured!")

async def server_deconfig(
self, server, message
): # deletes the discord server's details
channell = ""
query = {"_id": server}
user = self.collection2.find(query)
for result in user:
channell = result["channel"]

if channell == message.channel.id:
self.collection2.delete_one({"_id": server})
await message.channel.send('I\'ve been deconfigured!')
elif channell == '':
await message.channel.send('Configure me first!')
await message.channel.send("I've been deconfigured!")
elif channell == "":
await message.channel.send("Configure me first!")
elif channell != message.channel.id:
await message.channel.send('I\'m configured on <#'
+str(channell)+'> \nI can\'t deconfigure here!')
await message.channel.send(
"I'm configured on <#" + str(channell) + "> \nI can't deconfigure here!"
)

async def confess_config(self, server, message): #configures the confession channel
async def confess_config(
self, server, message
): # configures the confession channel
confess = 0
query = {"_id": server}
user = self.collection2.find(query)
for result in user:
confess = result["confess"]

if confess != 0:
await message.channel.send('I\'m already configured on <#'+str(confess)+'>')
await message.channel.send(
"I'm already configured on <#" + str(confess) + ">"
)
else:
self.collection2.update_one({"_id" : server},
{"$set" : {"_id" : server, "confess":message.channel.id}})
await message.channel.send('I just got the confession channel configured!')

async def confess_deconfig(self, server, message): #sets the confession channel's id to 0
self.collection2.update_one(
{"_id": server},
{"$set": {"_id": server, "confess": message.channel.id}},
)
await message.channel.send("I just got the confession channel configured!")

async def confess_deconfig(
self, server, message
): # sets the confession channel's id to 0
confess = 0
query = {"_id": server}
user = self.collection2.find(query)
Expand All @@ -109,46 +139,56 @@ async def confess_deconfig(self, server, message): #sets the confession chan
channell = result["channel"]

if confess == message.channel.id:
self.collection2.update_one({"_id" : server},
{"$set" : {"_id" : server, "channel" : channell, "confess":0}})
await message.channel.send('My confession channel has been deconfigured!')
self.collection2.update_one(
{"_id": server},
{"$set": {"_id": server, "channel": channell, "confess": 0}},
)
await message.channel.send("My confession channel has been deconfigured!")
elif confess == 0:
await message.channel.send('Configure my confession channel first!')
await message.channel.send("Configure my confession channel first!")
elif confess != message.channel.id:
await message.channel.send('My confession channel is configured on <#'
+str(confess)+'> \nI can\'t deconfigure here!')
await message.channel.send(
"My confession channel is configured on <#"
+ str(confess)
+ "> \nI can't deconfigure here!"
)

#function for leaving the server on command from pre-configured channel
# function for leaving the server on command from pre-configured channel
async def leave_server(self, server, message):
channell = ''
channell = ""
query = {"_id": server}
user = self.collection2.find(query)
for result in user:
channell = result["channel"]

if channell == message.channel.id:
await message.channel.send('Don\'t want me? Fine!')
await message.channel.send("Don't want me? Fine!")
await message.guild.leave()
elif channell == '':
await message.channel.send('Configure me first!')
elif channell == "":
await message.channel.send("Configure me first!")
else:
await message.channel.send('I\'ll only leave if instructed from <#'+str(channell)+'>')
await message.channel.send(
"I'll only leave if instructed from <#" + str(channell) + ">"
)

#function for forwarding the confession
# function for forwarding the confession
async def confess(self, client, discord, confession, message):
channell = 0
user = self.collection2.find({"_id":message.guild.id})
user = self.collection2.find({"_id": message.guild.id})
for result in user:
channell = result["confess"]

if channell != 0:
embed = discord.Embed(title='Someone just confessed:',
description=confession, color=discord.Color.blue())
embed = discord.Embed(
title="Someone just confessed:",
description=confession,
color=discord.Color.blue(),
)
await client.get_channel(channell).send(embed=embed)
else:
await message.channel.send('My confession channel hasn\'t been configured!')
await message.channel.send("My confession channel hasn't been configured!")

# function that enables moderation service on a server
# function that enables moderation service on a server
async def moderation_service(self, server, message):
mod = 0
query = {"_id": server}
Expand All @@ -157,13 +197,14 @@ async def moderation_service(self, server, message):
mod = result["mod"]

if mod == 1:
await message.channel.send('Moderation service running')
await message.channel.send("Moderation service running")
else:
self.collection2.update_one({"_id" : server},
{"$set" : {"_id" : server, "mod":1}})
await message.channel.send('Moderation service started!')
self.collection2.update_one(
{"_id": server}, {"$set": {"_id": server, "mod": 1}}
)
await message.channel.send("Moderation service started!")

# function to check moderation status of server
# function to check moderation status of server
async def check_server_moderation(self, server):
mod = -1
query = {"_id": server}
Expand Down
63 changes: 39 additions & 24 deletions scripts/games.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,64 @@
import random
import discord


async def roll_a_dice(message):
number = random.randint(1, 6)

if number == 1:
embed = discord.Embed(title="Dice!!",
description="|--------|\n|---0---|\n|--------|",
color=discord.Color.blue())
embed = discord.Embed(
title="Dice!!",
description="|--------|\n|---0---|\n|--------|",
color=discord.Color.blue(),
)
await message.channel.send(embed=embed)
elif number == 2:
embed = discord.Embed(title="Dice!!",
description="|-0---|\n|------|\n|---0-|",
color=discord.Color.blue())
embed = discord.Embed(
title="Dice!!",
description="|-0---|\n|------|\n|---0-|",
color=discord.Color.blue(),
)
await message.channel.send(embed=embed)
elif number == 3:
embed = discord.Embed(title="Dice!!",
description="|---------|\n|0--0--0|\n|---------|",
color=discord.Color.blue())
embed = discord.Embed(
title="Dice!!",
description="|---------|\n|0--0--0|\n|---------|",
color=discord.Color.blue(),
)
await message.channel.send(embed=embed)
elif number == 4:
embed = discord.Embed(title="Dice!!",
description="|0---0|\n|-------|\n|0---0|",
color=discord.Color.blue())
embed = discord.Embed(
title="Dice!!",
description="|0---0|\n|-------|\n|0---0|",
color=discord.Color.blue(),
)
await message.channel.send(embed=embed)
elif number == 5:
embed = discord.Embed(title="Dice!!",
description="|0----0|\n|---0---|\n|0----0|",
color=discord.Color.blue())
embed = discord.Embed(
title="Dice!!",
description="|0----0|\n|---0---|\n|0----0|",
color=discord.Color.blue(),
)
await message.channel.send(embed=embed)
else:
embed = discord.Embed(title="Dice!!",
description="|0 0 0|\n|------|\n|0 0 0|",
color=discord.Color.blue())
embed = discord.Embed(
title="Dice!!",
description="|0 0 0|\n|------|\n|0 0 0|",
color=discord.Color.blue(),
)
await message.channel.send(embed=embed)


async def toss_coin(message):
number = random.randint(1, 2)

if number == 1:
embed = discord.Embed(title="Toss!!",
description="Head",
color=discord.Color.blue())
embed = discord.Embed(
title="Toss!!", description="Head", color=discord.Color.blue()
)
await message.channel.send(embed=embed)
else:
embed = discord.Embed(title="Toss!!",
description="Tails",
color=discord.Color.blue())
embed = discord.Embed(
title="Toss!!", description="Tails", color=discord.Color.blue()
)
await message.channel.send(embed=embed)
Loading

0 comments on commit 1b151af

Please sign in to comment.