Skip to content

Commit

Permalink
Move to sql
Browse files Browse the repository at this point in the history
  • Loading branch information
Skelmis committed Jun 24, 2021
1 parent 32669c6 commit fb19f99
Show file tree
Hide file tree
Showing 13 changed files with 536 additions and 81 deletions.
7 changes: 7 additions & 0 deletions cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ async def build_average_support_response_time(self, ctx):
file_name=enum.value.lower(),
)

@commands.command(aliases=["ms"])
@commands.is_owner()
async def message_stats(self, ctx):
"""Shows stats for all messages"""
embed = await self.bot.manager.get_message_stats()
await ctx.send(embed=embed)


def setup(bot):
bot.add_cog(Stats(bot))
12 changes: 9 additions & 3 deletions conversations/abc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Protocol, List
from typing import Protocol, List, Union

from conversations import Conversation, Helper

Expand Down Expand Up @@ -101,7 +101,7 @@ async def remove_helper(self, identifier: int) -> None:
"""
raise NotImplementedError

async def get_all_conversations(self) -> List[dict]:
async def fetch_all_conversations(self) -> List[Conversation]:
"""
Returns a list of all possible conversations yea idk
Expand All @@ -113,7 +113,7 @@ async def get_all_conversations(self) -> List[dict]:
"""
raise NotImplementedError

async def get_all_helpers(self) -> List[dict]:
async def fetch_all_helpers(self) -> List[Helper]:
"""
Returns a list of all helpers to make dataclasses for
Expand All @@ -123,3 +123,9 @@ async def get_all_helpers(self) -> List[dict]:
A list of helpers
"""
raise NotImplementedError

async def create_indexes(self) -> None:
"""
Creates indexes in the database to support faster queries
"""
raise NotImplementedError
2 changes: 1 addition & 1 deletion conversations/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import attr


@attr.s(slots=True)
@attr.s(slots=True, frozen=True)
class Message:
author_id: int = attr.ib()
channel_id: int = attr.ib()
Expand Down
1 change: 1 addition & 0 deletions conversations/datastore/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .mongo import Mongo
from .sqlite import Sqlite
25 changes: 21 additions & 4 deletions conversations/datastore/mongo/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,25 @@ async def store_helper(self, helper: Helper) -> None:
async def remove_helper(self, identifier: int) -> None:
pass

async def get_all_conversations(self) -> List[dict]:
return await self.conversations.get_all()
async def fetch_all_conversations(self) -> List[Conversation]:
values = await self.conversations.get_all()
conversations = []
for convo in values:
messages = []
for message in convo["messages"]:
messages.append(Message(**message))

async def get_all_helpers(self) -> List[dict]:
return await self.helpers.get_all()
convo["messages"] = messages

conversations.append(Conversation(**convo))

return conversations

async def fetch_all_helpers(self) -> List[Helper]:
values = await self.helpers.get_all()
helpers = []
for helper in values:
helper.pop("_id")
helpers.append(Helper(**helper))

return helpers
33 changes: 0 additions & 33 deletions conversations/datastore/sqlite.py

This file was deleted.

1 change: 1 addition & 0 deletions conversations/datastore/sqlite/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .sqlite import Sqlite
Binary file added conversations/datastore/sqlite/datastore.db
Binary file not shown.
Loading

0 comments on commit fb19f99

Please sign in to comment.