Skip to content

Commit

Permalink
Implement script to get tgt of Character AI automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
SeoulSKY committed Jan 17, 2024
1 parent f05f8f7 commit a0fb0c8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 88 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Create `.env` file, copy and paste all contents from `.env.example` file, and fi
| FIREBASE_CLIENT_X509_CERT_URL | Same as above |
| CAI_TOKEN | Token for your Character AI account. Follow the [guide](https://pycai.gitbook.io/welcome/api/values) to learn how to acquire it. |
| CAI_CHAR_ID | ID for the character in the Character AI. Follow the [guide](https://pycai.gitbook.io/welcome/api/values) to learn how to acquire it. |
| CAI_TGT | ID for the target in the Character AI. Its value starts with `internal_id:` Follow the [guide](https://pycai.gitbook.io/welcome/api/values) to learn about it. |
| CAI_TGT | ID for the target in the Character AI. Its value starts with `internal_id:`. Run `scripts/cai_tgt.py` to get it. |
</details>

### Running with [Docker](https://www.docker.com) and [Docker Compose](https://docs.docker.com/compose/install/) (Recommended)
Expand Down
37 changes: 1 addition & 36 deletions firestore/channel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
Provides functions to interact with the channel configs in the firestore
Classes:
Channel
Functions:
get_collection()
has_channel()
Expand All @@ -14,39 +11,7 @@
from google.cloud.firestore_v1 import AsyncCollectionReference

from firestore import db


class Channel:
"""
A wrapper class to represent channel configs in the database
"""

def __init__(self, channel_id: int, translate_to: list[str] = None):
self.channel_id = channel_id
if translate_to is None:
translate_to = []
self.translate_to: list[str] = translate_to

@staticmethod
def from_dict(source: dict):
"""
Create a new user configs from the given source
:param source: The source to create a new user
:return: The new user config
"""
temp_id = 0
user = Channel(temp_id)
for key, value in source.items():
setattr(user, key, value)

return user

def to_dict(self) -> dict:
"""
Convert this user configs to dictionary
:return: The dictionary
"""
return vars(self)
from mongo.channel import Channel


def get_collection() -> AsyncCollectionReference:
Expand Down
12 changes: 0 additions & 12 deletions firestore/exceptions.py

This file was deleted.

40 changes: 1 addition & 39 deletions firestore/user.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
Provides functions to interact with the user configs in the firestore
Classes:
User
Functions:
get_collection()
has_channel()
Expand All @@ -14,42 +11,7 @@
from google.cloud.firestore_v1 import AsyncCollectionReference

from firestore import db


class User:
"""
A wrapper class to represent user configs in the database
"""

def __init__(self, user_id: int, chat_history_id: str = None, translate_to: list[str] = None,
main_language: str = None):
self.user_id = user_id
self.chat_history_id = chat_history_id
if translate_to is None:
translate_to = []
self.translate_to: list[str] = translate_to
self.main_language = main_language

@staticmethod
def from_dict(source: dict):
"""
Create a new user configs from the given source
:param source: The source to create a new user
:return: The new user config
"""
temp_user_id = 0
user = User(temp_user_id)
for key, value in source.items():
setattr(user, key, value)

return user

def to_dict(self) -> dict:
"""
Convert this user configs to dictionary
:return: The dictionary
"""
return vars(self)
from mongo.user import User


def get_collection() -> AsyncCollectionReference:
Expand Down
30 changes: 30 additions & 0 deletions scripts/cai_tgt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
This script is used to get the tgt of a character.
"""

import asyncio
import sys

from characterai.pyasynccai import PyAsyncCAI


async def main():
"""
Main function
"""

if len(sys.argv) != 3:
print("Usage: python cai_tgt.py <token> <character_id>")
sys.exit(1)

client = PyAsyncCAI(sys.argv[1])
json = await client.character.info(sys.argv[2])

if "status" in json:
raise RuntimeError(json["status"])

print("tgt:", json["character"]["participant__user__username"])


if __name__ == "__main__":
asyncio.run(main())
1 change: 1 addition & 0 deletions scripts/clear_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Clears all app commands of the bot
"""

import os
import sys

Expand Down

0 comments on commit a0fb0c8

Please sign in to comment.