Skip to content

Commit

Permalink
feat: set up some necromancy commands
Browse files Browse the repository at this point in the history
* feat: set up some necromancy commands

* chore: format and lint code
  • Loading branch information
Vyvy-vi authored Sep 17, 2021
1 parent 02dacfa commit c4c34d3
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 10 deletions.
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ updates:
interval: daily
time: "10:00"
open-pull-requests-limit: 10

10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dev dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.dev.txt
- name: Check code-formatting with Black
run: |
python -m black . --check --diff
Expand All @@ -35,18 +35,18 @@ jobs:
- name: Test code with Pytest
run: |
echo "No tests found..."
cog_loader_test:
# loads cogs, to check if they have any issues
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,3 @@
* Standup command for logging goals ([97b5182](https://github.com/MetaFam/shepherd-bot/commit/97b5182bef0de5f88c078acb09bb543f6487601a))
* versioning ([6f9b865](https://github.com/MetaFam/shepherd-bot/commit/6f9b86570fb45f77f8a6eef38ba79e82dbef61a7))
* versioning ([8061d6e](https://github.com/MetaFam/shepherd-bot/commit/8061d6e5565c5a8440e83ee194e6662b2bf6053c))



2 changes: 1 addition & 1 deletion meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"privacy_policy": "",
"terms_and_conditions": "",
"latest_image": ""
}
}
148 changes: 148 additions & 0 deletions src/commands/necromancy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
from datetime import datetime
from typing import List, Optional, Union

from discord import Color, Embed, Member, User
from discord.ext import commands
from discord.ext.commands import Cog, Context
from motor.motor_asyncio import AsyncIOMotorClient as MotorClient

from src.consts import ACTIVE_ROLE_ID, MONGO_URI

# GUILD_ID
# import csv


def get_last_active(last_active):
date = datetime.fromtimestamp(last_active).strftime("%b-%d-%Y")
days = (datetime.now() - last_active).days
return f"Last active on {date} ({days} days ago...)"


def get_xp(self, member: Union[Member, User]):
return None


class Necromancy(Cog):
"""
Cog to parse user activity stats from the server.
And implements tooling for the Nacromancers
(This is a temporary implementation, and may be shifted to Jergal)
"""

def __init__(self, bot):
self.bot = bot
self.DB = MotorClient(MONGO_URI).players.logs

@commands.command()
async def necro(
self, ctx: Context, member: Union[Member, User], action: Optional[str]
):
"""Command for Necromancy Utilities"""
if not action:
await self.get_activity(ctx, member)
elif action == "active":
await self.get_last_active(ctx, member)
elif action == "xp":
await ctx.send(
embed=Embed(
description="That action is currently not available",
colour=Color.red(),
)
)
else:
await ctx.send(
embed=Embed(
description="That action does not exist(as of _yet_).",
color=Color.red(),
)
)

async def get_activity(self, ctx: Context, member: Union[Member, User]):
record = await self.DB_find_one({"_id": str(member.id)})
if record:
stats = f"**Last active**: {get_last_active(record['last_active_at'])}\n\
**Total Message Count**: {record['message_count']}\n\
**XP since last purge**: {get_xp(member)}\n"
await ctx.send(
embed=Embed(
description=f"Activity stats for {member.mention}\n{stats}",
colour=Color.green(),
)
)
else:
await ctx.send(
embed=Embed(
description="There appears to be no instance of this user in the DB.",
colour=Color.red(),
)
)

async def get_last_active(self, ctx: Context, member: Union[Member, User]):
record = await self.DB.find_one({"_id": str(member.id)})
if record:
await ctx.send(
f"{member.mention} was {get_last_active(record['last_active'])}"
)
else:
await ctx.send(
embed=Embed(
description="There appears to be no instance of this user in the DB.",
colour=Color.red(),
)
)

async def update_status(
self, member_id: str, created_at: datetime, status: List[str]
):
try:
record = await self.DB.find_one({"_id": member_id})
if record:
await self.DB.update_one(record, {"$set": {"status": status}})
else:
await self.DB.insert_one(
{
"_id": member_id,
"status": status,
"message_count": 0,
"xp": 0,
"last_active": created_at,
}
)
except Exception as e:
print(f"ERROR - {e}")

@commands.has_role("Necromancer")
@commands.command(aliases=["fallen"])
async def slay(
self, ctx: Context, member: Union[Member, User], *, reason: Optional[str]
):
try:
active_role = ctx.guild.get_role(ACTIVE_ROLE_ID)
await member.remove_roles(active_role, reason=reason, atomic=True)

await self.update_status(
member.id, ctx.guild.created_at, ["fallen", f"Reason- {reason}"]
)
except Exception as e:
print(e)
await ctx.send(f"Some error occured\n{e}")

@commands.has_role("Necromancer")
@commands.command(aliases=["chosen"])
async def promote(
self, ctx: Context, member: Union[Member, User], *, reason: Optional[str]
):
try:
active_role = ctx.guild.get_role(ACTIVE_ROLE_ID)
await member.add_roles(active_role, reason=reason, atomic=True)

await self.update_status(
member.id, ctx.guild.created_at, ["fallen", f"Reason- {reason}"]
)
except Exception as e:
print(e)
await ctx.send(f"Some error occured\n{e}")


def setup(bot):
bot.add_cog(Necromancy(bot))

0 comments on commit c4c34d3

Please sign in to comment.