working simple bot
This commit is contained in:
parent
14ad6db788
commit
41bcfe01bc
1
.env
Normal file
1
.env
Normal file
@ -0,0 +1 @@
|
|||||||
|
DISCORD_TOKEN=MTM1NzQyNTQzNjAxNDkzNjA3NA.G_Iphl.ddfL8lYLJJs3OAyFBwi9Pn4V4Xe57ptualP_Mc
|
||||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
6
.idea/ansibleVaultSettings.xml
generated
Normal file
6
.idea/ansibleVaultSettings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="com.github.timo_reymann.ansible_vault_integration.settings.AnsibleVaultSettings">
|
||||||
|
<option name="vaultArguments" value="--vault-password-file ~/.vault_pass" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
4
.idea/misc.xml
generated
Normal file
4
.idea/misc.xml
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (tutorial-idently)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/tutorial-idently.iml" filepath="$PROJECT_DIR$/.idea/tutorial-idently.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
10
.idea/tutorial-idently.iml
generated
Normal file
10
.idea/tutorial-idently.iml
generated
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
52
main.py
Normal file
52
main.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
from typing import Final
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from discord import Intents, Client, Message
|
||||||
|
from responses import get_response
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
TOKEN: Final[str] = os.getenv('DISCORD_TOKEN')
|
||||||
|
|
||||||
|
|
||||||
|
intents: Intents = Intents.default()
|
||||||
|
intents.message_content = True # NOQA
|
||||||
|
client: Client = Client(intents=intents)
|
||||||
|
|
||||||
|
|
||||||
|
async def send_message(message: Message, user_message: str) -> None:
|
||||||
|
if not user_message:
|
||||||
|
print('(Message was empty because intents were not enabled probably)')
|
||||||
|
return
|
||||||
|
if is_private := user_message[0] == '?':
|
||||||
|
user_message = user_message[1:]
|
||||||
|
|
||||||
|
try:
|
||||||
|
response: str = get_response(user_message)
|
||||||
|
await message.author.send(response) if is_private else await message.channel.send(response)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_ready() -> None:
|
||||||
|
print(f'{client.user} is now running')
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_message(message: Message) -> None:
|
||||||
|
if message.author == client.user:
|
||||||
|
return
|
||||||
|
|
||||||
|
username: str = str(message.author)
|
||||||
|
user_message: str = message.content
|
||||||
|
channel: str = str(message.channel)
|
||||||
|
|
||||||
|
print(f'[{channel}] {username}: "{user_message}"')
|
||||||
|
await send_message(message, user_message)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
client.run(token=TOKEN)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
discord
|
||||||
|
python-dotenv
|
||||||
20
responses.py
Normal file
20
responses.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from random import choice, randint
|
||||||
|
|
||||||
|
|
||||||
|
def get_response(user_input: str) -> str:
|
||||||
|
lowered: str = user_input.lower()
|
||||||
|
|
||||||
|
if lowered == '':
|
||||||
|
return 'Gut, du bist sehr still ...'
|
||||||
|
elif 'hello' in lowered:
|
||||||
|
return 'Hello there!'
|
||||||
|
elif 'how are you' in lowered:
|
||||||
|
return 'Good, Thanks!'
|
||||||
|
elif 'bye' in lowered:
|
||||||
|
return "See you later!"
|
||||||
|
elif 'roll dice' in lowered:
|
||||||
|
return f'you rolled: {randint(1, 6)}'
|
||||||
|
else:
|
||||||
|
return choice(['I do not understand...',
|
||||||
|
'What are you talking abaout?',
|
||||||
|
'Do you mind rephrasing that?'])
|
||||||
Loading…
x
Reference in New Issue
Block a user