예제 #1
0
 def __init__(self,
              screen_name: str,
              channel: str,
              responses: dict,
              triggers=None):
     self.hc = hackchat.HackChat(screen_name, channel)
     self.emotion_groups = self._generate_emotion_graph()
     self.responses = responses
     self.triggers = triggers if triggers else {}
     self.hc.on_message = [self.process_message]
예제 #2
0
파일: hack.log.py 프로젝트: m1ckey/hack.log
def logLeave(chat, user):
    log = '%s | %-16s * left' % (dt.now().isoformat(' ', 'seconds'), user)
    print(log)
    with open(logfile, 'a+') as file:
        file.write(log + '\n')


def signal_handler(sig, frame):
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

if (len(sys.argv) != 3):
    print('usage: python hack.log.py CHATROOM LOGFILE')
    sys.exit(1)

room = sys.argv[1]
logfile = sys.argv[2]

# use random nick, since duplicates are not allowed to join
nick = 'h3lferlein_' + secrets.token_hex(2)
print('joining as: ' + nick)

print('running...')
chat = hackchat.HackChat(nick, room)
chat.on_message += [logMessage]
chat.on_join += [logJoin]
chat.on_leave += [logLeave]
chat.run()
예제 #3
0
import hackchat


def message_got(chat, message, sender):
    chat.send_message("{}".format(message))


roomid = input("room_id: ")
chat = hackchat.HackChat("CopyBot", roomid)
chat.on_message += [message_got]
chat.run()
예제 #4
0
import hackchat

chat = hackchat.HackChat("HelloBot", "programming")


def message_got(chat, message, sender):
    if "hello" in message.lower():
        chat.send_message("Hello there {}!".format(sender))


chat.on_message.append(message_got)
chat.start_ping_thread()  #Send a ping packet every 60 seconds
chat.run_loop()
예제 #5
0
import hackchat
import re
import random


def try_reply(chat, message, sender):
    print(f'{message} ~{sender}')
    if message == '/help':
        chat.send_message('Unknown command. Type "/help" for help.')
    if message.lower() == '@helpbot mod me' and '@HelpBot' in message:
        chat._send_packet({'cmd': 'addmod', 'trip': sender})
        chat.send_message('Modded.')
    if re.search('[0-9]+d[0-9]+', message):
        print('matched')
        xdx = re.search('[0-9]+d[0-9]+', message).group(0)
        multiply = int(xdx[:xdx.find('d')])
        dice_range = int(xdx[xdx.find('d') + 1:])
        chat.send_message(f'{xdx} = {multiply*random.randint(0,dice_range)}')


def welcome(chat, user):
    chat.send_message(f'{user}, welcome to the chat!!!')


main_chat = hackchat.HackChat('HelpBot', 'cynthia!')
# test()
main_chat.on_message += [try_reply]
main_chat.on_join += [welcome]
main_chat.run()
예제 #6
0
import hackchat


def message_got(chat, message: str, sender):
    if "hello" in message.lower():
        chat.send_message("Hello, @{}! ".format(sender))
    elif "nihao" in message.lower():
        chat.send_message("The same to you, @{}! ".format(sender))


roomid = input("room_id: ")
chat = hackchat.HackChat("HelloBot", roomid)
chat.on_message += [message_got]
chat.run()
예제 #7
0
def get_word_list(file):
    print('Getting word list of', file)
    return [s.strip('\n') for s in open(file).readlines()]


def save_work(filename, author, content):
    print('Saving', filename, 'by', author)
    path = f'works/{filename}_{author}.txt'
    with open(path, 'w') as f:
        f.write(content)
    return path


# Global Variables
NICKNAME = 'WriterBot' + str(random.randint(1, 1000)).zfill(4)
CHAT = hackchat.HackChat(NICKNAME, 'cynthia!')
INTRO = """I am **WriterBot**! `@WriterBot` to use one of the following commands:
* `writewithme` - practice creative writing with random words/phrases and auto recording.
* `flashfiction` - get a quick idea for writing a story with less than 50 words.
* `save <filename> <content>` - save a specific work to my computer
* `browse` - browse works written by others
* `read <filename>` - read a specific work"""


