Skip to content

Commit dedbc40

Browse files
authored
Merge pull request #10 from r-liner/r-liner-patch-0.7.5-1
v0.7.5
2 parents 6fe1d51 + 7c65b6e commit dedbc40

File tree

4 files changed

+195
-39
lines changed

4 files changed

+195
-39
lines changed

main.py

+71-35
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import nextcord
22
import nextcord.errors
3-
from nextcord.ext import commands, tasks
3+
from nextcord.ext import commands, application_checks
44
import os
5-
from itertools import cycle
65
import sys
76
import configparser
87

@@ -11,79 +10,116 @@
1110

1211
config = configparser.ConfigParser()
1312
config.read("config.ini")
14-
15-
if sys.version_info < (3, 8):
16-
exit("You need Python 3.8+ to run the bot.")
17-
18-
try:
19-
from nextcord import Intents, Client
20-
21-
except ImportError:
22-
exit("Nextcord isn`t installed or it`s old, unsupported version.")
13+
admin_guild = int(config['settings']['admin_guild'])
2314

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

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

33-
# загрузка когов
25+
26+
@client.event
27+
async def on_disconnect():
28+
if client.is_closed():
29+
await client.connect()
30+
31+
32+
# WORKING WITH COGS
3433

3534

36-
@client.command()
37-
@commands.is_owner()
38-
async def load(ctx, extension):
35+
@application_checks.is_owner()
36+
@client.slash_command(guild_ids=(admin_guild,))
37+
async def load(interaction, extension):
38+
"""
39+
Loading extension
40+
41+
Parameters
42+
----------
43+
interaction: Interaction
44+
extension: str
45+
Type name of extension to load.
46+
"""
3947
try:
4048
client.load_extension(f"cogs.{extension}")
4149
print(f"Cog {extension} is loaded.")
42-
await ctx.send(f"Cog **{str.upper(extension)}** is loaded.")
50+
await interaction.send(f"Cog **{str.upper(extension)}** is loaded.")
4351

4452
except Exception as error:
4553
print(error)
46-
await ctx.send("Incorrect name or not able to load")
54+
await interaction.send("Incorrect name or not able to load")
55+
4756

57+
@application_checks.is_owner()
58+
@client.slash_command(guild_ids=(admin_guild,))
59+
async def unload(interaction, extension):
60+
"""
61+
Unloading extension
4862
49-
@client.command()
50-
@commands.is_owner()
51-
async def unload(ctx, extension):
63+
Parameters
64+
----------
65+
interaction: Interaction
66+
extension: str
67+
Type name of extension to unload.
68+
"""
5269
try:
5370
client.unload_extension(f"cogs.{extension}")
5471
print(f"Cog {str.upper(extension)} is unloaded.")
55-
await ctx.send(f"Cog **{str.upper(extension)}** is unloaded.")
72+
await interaction.send(f"Cog **{str.upper(extension)}** is unloaded.")
5673

5774
except Exception as error:
5875
print(error)
59-
await ctx.send("Incorrect name or not able to unload")
76+
await interaction.send("Incorrect name or not able to unload")
6077

6178

62-
@client.command()
63-
@commands.is_owner()
64-
async def reload(ctx, extension):
79+
@application_checks.is_owner()
80+
@client.slash_command(guild_ids=(admin_guild,))
81+
async def reload(interaction, extension):
82+
"""
83+
Reloading extension
84+
85+
Parameters
86+
----------
87+
interaction: Interaction
88+
extension: str
89+
Type name of extension to reload.
90+
"""
6591
try:
6692
client.unload_extension(f"cogs.{extension}")
6793
client.load_extension(f"cogs.{extension}")
6894
print(f"Cog {str.upper(extension)} is reloaded.")
69-
await ctx.send(f"Cog **{str.upper(extension)}** is reloaded.")
95+
await interaction.send(f"Cog **{str.upper(extension)}** is reloaded.")
7096

7197
except Exception as error:
7298
print(error)
73-
await ctx.send("Incorrect name or not able to reload")
99+
await interaction.send("Incorrect name or not able to reload")
74100

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

79-
try:
80-
client.run(config["bot"]["token"])
105+
if __name__ == '__main__':
106+
if sys.version_info < (3, 8):
107+
exit("You need Python 3.8+ to run the bot.")
108+
109+
try:
110+
from nextcord import Intents, Client
111+
112+
except ImportError:
113+
exit("Nextcord isn`t installed or it`s old, unsupported version.")
114+
115+
try:
116+
client.run(config["bot"]["token"])
81117

