-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
178 lines (141 loc) · 6.06 KB
/
bot.py
File metadata and controls
178 lines (141 loc) · 6.06 KB
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
import discord
import asyncio
import subprocess
import pickle
from mcstatus import MinecraftServer
commands = ["help", "ip", "version", "info", "badCommand", "Messages","server"]
totalHidden = 3;
curVersion = 0.1
MineServer = MinecraftServer.lookup("127.0.0.1:25565")
class person:
name = ""
commandsNum = []
hiddenFound = 0
version = 0
def __init__(self):
self.commandsNum = [0, 0, 0, 0, 0, 0,0]
self.hiddenFound = 0
self.version = curVersion
client = discord.Client()
people = []
cashedIp = ""
def updatePerson(pos):
global people
if people[pos].version == curVersion:
return
while len(people[pos].commandsNum) < len(commands):
people[pos].commandsNum.append(0)
people[pos].version = curVersion
def checkIfInGame(author):
count = -1
global people
for persons in people:
count += 1
if persons.name == author:
updatePerson(count)
return count
return -1
def addNewPlayer(author):
global people
player = person()
player.name = author
people.append(player)
return checkIfInGame(author)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
try:
with open('peopleSaveFile', 'rb') as fp:
global people
people = pickle.load(fp)
except IOError as e:
global people
people = []
print(str(e))
global playerPos
@client.event
async def on_message(message):
global people
try:
messageCase = message.content.lower()
playerPos = checkIfInGame(message.author.name)
if playerPos == -1:
playerPos = addNewPlayer(message.author.name)
print("Added new player : " + people[playerPos].name)
if messageCase.startswith('!ip'):
# await client.send_message(message.channel, 'Currenttly Ip dont work')
# bash = "curl ipecho.net/plain"
output = result = subprocess.run(['curl', 'ipecho.net/plain'], stdout=subprocess.PIPE)
Ip = output.stdout.decode('utf-8')
if cashedIp != Ip and cashedIp != "":
print('IP CHANGED')
await client.send_message(message.channel, 'Current Ip ' + Ip)
people[playerPos].commandsNum[1] += 1
elif messageCase.startswith('!info'):
pp = people[playerPos]
string = "Player : " + pp.name
string += " \n !help : " + str(pp.commandsNum[0])
string += " \n !ip : " + str(pp.commandsNum[1])
string += " \n !version : " + str(pp.commandsNum[2])
string += " \n !info : " + str(pp.commandsNum[3])
string += " \n !badCommand : " + str(pp.commandsNum[4])
string += " \n General Chat : " + str(pp.commandsNum[5])
string += " \n !server : " + str(pp.commandsNum[6])
string += " \n hidden Commands used : " + str(pp.hiddenFound) + " / " + str(totalHidden)
string += " \n Bot Version : " + str(curVersion)
await client.send_message(message.channel, string)
people[playerPos].commandsNum[3] += 1
elif messageCase.startswith('!help'):
await client.send_message(message.channel, 'Current Commands : \n !version \n !ip \n !info')
people[playerPos].commandsNum[0] += 1
elif messageCase.startswith('!server'):
serverCommand = messageCase.split()
string = ""
if len(serverCommand) == 1:
string = "Needs a sub command :"
string += " \n ```<players>``` to see number of players online"
string += " \n ```<playerNames>``` to see the name of players online"
string += " \n ```<online>``` to see if the server is online"
elif serverCommand[1] == "players":
try:
status = MineServer.status()
string = "The server has {0} players online".format(status.players.online)
except Exception:
string = "Server not online"
elif serverCommand[1] == "online":
try:
ping = MineServer.ping()
string = "The server has {0} ms ping to bot so prob online".format(ping)
except Exception:
string = "Server not online"
elif serverCommand[1] == "playernames":
try:
query = MineServer.query()
string = "The server has the following players online: ``` {0}".format(", ".join(query.players.names)) + " ```"
except Exception:
string = "Server not online"
else:
string = "Incorrect Sub Command do !server to see all valid"
people[playerPos].commandsNum[6] += 1
await client.send_message(message.channel,string)
elif messageCase.startswith('!version'):
version = 'Server is Currently Running ```FTB DireWolf 1.10 - Minecraft V 1.7.0``` just get a legit minecraft account'
await client.send_message(message.channel, version)
people[playerPos].commandsNum[2] += 1
elif messageCase.startswith('!'):
await client.send_message(message.channel, "Command '" + message.content + "' is not a command dum dum, see !help")
people[playerPos].commandsNum[4] += 1
if messageCase.startswith('!'):
pass
with open('peopleSaveFile', 'wb') as fp:
pickle.dump(people, fp)
people[playerPos].commandsNum[5] += 1
except Exception as e:
print('Error! ' + str(e))
# await client.send_message(message.channel, 'ERROR')
print('Generated from : ' + message.content)
tokenFile = open("token", "r")
client.run(tokenFile.read())