<commit_before>from twisted.plugin import IPlugin
from desertbot.moduleinterface import IModule
from desertbot.modules.commandinterface import BotCommand
from desertbot.message import IRCMessage
from desertbot.response import IRCResponse, ResponseType
from desertbot.utils.api_keys import load_key
from desertbot.utils.timeutils import now, timestamp
from zope.interface import implementer
from datetime import datetime
from typing import Union


@implementer(IPlugin, IModule)
class Time(BotCommand):
    timeBaseURL = "https://maps.googleapis.com/maps/api/timezone/json?"

    def triggers(self):
        return ["time"]

    def help(self, query: Union[str, None]) -> str:
        return "Commands: time <lat> <lon>, time <place>, time <nickname> | Get the current local time for " \
               "the given latlon, place or user."

    def onLoad(self) -> None:
        self.apiKey = load_key("Google")

    def execute(self, message: IRCMessage):
        if not self.apiKey:
            return IRCResponse(ResponseType.Say, "No API key found.", message.replyTo)

        params = message.parameterList

        # Use the user's nickname as a parameter if none were given
        if len(params) == 0:
            params.append(message.user.nick)
            selfSearch = True
        else:
            selfSearch = False

        # Try using latlon to get the location
        try:
            lat = float(params[0])
            lon = float(params[1])
            location = self.bot.moduleHandler.runActionUntilValue("geolocation-latlon", lat, lon)
            if not location:
                return IRCResponse(ResponseType.Say,
                                   "I can't determine locations at the moment. Try again later.",
                                   message.replyTo)
            if not location["success"]:
                return IRCResponse(ResponseType.Say,
                                   "I don't think that's even a location in this multiverse...",
                                   message.replyTo)
            return self._handleCommandWithLocation(message, location)
        except (IndexError, ValueError):
            pass  # The user did not give a latlon, so continue using other methods

        # Try to determine the user's location from a nickname
        userLoc = self.bot.moduleHandler.runActionUntilValue("userlocation", params[0])
        if selfSearch:
            if not userLoc:
                return IRCResponse(ResponseType.Say,
                                   "I can't determine locations at the moment. Try again later.",
                                   message.replyTo)
            elif not userLoc["success"]:
                return IRCResponse(ResponseType.Say, userLoc["error"], message.replyTo)
        if userLoc and userLoc["success"]:
            if "lat" in userLoc:
                location = self.bot.moduleHandler.runActionUntilValue("geolocation-latlon", userLoc["lat"],
                                                                      userLoc["lon"])
            else:
                location = self.bot.moduleHandler.runActionUntilValue("geolocation-place", userLoc["place"])
            if not location:
                return IRCResponse(ResponseType.Say, "I can't determine locations at the moment. Try again later.",
                                   message.replyTo)
            if not location["success"]:
                return IRCResponse(ResponseType.Say, "I don't think that's even a location in this multiverse...",
                                   message.replyTo)
            return self._handleCommandWithLocation(message, location)
<commit_msg>[Time] Fix dictionary key<commit_after>from twisted.plugin import IPlugin
from desertbot.moduleinterface import IModule
from desertbot.modules.commandinterface import BotCommand
from desertbot.message import IRCMessage
from desertbot.response import IRCResponse, ResponseType
from desertbot.utils.api_keys import load_key
from desertbot.utils.timeutils import now, timestamp
from zope.interface import implementer
from datetime import datetime
from typing import Union


@implementer(IPlugin, IModule)
class Time(BotCommand):
    timeBaseURL = "https://maps.googleapis.com/maps/api/timezone/json?"

    def triggers(self):
        return ["time"]

    def help(self, query: Union[str, None]) -> str:
        return "Commands: time <lat> <lon>, time <place>, time <nickname> | Get the current local time for " \
               "the given latlon, place or user."

    def onLoad(self) -> None:
        self.apiKey = load_key("Google")

    def execute(self, message: IRCMessage):
        if not self.apiKey:
            return IRCResponse(ResponseType.Say, "No API key found.", message.replyTo)

        params = message.parameterList

        # Use the user's nickname as a parameter if none were given
        if len(params) == 0:
            params.append(message.user.nick)
            selfSearch = True
        else:
            selfSearch = False

        # Try using latlon to get the location
        try:
            lat = float(params[0])
            lon = float(params[1])
            location = self.bot.moduleHandler.runActionUntilValue("geolocation-latlon", lat, lon)
            if not location:
                return IRCResponse(ResponseType.Say,
                                   "I can't determine locations at the moment. Try again later.",
                                   message.replyTo)
            if not location["success"]:
                return IRCResponse(ResponseType.Say,
                                   "I don't think that's even a location in this multiverse...",
                                   message.replyTo)
            return self._handleCommandWithLocation(message, location)
        except (IndexError, ValueError):
            pass  # The user did not give a latlon, so continue using other methods

        # Try to determine the user's location from a nickname
        userLoc = self.bot.moduleHandler.runActionUntilValue("userlocation", params[0])
        if selfSearch:
            if not userLoc:
                return IRCResponse(ResponseType.Say,
                                   "I can't determine locations at the moment. Try again later.",
                                   message.replyTo)
            elif not userLoc["success"]:
                return IRCResponse(ResponseType.Say, userLoc["error"], message.replyTo)
        if userLoc and userLoc["success"]:
            if "lat" in userLoc:
                location = self.bot.moduleHandler.runActionUntilValue("geolocation-latlon", userLoc["lat"],
                                                                      userLoc["lon"])
            else:
                location = self.bot.moduleHandler.runActionUntilValue("geolocation-place", userLoc["locality"])
            if not location:
                return IRCResponse(ResponseType.Say, "I can't determine locations at the moment. Try again later.",
                                   message.replyTo)
            if not location["success"]:
                return IRCResponse(ResponseType.Say, "I don't think that's even a location in this multiverse...",
                                   message.replyTo)
            return self._handleCommandWithLocation(message, location)

{'fraction_non_alphanumeric': 0.08135871798383783, 'fraction_numerical': 0.0010957403095466374, 'mean_word_length': 1.9658813972380178, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4719522', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1737, 'n_words': 553}