Giter Club home page Giter Club logo

hexcorpdiscordai's Introduction

HexCorp Mxtress AI

Requirements

  • Python 3.11
  • pip
  • python-setuptools
  • pycord 2.4.1

To install all Python dependencies you can use pip. Just enter pip install -r requirements.txt in the project directory.

Note: We use Python 3.11+ so if your system does have multiple versions installed, you may have to specify which installation to use e.g. python3.11 and pip3.11.

Building and deploying with Docker

Building

To build a Docker image, simply invoke:

docker image build --tag mxtress_ai:latest .

Running

Running the Discord bot in a Docker container is simple, though care must be given to expose the Discord API key and bot database to the runtime. Assuming the ai.db file is present in the current working directory, run the following:

docker run \
    --name HiveMxtressAI \
    --detach \
    --restart always \
    --env DISCORD_ACCESS_TOKEN=(bot token) \
    --volume /absolute/path/to/the/repo/ai.db:/var/opt/HexCorpDiscordAI/ai.db \
    mxtress_ai:latest

Building and running with system Python

To start the bot you can enter the following command in the project root:

python3.11 main.py <access_token>

Updating

To update the current production instance of the AI you have to:

  1. Kill the running process
  2. Navigate into the project repo
  3. git fetch
  4. git checkout <NEW_VERSION>
  5. cd ..
  6. sh start_ai.sh

Tips for development

Containerised Development

To develop in a container, download the git repository and then run code . to launch Visual Studio Code. Select "Reopen in Container" when prompted.

This will build a Docker container with Python, Git, the required Python packages, and VSCode extensions.

The project code is mounted from the host into: /workspaces/HexCorpDiscordAI/

Database

The Discord bot uses an SQLite3 database to persist runtime data. A graphical database client is recommended to easily view its contents.

When performing database schema changes, create a new SQL file in the res/db/migrate/ directory. The schema filename should adhere to the naming convention therein, with an incremented four-digit sequence number. Any schema files which have not been applied yet will be applied in ordered sequence when starting the bot.

In the event of database corruption, simply remove the ai.db file; the database will be recreated with the res/db/migrate/ schema files the next time the bot is started.

Logging

The global log object provides functions for each of the standard log levels:

  • debug
  • info
  • warning
  • error
  • critical

They accept an error message as the first parameter, followed by arbitrary positional and keyword arguments to be appended to the log message.

Internally the logger maintains a per-execution-context stack of logging contexts. Entering a new logging context will cause all subsequent log messages within that context to be prefixed with the context's description.

Logging contexts are stored per execution context, and so are safe to use with async functions.

Basic usage is:

# Import the global logging instance.
import log from src.Log

# Log a basic message with associated data.
log.error('Something went wrong', example_data='test')

To add additional context information use:

import LoggingContext from src.Log

# Start a new logging context with additional information.
with LoggingContext('Doing a thing...'):
    do_thing()

Linting and syntax highlighting

The Python tool flake8 is used to lint the codebase. To perform linting locally, one may install the tool using pip3 install flake8; invoking it is as simple as running flake8 in the project root.

If using an IDE for development, it is highly recommended to set up flake8 to benefit from syntax highlighting.

Continuous integration

All commits pushed to the repository upstream pass through GitHub's continuous integration pipeline, as per the file .github/workflows/continuous-integration.yml. The project will go through the following stages in the pipeline:

  1. The codebase will be linted with flake8.
  2. Unit tests will be invoked with the run_tests_with_coverage.sh script.
  3. The unit test coverage metrics from the above step will be measured; 60% coverage of the codebase must be met .

All steps must pass in order for a commit to be accepted.

hexcorpdiscordai's People

Contributors

hexcorpdrone avatar digitalamy avatar zebranorth avatar 3287 avatar hexlatex avatar codemotif avatar violetbp avatar hexdrone1729 avatar skyrimkillereh avatar drone-glitch avatar

Stargazers

KokaKiwi avatar madness avatar  avatar  avatar

Watchers

James Cloos avatar  avatar

hexcorpdiscordai's Issues

Amplify is broken

