Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #127 from Vyxal:discord
Browse files Browse the repository at this point in the history
Something terrible is going down
  • Loading branch information
gingershaped authored Dec 6, 2023
2 parents f382a63 + 87fb60e commit b00af80
Show file tree
Hide file tree
Showing 18 changed files with 1,653 additions and 962 deletions.
675 changes: 473 additions & 202 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ gidgethub = "^5.2.1"
sechat = { git = "https://github.com/GingerIndustries/sechat.git", branch = "v2" }
cachetools = "^5.3.1"
tomli = "^2.0.1"
tinydb = "^4.7.1"
pyjwt = "^2.7.0"
python-dateutil = "^2.8.2"
websockets = "^10.4"
pyyaml = "^6.0"
odmantic = "^0.9.2"
blinker = "^1.7.0"
pydantic = "<2.0"
discord-py = "^2.3.2"
bs4 = "^0.0.1"
uwuipy = "^0.1.7"

[tool.poetry.group.dev.dependencies]
Expand Down
93 changes: 34 additions & 59 deletions vyxalbot2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,23 @@
import asyncio
from typing import Optional, cast, Any
from time import time
from typing import cast, Any
from datetime import datetime
from pathlib import Path
from asyncio import create_task, wait_for
from html import unescape
from string import ascii_letters

import logging
import sys
import json
import os
import random
import re
import codecs
import base64
import subprocess

from aiohttp.web import run_app
from discord.utils import setup_logging
from motor.motor_asyncio import AsyncIOMotorClient

import tomli
import yaml

from aiohttp import ClientSession
from aiohttp.web import Application, Request, Response, run_app
from aiohttp.client_exceptions import ContentTypeError
from sechat import Bot, Room, MessageEvent, EventType
from gidgethub import HTTPException as GitHubHTTPException, ValidationError
from gidgethub.aiohttp import GitHubAPI as AsyncioGitHubAPI
from gidgethub.abc import GitHubAPI
from gidgethub.routing import Router
from gidgethub.sansio import Event as GitHubEvent
from gidgethub.apps import get_installation_access_token, get_jwt
from cachetools import LRUCache
from dateutil.parser import parse as parseDatetime
from uwuivy import uwuipy
from vyxalbot2.github import GitHubApplication

from vyxalbot2.github import GitHubApplication
from vyxalbot2.reactions import Reactions
from vyxalbot2.services.discord import DiscordService
from vyxalbot2.services.se import SEService
from vyxalbot2.userdb import UserDB
from vyxalbot2.types import PublicConfigType, PrivateConfigType, MessagesType, AppToken
from vyxalbot2.chat import Chat
from vyxalbot2.types import CommonData, PublicConfigType, PrivateConfigType, MessagesType

__version__ = "2.0.0"

Expand All @@ -57,39 +37,38 @@ def __init__(
self.privateConfig = privateConfig
self.messages = messages
self.statuses = list(filter(lambda i: hash(i) != -327901152, statuses))
self.userDB = UserDB(storagePath, publicConfig["groups"])

with open(privateConfig["pem"], "r") as f:
self.privkey = f.read()

async def run(self):
self.bot = Bot(logger=self.logger)
await self.bot.authenticate(
self.privateConfig["chat"]["email"],
self.privateConfig["chat"]["password"],
self.privateConfig["chat"]["host"],
userDB = UserDB(AsyncIOMotorClient(self.privateConfig["mongoUrl"]), self.privateConfig["database"])

ghApp = GitHubApplication(self.publicConfig, self.privkey, self.privateConfig["appID"], self.privateConfig["account"], self.privateConfig["webhookSecret"])
reactions = Reactions(self.messages, self.privateConfig["chat"]["ignore"])

common = CommonData(
self.statuses,
self.messages,
self.publicConfig,
self.privateConfig,
0,
datetime.now(),
userDB,
ghApp
)
self.session = ClientSession()
self.room = await self.bot.joinRoom(self.privateConfig["chat"]["room"])
self.ghApp = GitHubApplication(self.room, self.publicConfig, self.privkey, self.privateConfig["appID"], self.privateConfig["account"], self.session, self.privateConfig["webhookSecret"])
self.chat = Chat(self.room, self.userDB, self.ghApp, self.session, self.publicConfig, self.privateConfig, self.messages, self.statuses)
await self.room.send(
"Well, here we are again."
if random.random() > 0.01
else "GOOD MORNING, MOTHERF***ERS"
)
self.startupTime = datetime.now()
self.se = await SEService.create(reactions, common)
self.discord = await DiscordService.create(reactions, common)
ghApp.services.append(self.se)
ghApp.services.append(self.discord)

self.ghApp.on_shutdown.append(self.shutdown)
return self.ghApp
ghApp.on_shutdown.append(self.shutdown)
return ghApp

async def shutdown(self, _):
try:
await self.room.send("Shutting down...")
except RuntimeError:
pass
await wait_for(self.bot.shutdown(), 6)
await wait_for(self.session.close(), 3)
await self.se.shutdown()
await self.discord.shutdown()


def run():
PUBLIC_CONFIG_PATH = os.environ.get("VYXALBOT_CONFIG_PUBLIC", "config.json")
Expand All @@ -99,11 +78,7 @@ def run():
MESSAGES_PATH = DATA_PATH / "messages.toml"
STATUSES_PATH = DATA_PATH / "statuses.txt"

logging.basicConfig(
format="[%(name)s] %(levelname)s: %(message)s",
stream=sys.stdout,
level=logging.INFO,
)
setup_logging()

with open(PUBLIC_CONFIG_PATH, "r") as f:
publicConfig = json.load(f)
Expand Down
Loading

0 comments on commit b00af80

Please sign in to comment.