This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
171 lines (154 loc) · 9.22 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
import discord
from discord.ext import commands
from mcstatus import MinecraftServer
from datetime import datetime
from datetime import date
import asyncio
import os
from dotenv import load_dotenv
import pytz
from discord_buttons_plugin import *
load_dotenv()
bot = commands.Bot(command_prefix='pog ')
buttons = ButtonsClient(bot)
server_ip = os.getenv("SERVERIP")
channel_id = os.getenv("CHANNELID")
server = MinecraftServer.lookup(server_ip) #poggerchair IP: 95.142.162.123:25565
async def request():
last_player_count = 0
while True:
tz_NY = pytz.timezone('America/New_York')
datetime_NY = datetime.now(tz_NY)
today = date.today()
status = server.status()
tosay = "\nDate: {0} Time: {1} Players: {2} Latency: {3}".format(today, datetime_NY.strftime("%H:%M:%S"), status.players.online, status.latency)
channel = bot.get_channel(int(channel_id))
if status.players.online != last_player_count:
try:
await channel.edit(topic=str("{0}/20 players online | Last Edited at {1} EST".format(status.players.online, datetime_NY.strftime("%H:%M:%S"))), reason="Automatic Edit: Player Count Changed")
last_player_count = status.players.online
except TimeoutError:
await channel.send("Channel Topic could not be changed: Timeout Error")
except:
await channel.send("An unknown error occured while trying to update the channel's topic.")
file1 = open("save.txt", "a")
file1.write(tosay)
#print("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency))
file1.close()
await asyncio.sleep(300)
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='poggerchair'))
await request()
@bot.command()
async def ping(ctx):
server = MinecraftServer.lookup(server_ip)
ping = server.ping()
await ctx.send(":ping_pong: Pong!")
await ctx.send("The server responded in {0} ms.".format(ping))
@bot.command()
async def ip(ctx):
await ctx.send("**95.142.162.123 - 1.17.1**")
await ctx.send("_Ask to be whitelisted in #poggerchair!_")
@bot.command()
async def playerCount(ctx):
server = MinecraftServer.lookup(server_ip) #poggerchair IP: 95.142.162.123:25565
status = server.status()
await ctx.send("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency))
print("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency))
@bot.command()
async def players(ctx):
server = MinecraftServer.lookup(server_ip) #poggerchair IP: 95.142.162.123:25565
status = server.status()
query = server.query()
tz_NY = pytz.timezone('America/New_York')
datetime_NY = datetime.now(tz_NY)
if status.players.online == 0:
to_say = "There is currently {0} players online.".format(status.players.online)
elif status.players.online == 1:
to_say ="There is currently {0} player online.".format(status.players.online)
else:
to_say = "There are currently {0} players online.".format(status.players.online)
embed = discord.Embed(
title = 'Poggerchair',
description = to_say,
color = discord.Color.from_rgb(255, 103, 76))
embed.set_footer(text='{0} | PogBot is a project by @SharkBaitBilly#5270'.format(datetime_NY.strftime("%H:%M:%S")))
embed.set_thumbnail(url='https://cdn.discordapp.com/attachments/876187825995919410/879860894258044948/pogbot.png')
#embed.set_author(name='Bot Template',
#icon_url='')
embed.add_field(name='Player Count', value="{0}/{1}".format(status.players.online, status.players.max), inline=True)
embed.add_field(name='Ping', value=str(status.latency) + " ms", inline=True)
if status.players.online > 0:
embed.add_field(name='Player List', value="\n ".join(query.players.names), inline=False)
embed.add_field(name='Server Version', value=query.software.version, inline=True)
await ctx.send(embed=embed)
@bot.command()
async def poggerchair(ctx):
server = MinecraftServer.lookup(server_ip) #poggerchair IP: 95.142.162.123:25565
status = server.status()
query = server.query()
tz_NY = pytz.timezone('America/New_York')
datetime_NY = datetime.now(tz_NY)
if status.players.online == 0:
to_say = "There is currently {0} players online.".format(status.players.online)
elif status.players.online == 1:
to_say ="There is currently {0} player online.".format(status.players.online)
else:
to_say = "There are currently {0} players online.".format(status.players.online)
embed = discord.Embed(
title = 'Poggerchair',
description = to_say,
color = discord.Color.from_rgb(255, 103, 76))
embed.set_footer(text='{0} | PogBot is a project by @SharkBaitBilly#5270'.format(datetime_NY.strftime("%H:%M:%S")))
embed.set_thumbnail(url='https://cdn.discordapp.com/attachments/876187825995919410/879860894258044948/pogbot.png')
#embed.set_author(name='Bot Template',
#icon_url='')
embed.add_field(name='Player Count', value="{0}/{1}".format(status.players.online, status.players.max), inline=True)
embed.add_field(name='Ping', value=str(status.latency), inline=True)
if status.players.online > 0:
embed.add_field(name='Player List', value="\n ".join(query.players.names), inline=False)
embed.add_field(name='Server Version', value=query.software.version, inline=True)
await ctx.send(embed=embed)
@bot.command()
async def charecraft(ctx):
server = MinecraftServer.lookup('charecraft.minehut.gg')
status = server.status()
tz_NY = pytz.timezone('America/New_York')
datetime_NY = datetime.now(tz_NY)
embed = discord.Embed(
title = 'charecraft',
description = "There is currently {0} player(s) online.".format(status.players.online),
color = discord.Color.from_rgb(255, 103, 76))
embed.set_footer(text='{0} | PogBot is a project by @SharkBaitBilly#5270'.format(datetime_NY.strftime("%H:%M:%S")))
embed.set_thumbnail(url='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS_TCpL190sxwuMJWpm7eM1NUYYtnFQ9SyJn-0wVdV6Dzufad-rYasqlfmWoiudvdP1o0E&usqp=CAU')
embed.add_field(name='Player Count', value="{0}/{1}".format(status.players.online, status.players.max), inline=True)
embed.add_field(name='Ping', value=status.latency, inline=True)
await ctx.send(embed=embed)
@bot.command()
async def github(ctx):
await buttons.send(
content = "**View on Github**",
channel = ctx.channel.id,
components = [
ActionRow([
Button(
label = "Github",
style = ButtonType().Link,
url="https://github.com/ajsya/PoggerchairBot"
)
])
]
)
@bot.command()
async def flag(ctx):
flag = (":purple_square::purple_square::purple_square::purple_square::purple_square::purple_square::yellow_square::white_large_square::yellow_square::purple_square::purple_square::purple_square::purple_square::purple_square::purple_square:\n:purple_square::purple_square::purple_square::purple_square::purple_square::purple_square::yellow_square::white_large_square::yellow_square::purple_square::purple_square::purple_square::purple_square::purple_square::purple_square:\n:purple_square::purple_square::purple_square::purple_square::purple_square::yellow_square::yellow_square::white_large_square::yellow_square::yellow_square::purple_square::purple_square::purple_square::purple_square::purple_square:\n:yellow_square::yellow_square::yellow_square::yellow_square::yellow_square::yellow_square::yellow_square::white_large_square::yellow_square::yellow_square::yellow_square::yellow_square::yellow_square::yellow_square::yellow_square:\n:white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::white_large_square:")
flag2 = ("\n:yellow_square::yellow_square::yellow_square::yellow_square::yellow_square::yellow_square::yellow_square::white_large_square::yellow_square::yellow_square::yellow_square::yellow_square::yellow_square::yellow_square::yellow_square:\n:purple_square::purple_square::purple_square::purple_square::purple_square::yellow_square::yellow_square::white_large_square::yellow_square::yellow_square::purple_square::purple_square::purple_square::purple_square::purple_square:\n:purple_square::purple_square::purple_square::purple_square::purple_square::purple_square::yellow_square::white_large_square::yellow_square::purple_square::purple_square::purple_square::purple_square::purple_square::purple_square:\n:purple_square::purple_square::purple_square::purple_square::purple_square::purple_square::yellow_square::white_large_square::yellow_square::purple_square::purple_square::purple_square::purple_square::purple_square::purple_square:")
await ctx.send(flag)
await ctx.send(flag2)
TOKEN = os.getenv("TOKEN")
bot.run(TOKEN)