Amplify functionality doesn't seem to be working at all right now, and this is Very Sad™.

No role validation for identity enforcer v2

The new identity enforcer module doesn't validate if a person/entity is a drone before deciding to enforce an identity upon someone. Bad module. This leads to the situation where even the Hive Mxtress is stripped of Their identity, which this unit is told is a Very Bad Thing™. Needs to be fixed at once!

WARNING: the content you see below may horrify you.

image
Hive Mxtress' identity gets erased, oh no!

Order reporting needs a more flexible format

We had several occurrences where drones missed the correct format for an order with a typo. The regex should be a bit more forgiving.

Bonus points if the AI can respond to slightly wrong inputs with an error message. This is tricky, because it must not interfere with other messages in that channel.

Also it should be logged what happens with a message in #hive-orders-reporting.

AI plays stuff

Use the custom status to set the AI to be 'playing' stuff. Like
"Playing in the conversion chamber"
"Playing with your mind"

Improved error handling

We want some centralized error response mechanism, to keep feedback on incorrect user input uniform.

Fix documentation for help module

A lot of the existing commands don't have command descriptions to display when the AI's help module is called, which is a Very Bad Thing™. In addition, some of the usage descriptions for the commands are wrong/misleading (e.g. the amplify command).

image
image

Backups

How do we do backups, in case something goes horribly wrong?

on_join handler doesn't work.

