Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something terrible is going down #127

Merged
merged 45 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9f77ac6
Something terrible is going down
gingershaped Nov 3, 2023
b4f48cf
Set up GH event reporting
gingershaped Nov 3, 2023
21cfacb
Get bridge working
gingershaped Nov 4, 2023
b35da04
fixen
gingershaped Nov 4, 2023
9cafdef
Make bot ignore self
gingershaped Nov 4, 2023
91c3f45
funny status
gingershaped Nov 4, 2023
4e50b71
h
gingershaped Nov 4, 2023
527b68f
attempt 3
gingershaped Nov 4, 2023
62d8bb5
attempt 4
gingershaped Nov 4, 2023
f82e533
attempt 5
gingershaped Nov 4, 2023
6889add
oops
gingershaped Nov 4, 2023
591ebba
oops 2
gingershaped Nov 4, 2023
1551c35
Self-forward on SE side
gingershaped Nov 4, 2023
8da659d
big brain time
gingershaped Nov 4, 2023
d5dcd13
Fix bot losing its mind because of bad chat forwarding implementation
gingershaped Nov 4, 2023
b1823ab
Stop GH embed spam in Discord
gingershaped Nov 4, 2023
dc9e017
big brain hours
gingershaped Nov 4, 2023
4e364ba
reaction fixes
gingershaped Nov 4, 2023
229267f
das webhooken
gingershaped Nov 4, 2023
130cd31
das reactionen
gingershaped Nov 4, 2023
d73ab30
reorder ifs so reactions work
gingershaped Nov 4, 2023
4e0c8a1
augh
gingershaped Nov 4, 2023
cb8cc0f
again?
gingershaped Nov 4, 2023
1a9f980
Add more guardrails
gingershaped Nov 4, 2023
ccdd238
fix order of calls
gingershaped Nov 4, 2023
0d24358
maybe this?
gingershaped Nov 4, 2023
47ad12e
markdownify
gingershaped Nov 4, 2023
d65bdcf
pretty discord formatting
gingershaped Nov 4, 2023
adc2e19
markdownify 2
gingershaped Nov 4, 2023
9531caf
image magick
gingershaped Nov 4, 2023
382f2c6
ygygygyg
gingershaped Nov 4, 2023
1cd8d40
Nuke the bridge once and for all
gingershaped Nov 27, 2023
65d4eed
fixes
gingershaped Nov 27, 2023
24e8855
mojon't
gingershaped Nov 27, 2023
2e5650a
ignore webhooks
gingershaped Nov 27, 2023
fd7bd9e
Make Bridget ignore GH notifications
gingershaped Nov 27, 2023
74c2962
Apply commit spam changes and import cleanup
gingershaped Nov 29, 2023
001d505
Source cleanup
gingershaped Nov 29, 2023
8023b47
Add !!/issue close
gingershaped Nov 29, 2023
9108981
Merge branch 'main' into discord
gingershaped Nov 29, 2023
d82dc2f
what the fuck
gingershaped Nov 30, 2023
785788e
ignored no longer
gingershaped Dec 4, 2023
ddc47f4
Merge branch 'discord' of https://github.com/Vyxal/VyxalBot2 into dis…
gingershaped Dec 4, 2023
b42e637
Merge branch 'main' into discord
gingershaped Dec 6, 2023
87fb60e
merge???
gingershaped Dec 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
782 changes: 476 additions & 306 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
Loading