Skip to content

Commit

Permalink
a lot of changes (#36)
Browse files Browse the repository at this point in the history
* added mvm upload support

* removed comment

* added a lot and fixed a lot

fixed tf2m search
fixed server timeout
added host commands

* fixed typo that stopped maps from uploading

* synced another change from prod to dev

* fixed typo

* Update hdr_check.py

* Update servers.py

* qol and release
  • Loading branch information
neilstottler authored May 8, 2024
1 parent 7d601cf commit 0b55aa8
Show file tree
Hide file tree
Showing 9 changed files with 589 additions and 204 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ config.yml
*__pycache__*
*.pex
*.sqlite*
moderation.py
server.py
6 changes: 4 additions & 2 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def main():
bot.add_cog(Servers(bot))
bot.add_cog(VIP())
bot.add_cog(Misc(bot))
bot.add_cog(Verification())
bot.add_cog(Hosts())
bot.add_cog(Verification(bot))
#bot.add_cog(Hosts())
bot.add_cog(SearchUsers(bot))
bot.add_cog(Release(bot))

# Setup Asyncio Loop
bot.loop.add_signal_handler(signal.SIGINT, lambda: bot.loop.stop())
Expand Down
3 changes: 2 additions & 1 deletion cogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
from .servers import Servers
from .misc import Misc
from .verification import Verification
from .hosts import Hosts
from .hosts import Hosts
from .moderation import SearchUsers
277 changes: 167 additions & 110 deletions cogs/maplist.py

Large diffs are not rendered by default.

336 changes: 336 additions & 0 deletions cogs/release.py

Large diffs are not rendered by default.

76 changes: 75 additions & 1 deletion cogs/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 3rd Party Imports
import discord
from discord.ext.commands import Cog, slash_command, user_command
import databases

# Local Imports
from utils import load_config, cog_error_handler
Expand All @@ -16,6 +17,18 @@
class Verification(Cog):
cog_command_error = cog_error_handler

def __init__(self, bot):
self.bot = bot

@Cog.listener()
async def on_ready(self):
self.bot.add_view(MyView(self.bot))
#for starting a new embed
channel = self.bot.get_channel(global_config.verification_channel_id)
#await channel.send(f"# RECOMMENDED WAY! \n Click the button to get verified after linking your discord and steam on the forums. <https://tf2maps.net>", view=MyView(self.bot))
pass


@user_command(
name="verify",
description=config.verify.help,
Expand Down Expand Up @@ -43,4 +56,65 @@ async def verify(self, ctx, member: discord.Member):
if unverified_role in member.roles:
await member.remove_roles(unverified_role)
await member.add_roles(verified_role)
await ctx.respond(f"{member.name} is Verified now.", ephemeral=True)
await ctx.respond(f"{member.name} is Verified now.", ephemeral=True)

class MyView(discord.ui.View):
def __init__(self, bot):
self.bot = bot
super().__init__(timeout=None) # timeout of the view must be set to None

@discord.ui.button(label="Verify Me!", custom_id="button-1", style=discord.ButtonStyle.primary)
async def button_callback(self, button, interaction):

database = databases.Database(global_config.databases.tf2maps_site)
await database.connect()

#reference discord ID for user
query = "SELECT user_id FROM xf_user_connected_account WHERE provider_key = :field_value"
values = {"field_value": interaction.user.id}
discord_id = interaction.user.id
result = await database.fetch_one(query=query, values=values)

if(result != None):
#get steam id
forum_id = result[0]
query = "SELECT provider_key FROM xf_user_connected_account WHERE provider = 'th_cap_steam' AND user_id = :user_id"
values = {"user_id": forum_id}
result = await database.fetch_one(query=query, values=values)
#if steam id present
if(result != None):
steam_id = result[0].decode("utf-8")

#roles
unverified_role = discord.utils.get(interaction.guild.roles, name="Unverified")
verified_role = discord.utils.get(interaction.guild.roles, name="Verified")

if unverified_role in interaction.user.roles:
await interaction.user.remove_roles(unverified_role)
await interaction.user.add_roles(verified_role)

# send DM?
await interaction.response.send_message("Welcome to TF2Maps! Check your DM for more info!", ephemeral=True)
user = await interaction.client.fetch_user(interaction.user.id)
try:
await user.send("Welcome to TF2Maps!")
#if it errors our for some reason
except:
pass

#verification log
channel = self.bot.get_channel(global_config.verification_log_channel_id)

#embed
embed = discord.Embed(description=f"")
embed.set_author(name=f"Verification", icon_url="https://cdn.discordapp.com/emojis/829026378078224435.png?v=1")
embed.add_field(name=f"TF2M Profile", value=f"https://tf2maps.net/members/{forum_id}", inline=False)
embed.add_field(name=f"Steam Profile", value=f"https://steamcommunity.com/profiles/{steam_id}", inline=False)
embed.add_field(name=f"Discord Profile", value=f"<@{discord_id}>", inline=False)
embed.set_footer(text=global_config.bot_footer)
await channel.send(embed=embed)

else:
await interaction.response.send_message("You do not have steam linked! https://tf2maps.net/account/connected-accounts/", ephemeral=True)
else:
await interaction.response.send_message("No forum account was found. Please check your connected accounts https://tf2maps.net/account/connected-accounts/", ephemeral=True)
89 changes: 0 additions & 89 deletions server.py

This file was deleted.

3 changes: 2 additions & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
from .search import search_with_bing, search_downloads, get_srcds_server_info
from .misc import get_random_password, wait_for_tcp, readable_time
from .timehash import Timehash
from .hdr_check import bsp_validate_hdr
from .hdr_check import bsp_validate_hdr
from .moderation import *
1 change: 1 addition & 0 deletions utils/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async def search_with_bing(site, term, exclude=[]):
response = await client.get(search_query)

soup = BeautifulSoup(response.text, 'html.parser')
print(response)
#old: ol#b_results > li.b_algo > h2 > a
#new: ol#b_results > li.b_algo h2 > a
#new titles only: ol#b_results > li.b_algo .b_title > h2 > a
Expand Down

0 comments on commit 0b55aa8

Please sign in to comment.