Skip to content

Commit

Permalink
Merge pull request #41 from Code4GovTech/development
Browse files Browse the repository at this point in the history
bot update
  • Loading branch information
KDwevedi authored Sep 20, 2023
2 parents c3702ee + 3a02a86 commit c83c24d
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 3 deletions.
36 changes: 36 additions & 0 deletions cogs/badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,42 @@ def get_user_badges(self, discord_id):
class Badges(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot

@commands.command()
async def show_badges(self, ctx):
# only works in DM channels
if isinstance(ctx.channel, discord.DMChannel):
#Information abt the point system
infoEmbed = discord.Embed(title="Point System", description='If you want to understand more about the points & badge system, check out this [link](https://github.com/Code4GovTech/C4GT/wiki/Point-System-for-Contributors).')
await ctx.send(embed = infoEmbed)

name = ctx.author.name

user_badges = {
"points": [BadgeContents(name).enthusiastBadge, BadgeContents(name).rockstarBadge, BadgeContents(name).wizardBadge],
"achievements": [BadgeContents(name).apprenticeBadge, BadgeContents(name).converserBadge]
}
embed = discord.Embed(title="Badge Type", description="What badge type do you want to view?", color=discord.Color.blue())
embed.set_footer(text="Please react with 📈 for Points Based Badges or 🥳 Achievements Based Badges .")
message = await ctx.send(embed=embed)
await message.add_reaction('📈')
await message.add_reaction('🥳')
def check(reaction, user):
return user == ctx.message.author and str(reaction.emoji) in ['📈', '🥳']
try:
reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await ctx.send("You took too long to respond.")
else:
if str(reaction.emoji) == '📈':
for badge in user_badges["points"]:
await ctx.send(embed=badge)
elif str(reaction.emoji) == '🥳':
for badge in user_badges["achievements"]:
await ctx.send(embed=badge)




@commands.command()
async def my_badges(self, ctx):
Expand Down
98 changes: 96 additions & 2 deletions cogs/metrics_tracker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# #Track metrics on github and discord and update the database accordingly
# #Implement using: https://discordpy.readthedocs.io/en/stable/ext/tasks/index.html?highlight=tasks#
from discord.ext import commands, tasks
from discord import Embed
import aiohttp, json
from utils.db import SupabaseInterface
# from discord import Member
# from discord.channel import TextChannel
# from datetime import time, datetime
Expand All @@ -12,12 +15,103 @@
# import os, dateutil.parser




# async def getCetificate(name, badge):
# url = 'http://139.59.20.91:5000/rcw/credential'
# headers = {
# 'Content-Type': 'application/json'
# }
# data = {
# "type": ["Test Credential"],
# "subject": {
# "id": "did:C4GT:test",
# "username": f"{name}",
# "badge": f"{badge}"
# },
# "schema": "cllbzgfor000ytj151nu7km4t",
# "tags": ["Tag 1"],
# "templateId": "cllbzglwa0010tj15104dtgc8"
# }

# async with aiohttp.ClientSession() as session:
# async with session.post(url, headers=headers, json=data) as response:
# if response.status == 201:
# resp_data = await response.json()
# return json.loads(resp_data)
# else:
# print(f"Failed to fetch credential. Status code: {response.status}")
class MetricsTracker(commands.Cog):
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot

# @commands.command()
# async def my_certificates(self, ctx):

# noCertsEmbed = Embed(title='', description=f'''Hey {ctx.author.name}

# You have currently not earned any C4GT certificates yet!
# But don’t worry, all you need to do is collect 50 DPG points and get a Rising Star :stars: badge by solving issue tickets to become eligible for your first certificate. **Get coding now!!**:computer:

# **Discover issue tickets [here](https://www.codeforgovtech.in/community-program-projects).**
# ''')
# oneCertEmbed = Embed(
# title="Congratulations!",
# description=f"Hey {ctx.author.mention}\n\n"
# "You have earned a C4GT certificate for being an **active DPG contributor and earning 50 DPG points!** :partying_face:\n\n"
# "Click [here](http://139.59.20.91:9000/c4gt/Kanav%20Dwevedi_Enthusiast%20Badge.pdf) to access your certificate :page_with_curl:",
# color=0x00ff00 # You can choose any color
# )

# contributor_data = SupabaseInterface("contributors").read("discord_id", ctx.author.id)
# if len(contributor_data)==0:
# ctx.send("Use the !join command to register to obtain certificates")
# return

# [contributor] = contributor_data
# name = contributor["github_url"].split('/')[-1]

# user = SupabaseInterface("github_profile_data").read("discord_id", ctx.author.id)
# data = user[0]
# data["points"] = 70
# if data["points"] <50 :
# await ctx.send(embed=noCertsEmbed)
# elif data["points"]>=50 and data["points"]<100:

# # resp = await getCetificate(name, "Enthusiast Badge")
# oneCertEmbed = Embed(
# title="Congratulations!",
# description=f"Hey {ctx.author.mention}\n\n"
# "You have earned a C4GT certificate for being an **active DPG contributor and earning 50 DPG points!** :partying_face:\n\n"
# "Click [here](http://139.59.20.91:9000/c4gt/Kanav%20Dwevedi_Enthusiast%20Badge.pdf) to access your certificate :page_with_curl:",
# color=0x00ff00 # You can choose any color
# )
# await ctx.send(embed=oneCertEmbed)




@commands.command()
async def points(self, ctx):
await ctx.send(f'''Hey {ctx.author}
**You have a total of 140 points**🌟
▶️ **Points Basis PRs accepted - 60 points**🔥
Number of tickets solved - 3
Points on tickets with low complexity - 10 points
Points on tickets with medium complexity - 20 points
Points of tickets with high complexity - 30 points
▶️ **Points as per PRs reviewed - 80 points**🙌
Number of tickets reviewed - 4
Points on tickets with low complexity - 10 points
Points on tickets with medium complexity - 40 points
Points of tickets with high complexity - 30 points
Get coding and earn more points to get a spot on the leaderboard📈''')





Expand Down
11 changes: 10 additions & 1 deletion cogs/user_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,22 @@ async def github_profile(self, ctx):
*Congratulations on your hard work & achievement!!*🥳
Your profile page will now show your achievements from the C4GT community.🏆''')

noPointsGithubProfileEmbed = discord.Embed(title="", description=f'''Hey {ctx.author.name}
You have currently not earned any C4GT points yet!
But don’t worry, all you need to do is collect 50 DPG points and get a Rising Star :stars: badge by solving issue tickets to become eligible for your first certificate. **Get coding now!!**:computer:
**Discover issue tickets [here](https://www.codeforgovtech.in/community-program-projects).**
''')
user = SupabaseInterface("github_profile_data").read("discord_id", ctx.author.id)
if len(user) == 0:
await ctx.send("Oops! It seems you aren't currently registered")
elif len(user) == 1:
data = user[0]
data["points"]=0
if data["points"] == 0:
await ctx.send("Oops! It seems you currently don't have any points")
await ctx.send(embed=noPointsGithubProfileEmbed)
else:
await ctx.send(embed=githubProfileInfoEmbed)
await ctx.send(f'''Snippet for your Github Profile README:
Expand Down

0 comments on commit c83c24d

Please sign in to comment.