-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.py
231 lines (201 loc) · 7.37 KB
/
Bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# main.py
import discord
import openai
import random
import requests
import json
from discord.ext import commands
import os
from config import TOKEN
openai.api_key = 'OPENAI_KEY'
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='/-', intents=intents)
# generate response using ChatGPT API
async def generate_response(message):
completion = openai.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": message.content,
},
],
)
return completion.choices[0].message.content
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user:
return
# Generate response using ChatGPT API
response = await generate_response(message)
# Send the response back to the Discord channel
await message.channel.send(response)
# Command: hello
@client.command()
async def hello(ctx):
await ctx.send("whass poppin")
# Command: pj
@client.command()
async def pj(ctx):
jokeurl = "https://joke3.p.rapidapi.com/v1/joke"
payload = {"content": "A joke here", "nsfw": "true"}
headers = {
"content-type": "application/json",
"X-RapidAPI-Key": "YOUR_RAPIDAPI_KEY",
"X-RapidAPI-Host": "joke3.p.rapidapi.com"
}
response = requests.post(jokeurl, json=payload, headers=headers)
data = json.loads(response.text)
await ctx.send(data['content'])
# Command: cut
@client.command()
async def cut(ctx):
await ctx.send("catch you later homie")
# Command: join
@client.command(pass_context=True)
async def join(ctx):
if ctx.author.voice:
channel = ctx.message.author.voice.channel
await channel.connect()
else:
await ctx.send("pull up to vc cuh")
# Command: leave
@client.command(pass_context=True)
async def leave(ctx):
if ctx.voice_client:
await ctx.guild.voice_client.disconnect()
await ctx.send("dipped from vc")
else:
await ctx.send("not in vc")
# Command: doggo
@client.command()
async def doggo(ctx):
embed = discord.Embed(title="doggo", url="https://www.google.com/search?q=dog&sxsrf=AOaemvIEUwO7gqX3EbnFLZ0CgRvNF9QCyQ:1638285894412&source=lnms&tbm=isch&sa=X&ved=2ahUKEwip5OP7xb_0AhVnxzgGHSkhBSgQ_AUoAXoECAEQAw&biw=1366&bih=657", description="bro da dawg", color=0x4dff4d)
embed.set_author(name="aura", url="", icon_url="https://images.app.goo.gl/vgsxAuKpaMEEVQc89")
embed.set_thumbnail(url="https://www.google.com/search?q=dog&sxsrf=AOaemvIEUwO7gqX3EbnFLZ0CgRvNF9QCyQ:1638285894412&source=lnms&tbm=isch&sa=X&ved=2ahUKEwip5OP7xb_0AhVnxzgGHSkhBSgQ_AUoAXoECAEQAw&biw=1366&bih=657")
await ctx.send(embed=embed)
# Command: rps
@client.command()
async def rps(ctx, user_choice):
choices = ["rock", "paper", "scissors"]
if user_choice.lower() not in choices:
await ctx.send("Invalid choice! Choose either rock, paper, or scissors.")
return
bot_choice = random.choice(choices)
winner = determine_winner(choices.index(user_choice.lower()), choices.index(bot_choice))
await ctx.send(f"I chose {bot_choice}. {winner}")
def determine_winner(user_choice_index, bot_choice_index):
if user_choice_index == bot_choice_index:
return "It's a tie!"
elif (user_choice_index - bot_choice_index) % 3 == 1:
return "You win!"
else:
return "I win!"
# Command: ban
@client.command()
async def ban(ctx, member: discord.Member):
if ctx.author.guild_permissions.administrator:
await member.ban()
await ctx.send(f"{member.mention} has been banned.")
else:
await ctx.send("You do not have permission to use this command.")
# Command: serverpeeps
@client.command()
async def serverpeeps(ctx):
member_count = ctx.guild.member_count
await ctx.send(f"The server has {member_count} members!")
# Command: mute
@client.command()
async def mute(ctx, member: discord.Member):
if ctx.author.guild_permissions.administrator:
voice_state = member.voice
if voice_state:
await member.edit(mute=True)
await ctx.send(f"{member.mention} has been muted.")
else:
await ctx.send(f"{member.mention} is not in a voice channel.")
else:
await ctx.send("This command is for admins only.")
# Command descriptions
command_descriptions = {
"hello": "Says hello!",
"pj": "Tells a joke.",
"cut": "Says goodbye.",
"join": "Joins the voice channel.",
"leave": "Leaves the voice channel.",
"doggo": "Sends a doggo image.",
"rps": "Plays Rock Paper Scissors.",
"ban": "Bans a member.",
"serverpeeps": "Displays the member count of the server.",
"mute" : "Mutes a member in voice chat."
}
# Command to display help
@client.command()
async def show_help(ctx):
embed = discord.Embed(title="Command List", description="BOT COMMANDS AVAILABLE!!!!!")
for command, description in command_descriptions.items():
embed.add_field(name=f"/-{command}", value=description, inline=False)
await ctx.send(embed=embed)
class TicTacToe:
def __init__(self):
self.board = [[' ' for _ in range(3)] for _ in range(3)]
self.current_player = 'X'
def print_board(self):
board_str = '\n'.join([' | '.join(row) for row in self.board])
return f'```\n{board_str}\n```'
def make_move(self, row, col):
if self.board[row][col] == ' ':
self.board[row][col] = self.current_player
self.current_player = 'O' if self.current_player == 'X' else 'X'
return True
return False
def check_winner(self):
for i in range(3):
if self.board[i][0] == self.board[i][1] == self.board[i][2] != ' ':
return True
if self.board[0][i] == self.board[1][i] == self.board[2][i] != ' ':
return True
if self.board[0][0] == self.board[1][1] == self.board[2][2] != ' ':
return True
if self.board[0][2] == self.board[1][1] == self.board[2][0] != ' ':
return True
return False
game = None
@client.command()
async def tictac(ctx):
global game
if game is None:
game = TicTacToe()
await ctx.send("Tic Tac Toe game started!\n" + game.print_board())
else:
await ctx.send("A Tic Tac Toe game is already in progress.")
# Command to make a move in Tic Tac Toe game
@client.command()
async def move(ctx, row: int, col: int):
global game
if game is None:
await ctx.send("No Tic Tac Toe game in progress. Use `/-tictac` to start a new game.")
return
if row < 0 or row > 2 or col < 0 or col > 2:
await ctx.send("Invalid move! Please enter row and column indices between 0 and 2.")
return
if game.make_move(row, col):
await ctx.send(f"Move made by player {game.current_player}:\n{game.print_board()}")
if game.check_winner():
await ctx.send(f"Player {game.current_player} wins!")
game = None
else:
await ctx.send("Invalid move! That position is already taken.")
# Command to display the current Tic Tac Toe board
@client.command()
async def board(ctx):
global game
if game is None:
await ctx.send("No Tic Tac Toe game in progress. Use `/-tictac` to start a new game.")
return
await ctx.send(game.print_board())
client.run(TOKEN)