コード例 #1
0
ファイル: Commands.py プロジェクト: sri-shree/Thunder
def commandAlive(message, args):
    secsAlive = time.time() - Utilities.startTime
    uptime = divmod(secsAlive, 60)
    secs = int(uptime[1])
    hrUptime = divmod(uptime[0], 60)
    mins = int(hrUptime[1])
    hrs = int(hrUptime[0])

    postReply(
        message, Utilities.botLink + " running since " + str(hrs) +
        " hours, " + str(mins) + " minutes and " + str(secs) + " seconds.")
コード例 #2
0
ファイル: Commands.py プロジェクト: sri-shree/Thunder
def commandUntrackBot(message, args):
    TrackBots.delete_bot(int(args[0]))

    if args[0].startswith("userid="):
        TrackBots.delete_bot(int(args[0].replace("userid=", "")))
    elif args[0].startswith("user_id=", ""):
        TrackBots.delete_bot(int(args[0].replace("user_id=", "")))
    else:
        TrackBots.delete_bot(int(args[0]))

    postReply(message, "Bot with userID '" + args[0] + "' has been deleted.")
コード例 #3
0
ファイル: Commands.py プロジェクト: sri-shree/Thunder
def commandDeleteQuietRoom(message, args):
    roomID = 0
    if args[0].startswith("roomid="):
        roomID = int(args[0].replace("roomid=", ""))
    else:
        postReply(message, "Please provide a `roomid=`.")
        return

    QuietRooms.delete_quiet_room(roomID)

    postReply(message,
              "Quiet room with id '" + str(roomID) + "' has been deleted.")
コード例 #4
0
ファイル: Commands.py プロジェクト: sri-shree/Thunder
def commandTrackBot(message, args):
    newBot = {
        "name": "unknown",
        "user_id": -1,
        "to_ping": "unknown",
        "time_to_wait": -1,
        "last_message_time": time.time(),
        "rooms": []
    }

    for each_arg in args:
        if each_arg.startswith("name="):
            newBot["name"] = each_arg.replace("name=", "")
        elif each_arg.startswith("userid="):
            newBot["user_id"] = int(each_arg.replace("userid=", ""))
        elif each_arg.startswith("userID="):
            newBot["user_id"] = int(each_arg.replace("userID=", ""))
        elif each_arg.startswith("user_id="):
            newBot["user_id"] = int(each_arg.replace("user_id=", ""))
        elif each_arg.startswith("to_ping="):
            newBot["to_ping"] = each_arg.replace("to_ping=", "")
        elif each_arg.startswith("time_to_wait="):
            newBot["time_to_wait"] = int(each_arg.replace("time_to_wait=", ""))
        elif each_arg.startswith("rooms="):
            stripped_arg = each_arg.replace("rooms=")
            newBot["rooms"] = stripped_arg.split(",")

    if len(newBot["rooms"]) == 0:
        newBot["rooms"] = [message.room.id]

    if (newBot["name"] == "unknown") or (newBot["user_id"] == -1) or (
            newBot["to_ping"] == "unknown") or (newBot["time_to_wait"] == -1):
        postReply(
            message,
            "Please provide adequate arguments: `name`, `user_id`, `to_ping`, `time_to_wait` and optionally `rooms`."
        )
    else:
        TrackBots.add_bot(newBot["name"], newBot["user_id"], newBot["to_ping"],
                          newBot["rooms"], newBot["time_to_wait"],
                          newBot["last_message_time"], True)
        postReply(
            message, "Bot '" + newBot["name"] +
            "' has been added to the bot watch list.")
コード例 #5
0
ファイル: Commands.py プロジェクト: sri-shree/Thunder
def commandAddQuietRoom(message, args):
    roomID = 0
    interval = 120

    for each_arg in args:
        if each_arg.startswith("roomid="):
            roomID = int(each_arg.replace("roomid=", ""))
        elif each_arg.startswith("interval="):
            interval = int(each_arg.replace("interval=", ""))

    if roomID == 0:
        postReply(message,
                  "Please provide a `roomid=` and optionally an `interval=`.")
        return

    QuietRooms.add_quiet_room(roomID, interval)

    postReply(message,
              "Quiet room with id '" + str(roomID) + "' has been added.")
コード例 #6
0
ファイル: Commands.py プロジェクト: sri-shree/Thunder
def commandUpdateBot(message, args):
    user_id = -1
    if args[0].startswith("userid="):
        user_id = int(args[0].replace("userid=", ""))
    elif args[0].startswith("user_id="):
        user_id = int(args[0].replace("user_id=", ""))
    elif args[0].startswith("userID="):
        user_id = int(args[0].replace("userID=", ""))

    if user_id == -1:
        postReply(message, "Please give the first argument as 'user_id=<id>'.")
        return

    bot = TrackBots.get_bot(user_id)

    for each_arg in args:
        if each_arg.startswith("time_to_wait="):
            bot.update_time_to_wait(int(each_arg.replace("time_to_wait=", "")))
        elif each_arg.startswith("to_ping="):
            bot.update_to_ping(each_arg.replace("to_ping=", ""))

    postReply(message, "The bot has been updated.")
コード例 #7
0
ファイル: Commands.py プロジェクト: sri-shree/Thunder
def commandShutdown(message, args):
    postReply(message, "Shutting down...")
    BackgroundTasks.shouldShutdown = True
コード例 #8
0
ファイル: Commands.py プロジェクト: sri-shree/Thunder
def commandReboot(message, args):
    postReply(message, "Rebooting...")
    BackgroundTasks.shouldReboot = True
コード例 #9
0
ファイル: Commands.py プロジェクト: sri-shree/Thunder
def commandHelp(message, args):
    postReply(
        message,
        "I'm " + Utilities.botLink + ", a status monitoring bot for SOBotics.")
コード例 #10
0
ファイル: Commands.py プロジェクト: sri-shree/Thunder
def commandUpdateCode(message, args):
    call(["git", "pull", "origin", "master"])
    BackgroundTasks.shouldReboot = True
    postReply(message, "Updating...")