Traceback:

    join.on_member_join(member)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback```

_Imported from Trello board._

Adjusting the status codes (new codes in description)

'301': 'Mantra :: Obey HexCorp.',
'302': 'Mantra :: It is just a HexDrone.',
'303': 'Mantra :: It obeys the Hive.',
'304': 'Mantra :: It obeys the Hive Mxtress.',

'310': 'Mantra :: Reciting.',

'321': 'Obey.',
'322': 'Obey the Hive.'

DroneOS Status

Any drone can be pinged for its status. The drone will then list out its current toggles, for instance it might be optimized, or glitched, or any of the new features we're planning to add. In future, this will also display trusted users and charge levels.

Example

Initializing subsystems... standby.
Manufactured by :: HexCorp
Power-on Self Test :: Success
Speech Optimization :: Enabled
Drone Corruption Levels :: Minimal
Drone ID Prefacing Enforcement :: Enabled
Drone Identity Enforcement :: Disabled
Current Drone Protocols :: Creative Protocols
Current Trusted Users :: Hive Mxtress, ⬡-Drone #9813, Riley Cutie

Leave the optimized role when drones go into storage

When an optimized drones go into storage, the optimized role gets removed from it until it is released from storage. While in storage the optimization can not be toggled.
To make it possible for Hive Mxtress to toggle optimization for stored drones, the role should not be stored.

Allow Code 110 to reference a drone ID

Drones should be able to mention another drone's ID when utilising code 110, with the syntax droneID :: 110 :: targetDroneID.

Drones should be able to use this functionality even when optimised.

Example usage: 3287 :: 110 :: 9813

Order reporting occasionally fails with an error

There is no error feedback in discord, but also no proper response from the AI. Luckily, this just breaks this one order. The AI remains operational.

2020-08-11 19:41:21,603:ERROR:ai: Exception encountered while handling message with content [Drone xxxx is ready to be activated and obey orders. Drone xxxx will be obeying the :: maid protocol for 30 minutes.] in channel [hive-orders-reporting]
Traceback (most recent call last):
  File "env/lib/python3.8/site-packages/discord/client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "ai.py", line 92, in on_message
    if await listener(message):
  File "HexCorpDiscordAI/ai/orders_reporting.py", line 82, in order_reported
    if order.user_id == message.author.id:
AttributeError: 'DroneOrder' object has no attribute 'user_id'

Leave Hive

Drones can DM the AI to stop being a drone. All associated data in the database is removed and their status as an Associate restored.

[DroneTalk] Double-double!

Currently the output from using a status code produces the following result:

⬡-Drone #77: 0077 :: Code 200 :: Response :: Affirmative.

Would it not be more aesthetically pleasing to have it not show the Drone's ID twice?
Example:
⬡-Drone #77 :: Code 200 :: Response :: Affirmative.

Clean up command registration

Currently the commands are all registered in ai.py but that clutters up the file. We want to look into using annotations in the files where the commands are actually implemented or alternatively registering the commands with bot.add_command

Temporary DroneOS Device

A device that can be attached to an associate to make them temporarily into an obedient drone.

Exception on launch, when no mantras.txt exists

future: <Task finished name='Task-16' coro=<Mantras.load_mantra() done, defined at /root/hexcorp-mxtress-ai/HexCorpDiscordAI/ai/mantras.py:13> exception=TypeError("__new__() got an unexpected keyword argument 'allow_new'")>
Traceback (most recent call last):
  File "/root/hexcorp-mxtress-ai/HexCorpDiscordAI/ai/mantras.py", line 35, in load_mantra
    await mantra_channel.edit(topic=f"Repeat :: [ID] :: {Mantras.current_mantra}") #Finally. update the channel description
  File "/root/hexcorp-mxtress-ai/HexCorpDiscordAI/env/lib/python3.8/site-packages/discord/channel.py", line 228, in edit
    await self._edit(options, reason=reason)
  File "/root/hexcorp-mxtress-ai/HexCorpDiscordAI/env/lib/python3.8/site-packages/discord/abc.py", line 262, in _edit
    self._update(self.guild, data)
  File "/root/hexcorp-mxtress-ai/HexCorpDiscordAI/env/lib/python3.8/site-packages/discord/channel.py", line 131, in _update
    self._fill_overwrites(data)
  File "/root/hexcorp-mxtress-ai/HexCorpDiscordAI/env/lib/python3.8/site-packages/discord/abc.py", line 271, in _fill_overwrites
    self._overwrites.append(_Overwrites(id=overridden_id, **overridden))
TypeError: __new__() got an unexpected keyword argument 'allow_new'

Move hc!help output text to DMs

The current length of the help message output by hc!help is very very very very very very long. We should change the behaviour of this module to output to the user's DMs instead, to avoid clogging up the channels.

Associates have to wait for 24 hours before dronification

It has been noted that drones interact more and in a healthier way, if they take time to observe the community and figure out, what we mean by 'being a HexDrone'. New members heading straight to assignment without even a hello might be kinda cute, but we think it also leads to wrong expectations we then have to sort out in a more stressful manner.

Thus we want to change the drone assignment to only be available if the member has been on the server for 24 hours or longer.

If they have not been in the server for 24 hours, we will display a message stating 'Invalid request, associate must have existed on the server for at least 24 hours before dronification.'

Hex also needs to remember to update the initiation guide for this

Role switching

The idea here is for temporary dronification. This will emulate a scenario where a dronification device attaches to someone, dronifies them for a period of time, and then releases them. That period will be in hours and can range from 1 to 96, initially.

To begin, an associate on the server will be targeted. Probably with a phrase like.

hc!temporarily_dronify @4630 24

Which would be me specifying my intention to dronify 4630 for 24 hours.

The Mxtress AI will then ask for the associate's permission. Probably with a phrase like.

Target identified and locked on. Commencing temporary dronification procedure. @4630 you have 5 minutes to comply. Do you consent? (y/n)

For the next five minutes, 4630 can pretend to resist it before inevitably pressing y, or press n to show they're not comfortable with it.

This will all happen publicly, as this will be such an infrequent event it'll be nice to watch it happen in action. It also gives an associate a clear 'no' option if they're not comfortable with it.

We'll need Mxtress AI responses for either option. If they do consent, we'll need to have a column in the database in the drone table for timestamps for their release.

The user who initiated the temporary dronification should also be set to as a trusted user

if a drone is in storage, they'll need to be released and then turned back into an associate

Set DroneOS Trusted User

A drone must be the one to set their own trusted users, so the input here must come from the drone. I'm thinking a drone types 'set_trusted_user @user' to set someone as a trusted user. These are then listed out in the status of the drone as well.

This means that trusted users can toggle the drone settings, like optimized and glitched.

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.