Compare commits
3
Commits
00c8227b8e
..
v1.4.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ff13453be | ||
|
|
6b29e26140 | ||
|
|
bbcb4e4dff |
@@ -13,7 +13,6 @@ COPY config.py config.py
|
|||||||
COPY main.py main.py
|
COPY main.py main.py
|
||||||
COPY utils.py utils.py
|
COPY utils.py utils.py
|
||||||
|
|
||||||
COPY bot_messages bot_messages/
|
|
||||||
COPY classes classes/
|
COPY classes classes/
|
||||||
COPY cogs cogs/
|
COPY cogs cogs/
|
||||||
COPY database_setup database_setup/
|
COPY database_setup database_setup/
|
||||||
|
|||||||
@@ -1,195 +0,0 @@
|
|||||||
# generated by datamodel-codegen:
|
|
||||||
# filename: gitea_webhook.json
|
|
||||||
# timestamp: 2024-05-16T21:15:27+00:00
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
|
|
||||||
class Author(BaseModel):
|
|
||||||
name: str
|
|
||||||
email: str
|
|
||||||
username: str
|
|
||||||
|
|
||||||
|
|
||||||
class Committer(BaseModel):
|
|
||||||
name: str
|
|
||||||
email: str
|
|
||||||
username: str
|
|
||||||
|
|
||||||
|
|
||||||
class Commit(BaseModel):
|
|
||||||
id: str
|
|
||||||
message: str
|
|
||||||
url: str
|
|
||||||
author: Author
|
|
||||||
committer: Committer
|
|
||||||
verification: None
|
|
||||||
timestamp: str
|
|
||||||
added: List[str]
|
|
||||||
removed: List[str]
|
|
||||||
modified: List[str]
|
|
||||||
|
|
||||||
|
|
||||||
class HeadCommit(BaseModel):
|
|
||||||
id: str
|
|
||||||
message: str
|
|
||||||
url: str
|
|
||||||
author: Author
|
|
||||||
committer: Committer
|
|
||||||
verification: None
|
|
||||||
timestamp: str
|
|
||||||
added: List[str]
|
|
||||||
removed: List[str]
|
|
||||||
modified: List[str]
|
|
||||||
|
|
||||||
|
|
||||||
class Owner(BaseModel):
|
|
||||||
id: int
|
|
||||||
login: str
|
|
||||||
login_name: str
|
|
||||||
full_name: str
|
|
||||||
email: str
|
|
||||||
avatar_url: str
|
|
||||||
language: str
|
|
||||||
is_admin: bool
|
|
||||||
last_login: str
|
|
||||||
created: str
|
|
||||||
restricted: bool
|
|
||||||
active: bool
|
|
||||||
prohibit_login: bool
|
|
||||||
location: str
|
|
||||||
website: str
|
|
||||||
description: str
|
|
||||||
visibility: str
|
|
||||||
followers_count: int
|
|
||||||
following_count: int
|
|
||||||
starred_repos_count: int
|
|
||||||
username: str
|
|
||||||
|
|
||||||
|
|
||||||
class Permissions(BaseModel):
|
|
||||||
admin: bool
|
|
||||||
push: bool
|
|
||||||
pull: bool
|
|
||||||
|
|
||||||
|
|
||||||
class Repository(BaseModel):
|
|
||||||
id: int
|
|
||||||
owner: Owner
|
|
||||||
name: str
|
|
||||||
full_name: str
|
|
||||||
description: str
|
|
||||||
empty: bool
|
|
||||||
private: bool
|
|
||||||
fork: bool
|
|
||||||
template: bool
|
|
||||||
parent: None
|
|
||||||
mirror: bool
|
|
||||||
size: int
|
|
||||||
language: str
|
|
||||||
languages_url: str
|
|
||||||
html_url: str
|
|
||||||
url: str
|
|
||||||
link: str
|
|
||||||
ssh_url: str
|
|
||||||
clone_url: str
|
|
||||||
original_url: str
|
|
||||||
website: str
|
|
||||||
stars_count: int
|
|
||||||
forks_count: int
|
|
||||||
watchers_count: int
|
|
||||||
open_issues_count: int
|
|
||||||
open_pr_counter: int
|
|
||||||
release_counter: int
|
|
||||||
default_branch: str
|
|
||||||
archived: bool
|
|
||||||
created_at: str
|
|
||||||
updated_at: str
|
|
||||||
archived_at: str
|
|
||||||
permissions: Permissions
|
|
||||||
has_issues: bool
|
|
||||||
has_wiki: bool
|
|
||||||
has_pull_requests: bool
|
|
||||||
has_projects: bool
|
|
||||||
has_releases: bool
|
|
||||||
has_packages: bool
|
|
||||||
has_actions: bool
|
|
||||||
ignore_whitespace_conflicts: bool
|
|
||||||
allow_merge_commits: bool
|
|
||||||
allow_rebase: bool
|
|
||||||
allow_rebase_explicit: bool
|
|
||||||
allow_squash_merge: bool
|
|
||||||
allow_rebase_update: bool
|
|
||||||
default_delete_branch_after_merge: bool
|
|
||||||
default_merge_style: str
|
|
||||||
default_allow_maintainer_edit: bool
|
|
||||||
avatar_url: str
|
|
||||||
internal: bool
|
|
||||||
mirror_interval: str
|
|
||||||
mirror_updated: str
|
|
||||||
repo_transfer: None
|
|
||||||
|
|
||||||
|
|
||||||
class Pusher(BaseModel):
|
|
||||||
id: int
|
|
||||||
login: str
|
|
||||||
login_name: str
|
|
||||||
full_name: str
|
|
||||||
email: str
|
|
||||||
avatar_url: str
|
|
||||||
language: str
|
|
||||||
is_admin: bool
|
|
||||||
last_login: str
|
|
||||||
created: str
|
|
||||||
restricted: bool
|
|
||||||
active: bool
|
|
||||||
prohibit_login: bool
|
|
||||||
location: str
|
|
||||||
website: str
|
|
||||||
description: str
|
|
||||||
visibility: str
|
|
||||||
followers_count: int
|
|
||||||
following_count: int
|
|
||||||
starred_repos_count: int
|
|
||||||
username: str
|
|
||||||
|
|
||||||
|
|
||||||
class Sender(BaseModel):
|
|
||||||
id: int
|
|
||||||
login: str
|
|
||||||
login_name: str
|
|
||||||
full_name: str
|
|
||||||
email: str
|
|
||||||
avatar_url: str
|
|
||||||
language: str
|
|
||||||
is_admin: bool
|
|
||||||
last_login: str
|
|
||||||
created: str
|
|
||||||
restricted: bool
|
|
||||||
active: bool
|
|
||||||
prohibit_login: bool
|
|
||||||
location: str
|
|
||||||
website: str
|
|
||||||
description: str
|
|
||||||
visibility: str
|
|
||||||
followers_count: int
|
|
||||||
following_count: int
|
|
||||||
starred_repos_count: int
|
|
||||||
username: str
|
|
||||||
|
|
||||||
|
|
||||||
class GiteaWebhook(BaseModel):
|
|
||||||
ref: str
|
|
||||||
before: str
|
|
||||||
after: str
|
|
||||||
compare_url: str
|
|
||||||
commits: List[Commit]
|
|
||||||
total_commits: int
|
|
||||||
head_commit: HeadCommit
|
|
||||||
repository: Repository
|
|
||||||
pusher: Pusher
|
|
||||||
sender: Sender
|
|
||||||
@@ -10,9 +10,8 @@ from fastapi import FastAPI
|
|||||||
from git import Repo
|
from git import Repo
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from classes.gitea_webhook import GiteaWebhook
|
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
from utils import REPO_DIR, edit_clan_council_info, update_clan_messages
|
from utils import REPO_DIR, update_clan_messages
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git"
|
REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git"
|
||||||
@@ -39,38 +38,16 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
|
|||||||
server = uvicorn.Server(config)
|
server = uvicorn.Server(config)
|
||||||
await server.serve()
|
await server.serve()
|
||||||
|
|
||||||
async def update_messages(self, hook_info: GiteaWebhook):
|
async def update_messages(self):
|
||||||
"""
|
"""
|
||||||
Pulls from git and then calls method to update all the discord messages as described by the
|
Pulls from git and then calls method to update all the discord messages as described by the
|
||||||
files in the git repo.
|
files in the git repo.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Get all modified/added files
|
|
||||||
modified_files: list[str] = [
|
|
||||||
file
|
|
||||||
for list in [commit.modified + commit.added for commit in hook_info.commits]
|
|
||||||
for file in list
|
|
||||||
]
|
|
||||||
|
|
||||||
template_updates = {
|
|
||||||
file.split("/")[1] for file in modified_files if "message_templates" in file
|
|
||||||
}
|
|
||||||
channel_updates = {
|
|
||||||
file.split("/")[1]
|
|
||||||
for file in modified_files
|
|
||||||
if file.split("/")[1] not in template_updates
|
|
||||||
}
|
|
||||||
|
|
||||||
self.origin.pull()
|
self.origin.pull()
|
||||||
guild: nextcord.Guild = self.bot.get_guild(self.config.params.guild_id)
|
guild: nextcord.Guild = self.bot.get_guild(self.config.params.guild_id)
|
||||||
|
|
||||||
await update_clan_messages(guild, channel_updates)
|
await update_clan_messages(guild)
|
||||||
|
|
||||||
# if the council members template has changed, update the message
|
|
||||||
if "council_members.txt" in template_updates:
|
|
||||||
await edit_clan_council_info(
|
|
||||||
self.bot.get_guild(self.config.params.guild_id), self.config
|
|
||||||
)
|
|
||||||
|
|
||||||
return {"message": "Successfully updated all discord messages."}
|
return {"message": "Successfully updated all discord messages."}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,10 @@
|
|||||||
Contained commands and views for refresh commands.
|
Contained commands and views for refresh commands.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from utils import MESSAGES_DIR, edit_clan_council_info, update_clan_messages
|
from utils import edit_clan_council_info, update_clan_messages
|
||||||
|
|
||||||
|
|
||||||
class RefreshCog(commands.Cog, name="Refresh Commands"):
|
class RefreshCog(commands.Cog, name="Refresh Commands"):
|
||||||
@@ -31,33 +29,15 @@ class RefreshCog(commands.Cog, name="Refresh Commands"):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@refresh.subcommand(description="Force refresh all of the bot managed messages.")
|
@refresh.subcommand(description="Force refresh all of the bot managed messages.")
|
||||||
async def messages(
|
async def messages(self, interaction: nextcord.Interaction):
|
||||||
self,
|
|
||||||
interaction: nextcord.Interaction,
|
|
||||||
channel: nextcord.TextChannel = nextcord.SlashOption(
|
|
||||||
description="Channel to refresh messages in.",
|
|
||||||
required=False,
|
|
||||||
),
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Calls update_clan_messages() to update all messages.
|
Calls update_clan_messages() to update all messages.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction with the command.
|
interaction (nextcord.Interaction): Interaction with the command.
|
||||||
channel (nextcord.TextChannel): channel to refresh messages in.
|
|
||||||
"""
|
"""
|
||||||
await interaction.response.defer(ephemeral=True)
|
await interaction.response.defer(ephemeral=True)
|
||||||
|
await update_clan_messages(interaction.guild)
|
||||||
if channel is None:
|
|
||||||
channel_updates = [
|
|
||||||
dir_name
|
|
||||||
for dir_name in os.listdir(MESSAGES_DIR)
|
|
||||||
if os.path.isdir(f"{MESSAGES_DIR}/{dir_name}")
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
channel_updates = [channel.name]
|
|
||||||
|
|
||||||
await update_clan_messages(interaction.guild, channel_updates)
|
|
||||||
await interaction.followup.send("Messages have been refreshed.", ephemeral=True)
|
await interaction.followup.send("Messages have been refreshed.", ephemeral=True)
|
||||||
|
|
||||||
@refresh.subcommand(description="Updates the current council info message.")
|
@refresh.subcommand(description="Updates the current council info message.")
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ File contains util functions.
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Iterable
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from sqlalchemy import select, true, update
|
from sqlalchemy import select, true, update
|
||||||
@@ -396,7 +395,7 @@ def record_event_host(config: DakinyConfig, user: int):
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
async def update_clan_messages(guild: nextcord.Guild, channel_updates: Iterable[str]):
|
async def update_clan_messages(guild: nextcord.Guild):
|
||||||
"""
|
"""
|
||||||
Updates all clan messages to contents in MESSAGES_DIR.
|
Updates all clan messages to contents in MESSAGES_DIR.
|
||||||
Does not to any git work. Is expected to be called after git is pulled.
|
Does not to any git work. Is expected to be called after git is pulled.
|
||||||
@@ -412,7 +411,7 @@ async def update_clan_messages(guild: nextcord.Guild, channel_updates: Iterable[
|
|||||||
|
|
||||||
dirs = [
|
dirs = [
|
||||||
dir_name
|
dir_name
|
||||||
for dir_name in channel_updates
|
for dir_name in os.listdir(MESSAGES_DIR)
|
||||||
if os.path.isdir(f"{MESSAGES_DIR}/{dir_name}")
|
if os.path.isdir(f"{MESSAGES_DIR}/{dir_name}")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user