def bot(): import tsktsk.commands.bot # noqa logging.basicConfig(level=logging.INFO) name = os.environ.get("TSKTSK_NAME", "tsktsk") apply_migrations() smalld = SmallD() create_message = lambda msg: {"content": f"```\n{msg}\n```"} with SmallDCliRunner(smalld, root, prefix="", name=name, create_message=create_message): smalld.run()
import click from smalld import SmallD from smalld_click import SmallDCliRunner @click.command() @click.option("--count", default=1, help="Number of greetings.") @click.option("--name", prompt="Your name", help="The person to greet.") def hello(count, name): """Simple program that greets NAME for a total of COUNT times.""" for x in range(count): click.echo("Hello %s!" % name) smalld = SmallD() with SmallDCliRunner(smalld, hello, prefix="++"): smalld.run()
import collections import logging import os import textwrap from smalld import SmallD, Intent from .message_modification import MessageModification LOG_CHANNEL_ID = os.environ.get("AIO_CHANNEL_ID") logging.basicConfig(level=logging.INFO) smalld = SmallD(token=os.environ.get("AIO_TOKEN"), intents=Intent.GUILD_MESSAGES) def log(what): smalld.post( f"/channels/{LOG_CHANNEL_ID}/messages", { "content" : textwrap.dedent(what) + "\n_ _"}) def register(cls, *args, **kwargs): instance = cls(*args, **kwargs, log=log) def dispatch(payload): if (payload.op != 0): return method = f"on_{payload.t.lower()}" try:
import logging from smalld import SmallD smalld = SmallD.v8() logging.basicConfig(level=logging.DEBUG) @smalld.on_message_create def on_message(msg): if msg.content == "++ping": smalld.post(f"/channels/{msg.channel_id}/messages", {"content": "pong"}) smalld.run()
from monitoro.notifications import Notifications from monitoro.status import Status, Statuses from monitoro.watchers import Watchers NAME = os.environ.get("MT_NAME", "monitoro") DATA_DIR = os.environ.get("MT_DATA", "data") MONITORING_FILE = os.path.join(DATA_DIR, "monitoring.yaml") logging.basicConfig( level=logging.DEBUG if os.environ.get("MT_DEBUG") else logging.INFO) logger = logging.getLogger("monitoro.bot") start_time = datetime.now() smalld = SmallD(intents=Intent.GUILDS | Intent.GUILD_MESSAGES | Intent.DIRECT_MESSAGES | Intent.GUILD_PRESENCES) statuses = Statuses() watchers = Watchers(MONITORING_FILE) notifications = Notifications(smalld, watchers) statuses.add_listener(on_offline=notifications.notify_offline, on_online=notifications.on_online) STATUS_ICONS = { Status.UNKNOWN: "❓", Status.ONLINE: "✅", Status.OFFLINE: "❌", }
def top_elements(array, k): ind = np.argpartition(array, -k)[-k:] return ind[np.argsort(array[ind])][::-1] logging.info('Tokenizing using dictionary from %s', VOCAB_PATH) with open(VOCAB_PATH, 'r') as f: vocabulary = json.load(f) st = SentenceTokenizer(vocabulary, 2000) logging.info('Loading model from %s.', PRETRAINED_PATH) model = torchmoji_emojis(PRETRAINED_PATH) logging.debug(model) smalld = SmallD(intents=Intent.GUILD_MESSAGES) @smalld.on_message_create() def on_message(msg): if not msg.content: return if len(msg.content) > 140: return global threshold tokenized, _, _ = st.tokenize_sentences([msg.content]) prediction = model(tokenized)[0]