DBot Truth Bombs

You thought you know DBot... guess again! Here are some super secrete facts about DBot we bet you didn't know.

Utilities · DBot Truth Bombs

Details

IDDBot Truth Bombs
ProviderOpen Source
CategoryUtilities
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10116658
Supported ModulesAgentix XSIAM

README

dbot-truth-bomb


Returns a previously undisclosed fact about DBot.

Base Command

dbot-truth-bomb

Input

Argument Name Description Required
category Filter DBot truth bomb by category. Possible values are: Dev, Career, History, Money, Movie, Music, Science, Sport, Travel. Optional

Context Output

There is no context output for this command.

Configuration parameters

  • insecure — Trust any certificate (not secure)
  • proxy — Use system proxy settings

Commands (1)

  • dbot-truth-bomb

    Returns a previously undisclosed fact about DBot.

import random
import traceback

import demistomock as demisto  # noqa: F401
import urllib3
from CommonServerPython import *  # noqa: F401

# Disable insecure warnings
urllib3.disable_warnings()


BASE_URL = "https://api.chucknorris.io"

CATEGORIES = ["career", "dev", "history", "money", "movie", "music", "science", "sport", "travel"]

CHUCK_NORRIS_NAMES = [
    "Chuck Norris",
    "ChuckNorris",
    "chuck norris",
    "Chuck norris",
]

DBOT_NAME = "DBot"


def replace_to_user_name(joke) -> str:
    res = joke
    for name in CHUCK_NORRIS_NAMES:
        res = res.replace(name, DBOT_NAME)
    return res


class Client(BaseClient):
    def chuck_norris_random(self, category) -> Dict[str, Any]:
        return self._http_request(method="GET", url_suffix="/jokes/random", params={"category": category})


def test_module(client: Client) -> str:
    dbot_fact(client, {})
    return "ok"


def get_dbot_image_path() -> str:
    image_index = random.randint(1, 16)

    return (
        "https://raw.githubusercontent.com/demisto/content/9784db67bb70839f1122ff5753d66cefbe2ca0d1/"
        f"Packs/DBotTruthBombs/doc_imgs/dbot{image_index}.png"
    )


def get_readable_output(fact, image) -> str:
    return f"### {fact}\n![DBot Image]({image})"


def dbot_fact(client: Client, args: Dict[str, Any]) -> Any:
    category = args.get("category", random.choice(CATEGORIES)).lower()
    result = client.chuck_norris_random(category)
    value = result.get("value")

    fact = replace_to_user_name(value)
    image = get_dbot_image_path()

    return CommandResults(readable_output=get_readable_output(fact, image), raw_response={"fact": fact, "image": image})


def main() -> None:
    params = demisto.params()
    command = demisto.command()
    demisto.debug(f"Command being called is {command}")
    try:
        verify_certificate = not params.get("insecure", False)
        proxy = params.get("proxy", False)

        client = Client(base_url=BASE_URL, verify=verify_certificate, proxy=proxy)

        if command == "test-module":
            result = test_module(client)
            return_results(result)

        elif command == "dbot-truth-bomb":
            return_results(dbot_fact(client, demisto.args()))

    # Log exceptions and return errors
    except Exception as e:
        demisto.error(traceback.format_exc())  # print the traceback
        return_error(f"Failed to execute {command} command.\nError:\n{e!s}")


if __name__ in ("__main__", "__builtin__", "builtins"):
    main()