Files
SCNewsBot/scnewsbot/bot.py

106 lines
4.1 KiB
Python
Raw Normal View History

2023-05-07 15:58:01 -06:00
import subprocess
2023-05-07 14:00:46 -06:00
from discord.ext import commands
2024-04-11 12:55:02 -04:00
from discord.ui import Button
2023-05-07 14:00:46 -06:00
import discord
2024-04-11 12:55:02 -04:00
import datetime
2023-05-07 14:00:46 -06:00
from utils import Config
2024-04-15 16:28:51 -04:00
VERSION = "1.0.4"
2023-05-07 14:00:46 -06:00
INTENTS = discord.Intents.default()
INTENTS.message_content = True
INTENTS.members = True
class Bot(commands.Bot):
def __init__(self, config: Config, /) -> None:
super().__init__(
intents=INTENTS,
command_prefix=commands.when_mentioned_or(config.prefix),
allowed_mentions=discord.AllowedMentions(everyone=False),
case_insensitive=True,
activity=discord.Activity(
type=discord.ActivityType.watching, name="the devs..."
),
2023-05-07 14:00:46 -06:00
)
self.config = config
2023-05-07 16:02:34 -06:00
self.version = VERSION
2023-05-07 14:00:46 -06:00
async def setup_hook(self) -> None:
for extension in self.config.extensions:
await self.load_extension(extension)
2023-05-07 15:58:01 -06:00
await self.add_cog(CoreCog(self))
class CoreCog(commands.Cog, name="Core"):
def __init__(self, bot: Bot) -> None:
self.bot = bot
def _get_version(self) -> str:
return (
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
.decode("ascii")
.strip()
)
2023-09-17 21:57:16 -06:00
@commands.Cog.listener()
async def on_ready(self) -> None:
2024-04-11 12:55:02 -04:00
print("The News Bot is now ready.")
2024-04-15 16:28:51 -04:00
# channel = self.bot.get_channel(611922107345141760)
# embed=discord.Embed(title=f"The News Bot is now online!",description="Hello! Please use the below command to summon the embed editor. ```&embed create```", color=0x00FFFF)
# embed.timestamp = datetime.datetime.now()
# await channel.send(embed=embed)
2023-09-17 21:57:16 -06:00
2023-09-20 19:12:22 -06:00
@commands.Cog.listener()
async def on_message(self, message: discord.Message) -> None:
if (
message.channel.id in self.bot.config.publish_channels
and message.channel.type is discord.ChannelType.news
):
try:
await message.publish()
except discord.Forbidden:
pass
2024-03-10 00:21:05 -05:00
# @commands.Cog.listener()
# async def on_message(self, message):
# if message.channel.id == 649390966259580929 and message.author.id != 1091116499936223252:
# if message.embeds:
# for embed in message.embeds:
# reply_channel = self.bot.get_channel(611922107345141760)
# if "Patch Notes" in embed.title:
# await reply_channel.send(f"<@&159107041896562688> CIG has published new [Patch Notes](<{embed.url}>).")
# elif "Galactapedia" in embed.title:
# await reply_channel.send(f"<@&159107041896562688> CIG has published a new [Galactapedia update](<{embed.url}>).")
# elif "This Week in Star Citizen" in embed.title:
# await reply_channel.send(f"<@&159107041896562688> CIG has published a new [TWISC](<{embed.url}>).")
# elif "Monthly Report" in embed.title:
# await reply_channel.send(f"<@&159107041896562688> CIG has published a new [Monthly Report](<{embed.url}>).")
2023-05-07 15:58:01 -06:00
@commands.hybrid_command(description="Shows you some info about the bot.")
async def info(self, ctx: commands.Context) -> None:
embed = discord.Embed(
color=self.bot.config.embed_color,
2023-09-17 21:57:16 -06:00
title="Info",
2024-03-10 00:21:05 -05:00
description="The SC News Bot is a bot created for the r/starcitizen Discord server to help with writing news posts.",
2023-05-07 16:02:46 -06:00
)
2023-10-26 09:26:31 -04:00
# embed.add_field(
# name="Version", value=f"v{self.bot.version}+{self._get_version()}"
# )
2023-05-07 15:58:01 -06:00
embed.add_field(
name="Library", value=f"discord.py v{discord.__version__}", inline=False
)
2023-09-17 21:57:16 -06:00
embed.add_field(
name="Authors",
2024-04-15 16:28:51 -04:00
value=f"<@288522211164160010> and <@998070081709932654>",
2023-09-17 21:57:16 -06:00
)
2023-05-07 16:00:59 -06:00
view = discord.ui.View()
view.add_item(
discord.ui.Button(
label="Source Code",
url="https://github.com/mudkipdev/scnewsbot",
style=discord.ButtonStyle.link,
)
)
await ctx.reply(embed=embed, view=view, mention_author=False)