CactusDev / CactusBot

An open source, community-written service-agnostic chat bot
MIT License
30 stars 6 forks source link

Move MessagePackets to raw strings #248

Closed 2Cubed closed 6 years ago

2Cubed commented 7 years ago

Currently, we store MessagePackets, comprising of components which each contain data, text, and type.

{
  "data": "Hello, world!",
  "text": "Hello, world!",
  "type": "text"
}

While this is a good format, it makes storage errors due to parsing very easy. (For example, if stored with the incorrect link type instead of url, the component will not be seen as a URL until the packet is re-added.)

Instead, we should store plaintext, and use helper functions to perform operations on it.

For example, rather than storing ("Cactus! ", "Cactus! ", "text"), ("🌡", "🌡", "emoji"), we would simply store "Cactus! 🌡". Methods of MessagePacket would still perform the same operations, but using this simpler format, rather than the nested components.

This will require far less mass updating of data for schema upgrades; if we currently wanted to make variable a valid type currently, for example, we would have to change every stored MessagePacket in the database. We also gain access to Python's powerful string processing tools, without having to use .text or writing custom versions of the methods.

Innectic commented 7 years ago

How would we use this to create cross-service stuff?

2Cubed commented 7 years ago

@Innectic In the same way that our current format works.

If a user on Beam sends Hello! :cactus and we receive a Beam-formatted packet, we then convert it to reflect the standard we set for these text-based packets. (Hello! 🌡)

2Cubed commented 7 years ago

Unicode emoji filtering is "impossible", unless you have a giant list of all Unicode emoji somewhere. Maybe use a custom regex? The following seems like it should work, without getting in the way of anything that would show up in a regular message (Favorite food: potato, 12:56:43pm, etc.).

:[a-zA-Z]\w+:
2Cubed commented 6 years ago

Closed in favor of a standard CactusBot format.