82-
except Exception as err:
83-
print(err)
118+
except Exception as err:
119+
print(err)
84120

85-
except nextcord.PrivilegedIntentsRequired:
86-
exit("Login failure! Privileged Intents not enabled.")
121+
except nextcord.PrivilegedIntentsRequired:
122+
exit("Login failure! Privileged Intents not enabled.")
87123

88-
except nextcord.errors.LoginFailure:
89-
exit("Login failure! Token is required.")
124+
except nextcord.errors.LoginFailure:
125+
exit("Login failure! Token is required.")

setup.py

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import configparser
2+
from shutil import copy
3+
4+
print("""## Welcome to bot setup ##
5+
6+
If you have additional questions type 'help' on each of answers.
7+
If you wanna abort the setting up just close the program.
8+
Please make sure that you will input the right data.
9+
""")
10+
11+
while True:
12+
token = input('Please enter your token here: ')
13+
14+
if token.lower() == 'help':
15+
print("""Open the discord developer portal, create your application and copy your token.
16+
https://discord.com/developers/applications""")
17+
18+
elif token == '':
19+
continue
20+
21+
else:
22+
break
23+
24+
while True:
25+
owner_id = input('\nPlease enter your discord id: ')
26+
27+
if owner_id.lower() == 'help':
28+
print("""Turn on developer mode in discord app settings. Then copy your id in the profile.
29+
It will need for some commands.""")
30+
31+
elif owner_id == '':
32+
continue
33+
34+
else:
35+
break
36+
37+
while True:
38+
prefix = input('\nPlease enter bot prefix: ')
39+
40+
if prefix.lower() == 'help':
41+
print("""Prefix will be used for some ctx commands.""")
42+
43+
elif prefix == '':
44+
continue
45+
46+
else:
47+
break
48+
49+
while True:
50+
admin_guild = input('\nPlease enter admin guild id: ')
51+
52+
if admin_guild.lower() == 'help':
53+
print("""Admin guild id used for some commands.""")
54+
55+
elif admin_guild == '':
56+
continue
57+
58+
else:
59+
break
60+
61+
while True:
62+
openweather_token = input('\nPlease enter openweather token (type "skip" for skip): ')
63+
64+
if openweather_token.lower() == 'help':
65+
print("""Open https://openweathermap.org/ then login. Create token, copy and paste there.""")
66+
67+
elif openweather_token.lower() == 'skip':
68+
break
69+
70+
elif openweather_token == '':
71+
continue
72+
73+
else:
74+
break
75+
76+
while True:
77+
is_save = input('\nSave settings? (Yes/No): ')
78+
79+
if is_save.lower() == 'yes':
80+
break
81+
82+
elif is_save.lower() == 'no':
83+
exit('\nOkay. Try again.')
84+
85+
else:
86+
continue
87+
88+
copy('config.ini.sample', 'config.ini')
89+
90+
config = configparser.ConfigParser()
91+
config.read('config.ini')
92+
93+
94+
config['bot']['token'] = token
95+
config['bot']['owner_id'] = owner_id
96+
config['bot']['prefix'] = prefix
97+
98+
config['settings']['admin_guild'] = admin_guild
99+
100+
config['weather']['openweather_token'] = '' if openweather_token == 'skip' else openweather_token
101+
102+
with open('config.ini', 'w') as f:
103+
config.write(f)
104+
105+
print('\nDone. Now you can run the bot.')

start_win.bat

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
@echo off
2-
title discord-bot-ru
2+
title DISCORD BOT
33

44
cls
55

6+
if not exist config.ini (
7+
goto setup
8+
)
9+
610
>nul 2>nul assoc .py
711
if errorlevel 1 (
812
goto install_python
@@ -12,10 +16,10 @@ if errorlevel 1 (
1216

1317
:install_python
1418
cls
15-
echo You must download Python ver 3.8 or newer!
19+
echo You must install Python 3.8 or above!
1620
echo Install Python and try again.
1721
echo.
18-
echo If Python has installed, reinstall and add it to PATH via "Add Python to PATH" during installation
22+
echo If python already installed, reinstall and add it to PATH via "Add Python to PATH" during installation
1923
start https://www.python.org/downloads/
2024
echo.
2125

@@ -27,3 +31,14 @@ py main.py
2731

2832
pause
2933
exit
34+
35+
:setup
36+
cls
37+
38+
echo You must setup the bot firstly
39+
echo.
40+
41+
py setup.py
42+
43+
pause
44+
exit

version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.4
1+
0.7.5

0 commit comments

Comments
 (0)