Skip to content

Commit

Permalink
Update Command to have better time & type hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed Dec 1, 2021
1 parent 8c35849 commit 0bc1ca2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rustplus/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def __getTime(self) -> RustTime:

time_parser = TimeParser()

return RustTime(time.dayLengthMinutes, time_parser.convert(time.sunrise), time_parser.convert(time.sunset), time_parser.convert(time.time))
return RustTime(time.dayLengthMinutes, time_parser.convert(time.sunrise), time_parser.convert(time.sunset), time_parser.convert(time.time), time.time)

async def __getInfo(self) -> RustInfo:

Expand Down
6 changes: 3 additions & 3 deletions rustplus/api/structures/rust_chat_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ class RustChatMessage():

def __init__(self, data):

self.steamId = data.steamId
self.name = data.name
self.steamId = int(data.steamId)
self.name = str(data.name)
self.message = str(data.message)
self.colour = data.color
self.time = data.time
self.time = int(data.time)

def __repr__(self):
return "RustChatMessage[steamId={}, senderName={}, message={}, colour={}, time={}]".format(self.steamId, self.name, self.message, self.colour, self.time)
5 changes: 3 additions & 2 deletions rustplus/api/structures/rust_time.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class RustTime:

def __init__(self, day_length, sunrise, sunset, time) -> None:
def __init__(self, day_length, sunrise, sunset, time, raw_time) -> None:

self.day_length = day_length
self.sunrise = sunrise
self.sunset = sunset
self.time = time
self.raw_time = raw_time

def __str__(self) -> str:
return "RustTime[day_length={}, sunrise={}, sunset={}, time={}]".format(self.day_length, self.sunset, self.sunset, self.time)
return "RustTime[day_length={}, sunrise={}, sunset={}, time={}, raw_time={}]".format(self.day_length, self.sunset, self.sunset, self.time, self.raw_time)
2 changes: 1 addition & 1 deletion rustplus/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .command_options import CommandOptions
from .command_handler import RustCommandHandler
from .command import Command
from .command import Command, CommandTime
11 changes: 10 additions & 1 deletion rustplus/commands/command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from typing import List

class CommandTime:

def __init__(self, formatted_time, raw_time) -> None:

self.formatted_time = formatted_time
self.raw_time = raw_time

class Command:

def __init__(self, sender_name, sender_steamid, time, command, args) -> None:
def __init__(self, sender_name : str, sender_steamid : int, time : CommandTime, command : str, args : List[str]) -> None:

self.sender_name = sender_name
self.sender_steamid = sender_steamid
Expand Down
9 changes: 5 additions & 4 deletions rustplus/commands/command_handler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import asyncio

from rustplus import commands, exceptions
from datetime import datetime

from ..api.structures import RustChatMessage
from .command_options import CommandOptions
from .command import Command
from .command import Command, CommandTime

class RustCommandHandler:

Expand All @@ -26,4 +25,6 @@ async def run_command(self, message : RustChatMessage) -> None:

coro = getattr(self, command)

await coro(Command(message.name, message.steamId, message.time, command, message.message.split(" ")[1:]))
time = CommandTime(datetime.utcfromtimestamp(message.time), message.time)

await coro(Command(message.name, message.steamId, time, command, message.message.split(" ")[1:]))

0 comments on commit 0bc1ca2

Please sign in to comment.