Giter Club home page Giter Club logo

fchatpy's Introduction

fchatpy

A python library to create bots and chat clients for the F-Chat websocket. This library is still in heavy development, don't expect a bug-free experience quite yet.

This does NOT have a GUI. So unless you're planning on making one yourself, I would not use this to do your chatting on. However, it's pretty easy to make simple bots with this library, if that's what you're looking for.

This library supports nearly every F-Chat command available. So you should be able to do everything a non-chatop can do.

How to install:

In bash, type the following:

pip install -i https://test.pypi.org/simple/ FChatPy==0.3.0

If you're on Windows, I'd recommend installing it with an IDE such as PyCharm.

How to use:

The F-Chat websocket sends and receives messages to/from every user. Each message has a three letter "command" attached to each one, followed by a JSON object of some kind. For example, if a message has the "MSG" command attached to it, that means that command is related to a message sent in a channel. If it has the "PRI" command, then it's a private message sent between two users.

For a list of commands sent to you by the server, go to: https://wiki.f-list.net/F-Chat_Server_Commands

For a list of commands sent to the server by you, go to: https://wiki.f-list.net/F-Chat_Client_Commands

The majority of the functions in client.py either send these commands to the server, or automatically run when these commands are received from the server. By overriding the "on_XXX" functions, you can program how your client responds to these events. For example, let's write a simple bot that just echos private messages sent to it.

from fchatpy import FChatClient

class EchoBot(FChatClient):    
    def on_PRI(self, character, message):
        super().on_PRI(character, message)
        self.PRI(character, message)

if __name__ == "__main__":
    bot = EchoBot('username', 'password', 'character')
    bot.setup()
    bot.run_forever()

As you can see, the way you create a bot is by treating the FChatClient class like an abstract class (even though it's technically not one...) and override any function you want to add features to. In this case, we override the function on_PRI, which is called whenever we get a private message.

Once you've created your new class, you initialize it with three variables: your username, your password, and the name of the character you're using.

If you want to know what a specific command for something is, or what arguments a command uses, check the documentation for that command in the client.py file.

fchatpy's People

Contributors

buildabuddha avatar

Watchers

 avatar  avatar

fchatpy's Issues

Insight on your library?

I'm using your library for my attempt to create a bot. But it's not quite clear on some things - or maybe it is - I'm not a professional developer. I may be missing something.

Is there a command to have the bot wait for a specific response? Example: "What is your name?" Then the bot waits for person that executed the command to respond, store that in a variable, then reply with "Welcome, ::name::."

I can't seem to 1) have the bot wait for said response, and 2) Store response, once it is given, in a variable. The on_MSG command states the variable is 'message' But when run a print command on message, it's always just the input that triggered the command itself (i.e '!create')

Code as follows:

def on_MSG(self, character, message, channel):
        super().on_MSG(character, message, channel)
        if message == "!create":
            super().MSG("ADH-64f8d1b633ed80256a6a", "I did it!")
            basics = self.basics(character, message)
            # abilities = self.abilities(basics)
            # self.save(basics, abilities)

    def on_PRI(self, character, message):
        super().on_PRI(character, message)

    def basics(self, character, message):
        levelDict = {1: [ 25,  1,   6,   15,   2,  1,  5,    75]}
        unspoiledDesire = "ADH-xxxxxxxxxxxxxxxxxxxx"
        # As this is character creation, level will always be equal to 1, and xp always equal to 0
        playerLevel = 1
        playerXP = 0
        # Grabs character's name, and then assigns appropriate values from the dictionary above to display.
        super().PRI(character, "What is your characters name? ")
        time.sleep(10)
        super().MSG(unspoiledDesire, message)`

From my understanding, message should at least be "What is your characters name? " As that was the last string stored in the variable, message.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.