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

Commit

Permalink
Merge pull request #10 from r-liner/r-liner-patch-0.7.5-1
Browse files Browse the repository at this point in the history
v0.7.5
  • Loading branch information
liner-exe authored Oct 1, 2023
2 parents 6fe1d51 + 7c65b6e commit dedbc40
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 39 deletions.
106 changes: 71 additions & 35 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import nextcord
import nextcord.errors
from nextcord.ext import commands, tasks
from nextcord.ext import commands, application_checks
import os
from itertools import cycle
import sys
import configparser

Expand All @@ -11,79 +10,116 @@

config = configparser.ConfigParser()
config.read("config.ini")

if sys.version_info < (3, 8):
exit("You need Python 3.8+ to run the bot.")

try:
from nextcord import Intents, Client

except ImportError:
exit("Nextcord isn`t installed or it`s old, unsupported version.")
admin_guild = int(config['settings']['admin_guild'])

client = commands.Bot(command_prefix=config["bot"]["prefix"], owner_id=int(config["bot"]["owner_id"]), intents=intents)
client.remove_command('help')


@client.event
async def on_ready():
await client.change_presence(activity=nextcord.Activity(type=nextcord.ActivityType.watching, name="bot status"))
print("Logged in as {0.user}.".format(client))
print("Bot is using on {0} servers!".format(len(client.guilds)))

# загрузка когов

@client.event
async def on_disconnect():
if client.is_closed():
await client.connect()


# WORKING WITH COGS


@client.command()
@commands.is_owner()
async def load(ctx, extension):
@application_checks.is_owner()
@client.slash_command(guild_ids=(admin_guild,))
async def load(interaction, extension):
"""
Loading extension
Parameters
----------
interaction: Interaction
extension: str
Type name of extension to load.
"""
try:
client.load_extension(f"cogs.{extension}")
print(f"Cog {extension} is loaded.")
await ctx.send(f"Cog **{str.upper(extension)}** is loaded.")
await interaction.send(f"Cog **{str.upper(extension)}** is loaded.")

except Exception as error:
print(error)
await ctx.send("Incorrect name or not able to load")
await interaction.send("Incorrect name or not able to load")


@application_checks.is_owner()
@client.slash_command(guild_ids=(admin_guild,))
async def unload(interaction, extension):
"""
Unloading extension
@client.command()
@commands.is_owner()
async def unload(ctx, extension):
Parameters
----------
interaction: Interaction
extension: str
Type name of extension to unload.
"""
try:
client.unload_extension(f"cogs.{extension}")
print(f"Cog {str.upper(extension)} is unloaded.")
await ctx.send(f"Cog **{str.upper(extension)}** is unloaded.")
await interaction.send(f"Cog **{str.upper(extension)}** is unloaded.")

except Exception as error:
print(error)
await ctx.send("Incorrect name or not able to unload")
await interaction.send("Incorrect name or not able to unload")


@client.command()
@commands.is_owner()
async def reload(ctx, extension):
@application_checks.is_owner()
@client.slash_command(guild_ids=(admin_guild,))
async def reload(interaction, extension):
"""
Reloading extension
Parameters
----------
interaction: Interaction
extension: str
Type name of extension to reload.
"""
try:
client.unload_extension(f"cogs.{extension}")
client.load_extension(f"cogs.{extension}")
print(f"Cog {str.upper(extension)} is reloaded.")
await ctx.send(f"Cog **{str.upper(extension)}** is reloaded.")
await interaction.send(f"Cog **{str.upper(extension)}** is reloaded.")

except Exception as error:
print(error)
await ctx.send("Incorrect name or not able to reload")
await interaction.send("Incorrect name or not able to reload")

for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
client.load_extension(f"cogs.{filename[:-3]}")

try:
client.run(config["bot"]["token"])
if __name__ == '__main__':
if sys.version_info < (3, 8):
exit("You need Python 3.8+ to run the bot.")

try:
from nextcord import Intents, Client

except ImportError:
exit("Nextcord isn`t installed or it`s old, unsupported version.")

try:
client.run(config["bot"]["token"])

except Exception as err:
print(err)
except Exception as err:
print(err)

except nextcord.PrivilegedIntentsRequired:
exit("Login failure! Privileged Intents not enabled.")
except nextcord.PrivilegedIntentsRequired:
exit("Login failure! Privileged Intents not enabled.")

except nextcord.errors.LoginFailure:
exit("Login failure! Token is required.")
except nextcord.errors.LoginFailure:
exit("Login failure! Token is required.")
105 changes: 105 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import configparser
from shutil import copy

print("""## Welcome to bot setup ##
If you have additional questions type 'help' on each of answers.
If you wanna abort the setting up just close the program.
Please make sure that you will input the right data.
""")

while True:
token = input('Please enter your token here: ')

if token.lower() == 'help':
print("""Open the discord developer portal, create your application and copy your token.
https://discord.com/developers/applications""")

elif token == '':
continue

else:
break

while True:
owner_id = input('\nPlease enter your discord id: ')

if owner_id.lower() == 'help':
print("""Turn on developer mode in discord app settings. Then copy your id in the profile.
It will need for some commands.""")

elif owner_id == '':
continue

else:
break

while True:
prefix = input('\nPlease enter bot prefix: ')

if prefix.lower() == 'help':
print("""Prefix will be used for some ctx commands.""")

elif prefix == '':
continue

else:
break

while True:
admin_guild = input('\nPlease enter admin guild id: ')

if admin_guild.lower() == 'help':
print("""Admin guild id used for some commands.""")

elif admin_guild == '':
continue

else:
break

while True:
openweather_token = input('\nPlease enter openweather token (type "skip" for skip): ')

if openweather_token.lower() == 'help':
print("""Open https://openweathermap.org/ then login. Create token, copy and paste there.""")

elif openweather_token.lower() == 'skip':
break

elif openweather_token == '':
continue

else:
break

while True:
is_save = input('\nSave settings? (Yes/No): ')

if is_save.lower() == 'yes':
break

elif is_save.lower() == 'no':
exit('\nOkay. Try again.')

else:
continue

copy('config.ini.sample', 'config.ini')

config = configparser.ConfigParser()
config.read('config.ini')


config['bot']['token'] = token
config['bot']['owner_id'] = owner_id
config['bot']['prefix'] = prefix

config['settings']['admin_guild'] = admin_guild

config['weather']['openweather_token'] = '' if openweather_token == 'skip' else openweather_token

with open('config.ini', 'w') as f:
config.write(f)

print('\nDone. Now you can run the bot.')
21 changes: 18 additions & 3 deletions start_win.bat
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
@echo off
title discord-bot-ru
title DISCORD BOT

cls

if not exist config.ini (
goto setup
)

>nul 2>nul assoc .py
if errorlevel 1 (
goto install_python
Expand All @@ -12,10 +16,10 @@ if errorlevel 1 (

:install_python
cls
echo You must download Python ver 3.8 or newer!
echo You must install Python 3.8 or above!
echo Install Python and try again.
echo.
echo If Python has installed, reinstall and add it to PATH via "Add Python to PATH" during installation
echo If python already installed, reinstall and add it to PATH via "Add Python to PATH" during installation
start https://www.python.org/downloads/
echo.

Expand All @@ -27,3 +31,14 @@ py main.py

pause
exit

:setup
cls

echo You must setup the bot firstly
echo.

py setup.py

pause
exit
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.4
0.7.5

0 comments on commit dedbc40

Please sign in to comment.