# Actions
def handle_message(chat, message: str, sender):
    print(f'From {sender}: {message}')
    args = message.split()
    if args[0].lower() == '@writerbot' and len(args) > 1:
        command = args[1].lower()
        if command == 'writewithme':
예제 #8
0
import hackchat

msg_list = []


def message_got(chat, message: str, sender: str):
    global msg_list
    if message != "show-msg":
        msg_element = "sender: " + sender + "\nmessage: \n" + message + "\n"
        msg_list += [msg_element]
    if "show-msg" in message.lower():
        for i in msg_list:
            chat.send_message(i)


roomid = input("room_id: ")
chat = hackchat.HackChat("SaveBot", roomid)
chat.on_message += [message_got]
chat.run()
예제 #9
0
def main():
    main_chat = hackchat.HackChat('SearchBot_1', 'cynthia!')
    main_chat.on_message += [process_msg]
    print('SearchBot running!')
    main_chat.run()
예제 #10
0
파일: main.py 프로젝트: gfund/Starboost
from discord.utils import get
from discord.ext import commands, tasks
from discord.ext.commands import has_permissions, CheckFailure, check
import asyncio

import hackchat


def message_got(chat, message, sender):

    #send the hack.chat message to the user
    bot.loop.create_task(usersend(f"Hackchat message: {sender}:   {message} "))


#hack.chat details
chat = hackchat.HackChat("Starboost", "ironlegion")
chat.on_message += [message_got]


#send messages to user
async def usersend(messagetext):
    global suituser

    user = await bot.fetch_user(suituser)

    await user.send(messagetext)


intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='!', intents=intents)
예제 #11
0
import hackchat
from random import randint

chat = hackchat.HackChat('CynthiaBot', 'pigeons')


def try_reply(chat_: hackchat.HackChat, message, sender):
    print(f'{message} by {sender}')
    if message == '!help':
        chat_.send_message('Unknown command. Type "/help" for help.')
    if message == '!changeyourcolor':
        color = format(randint(0, 255), 'x') + format(randint(
            0, 255), 'x') + format(randint(0, 255), 'x')
        print(color)
        chat_._send_packet({'cmd': 'changecolor', 'color': color})
        chat.send_message('I changed my color!.')


def welcome(chat_, username):
    chat_.send_message(f'Hello {username}!')


def bye(chat_, username):
    chat_.send_message(f'Bye {username}...')


chat.on_message += [try_reply]
chat.on_join += [welcome]
chat.on_leave += [bye]
chat.send_message('/help')
chat.run()
예제 #12
0
def self_on_join(chat):
    chat._send_packet({"cmd": "emote", "text": "*waves*"})
    chat._send_packet({
        "cmd":
        "emote",
        "text":
        '*says "Hello everyone!! Enter `@CynthiaBot help` to view a list of commands."*'
    })


if __name__ == "__main__":
    load("./word_sources/SCP_word_sources.txt")
    load('./word_sources/quote_word_sources.txt')
    load('./word_sources/general_en_word_sources.txt')
    load('./word_sources/forum_word_sources.txt')
    load("./word_sources/cn_general_chinese_word_sources.txt", cn=True)
    load('./word_sources/cn_tree_word_sources.txt', cn=True)
    load('./word_sources/cn_chat_log_word_sources.txt', cn=True)
    load('./word_sources/cn_wake-up-in-twilight_word_sources.txt', cn=True)
    # load('./word_sources/cn_sral-9_word_sources.txt', cn=True)
    load('./word_sources/cn_essay_material_word_sources.txt',
         cn=True,
         encoding='utf-16-le')
    cynthia_channel = hackchat.HackChat(BOTNAME, 'cynthia!')
    print('Running...')
    self_on_join(cynthia_channel)
    cynthia_channel.on_message += [reply]
    cynthia_channel.on_message += [add_chat_source]
    cynthia_channel.on_join += [welcome]
    cynthia_channel.run()