repl.it
@MinecraftMrGabe/

Plagueis bot

Python

No description

fork
loading
Files
  • main.py
  • adventure.py
  • keep_alive.py
  • Mr. MidKnight.txt
  • Spooky FreshmEn πŸ’€πŸ§ŸπŸ•·πŸ¦‡.txt
  • test_log.txt
  • Thankful FreshmEnπŸ¦ƒπŸ™πŸ½πŸ—.txt
  • TheArkMecha
  • TheArkMecha_Backup.txt
  • TheArkMecha.txt
  • user_data.txt
  • users.txt
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
import discord
import os
import string
import random
import math
client = discord.Client()


class active_user():
  def __init__(self,name,file):
    pass


def read_data(user,variable,line=0):
  data = open(user+'.txt','r')
  line = data.readline(line)
  while(line[0:len(variable)]!=variable):
    line = data.readline()
  x = line[len(variable)+3:len(line)]
  data.close()
  return x

def write_data(user,variable,replace,area='inventory'):#,line=0):
  data = open(user+'.txt','r')
  line = data.readline()
  lines = ''
  while(line[0:len(variable)]!=variable and line[0:3]!='end'):
    lines = lines+line
    line = data.readline()
  
  if line[0:3]!='end':
    lines = lines+line[0:len(variable)]
    #x = line[len(variable)+2:len(line)]
    x = ' = '+str(replace) + '\n'
    lines = lines+ x
    while(line[0:3]!='end'):
      line = data.readline()
      lines = lines+line
    data.close()
    data = open(user+'.txt','w')
    data.write(lines)
    data.close
    print(lines)
    return x
  else:
    lines = ''
    line = data.readline(1)
    print(line)
write_data('TheArkMecha','saber','plagueis')
ships = []
weapons = []
worlds = []
class world():
  def __init__(self,name,loot_max,loot_table):
    self.name = name
    self.loot_table = loot_table
    self.loot_max = loot_max
    worlds.append(self)

class trade_item():
  def __init__(self,name,prices):
    self.name = name
    self.prices = prices

sabers = {
  'training': (10,10),
  'plagueis': (100,1)
}

Jakku = world("jacku",8,['scrap','armor plates','engine parts','nav computer parts','Y-Wing engine','TIE cockpit','X-Wing cockpit','Eta-2 radiator wing','AT-AT cockpit'])

geonosis = world("geonosis",20,['scrap','armor plates','engine parts','laat wing','spha main cannon','spha legs','hellfire droid wreckage','b1 wreckage','b2 wreckage','clone armor','homing spider droid wreckage','dwarf spider droid wreckage','at-te main cannon','at-te hull','at-te legs','at-te ball turret','saber fighter tank wreckage','v-19 wreckage','y-wing wreckage','droideka wreckage','aat wreckage','sonic cannon wreckage'])

coruscant = world("coruscant",5,['scrap','bottle','credits','droid parts','rusty pipe'])

space = world("space",2,['scrap','astroid chunk'])

class weapon():
  def __init__(self,name,power,rate):
    self.name = name
    self.power = power
    self.rate = rate
    weapons.append(self)
class laser():
  def __init__(self,name,power,rate):
    self.name = name
    self.power = power
    self.rate = rate
    weapons.append(self)
class ion_cannon():
  def __init__(self,name,power,rate):
    self.name = name
    self.power = power
    self.rate = rate
    weapons.append(self)
light_laser = laser('light laser',10,3)
dual_light_laser = laser('dual light laser',8,5)
dual_heavy_laser = laser('dual heavy laser',20,4)
heavy_turbolaser = laser('heavy turbolaser',250,1.25)
turbolaser = laser("turbolaser",150,1.5)
heavy_laser = laser('heavy laser',12,3)
capital_laser = laser('laser cannons',40,1)
quad_capital_laser = laser('quad laser cannons',40,5)
heavy_capital_laser = laser('heavy laser cannons',120,1.5)
capital_ion = ion_cannon('ion cannon',10,1)
quad_heavy_turbolaser = laser('quad heavy turbolaser',250,5)
twin_heavy_turbolaser = laser('twin heavy turbolaser',250,2.5)
capital_heavy_ion_cannon = ion_cannon('heavy ion cannon',20,1.5)
capital_twin_heavy_ion_cannon = ion_cannon('heavy twin ion cannon',20,3)

omnicannon = weapon('omnicannon',25000,0.1)
class ship():
  def __init__(self,name,nickname,cost,costused,max_hp,modmax,weapons,cargo,hyperdrive_rating,mods=[]):
    self.classname = name
    self.name = nickname
    self.cost = cost#in credits
    self.used_cost = costused
    self.max_hp = max_hp
    self.mods = mods
    self.mod_slots = modmax#modification slots
    self.weapons = weapons#list containing weapon classes
    self.cargo = cargo#in m^#
    ships.append(self)

MC80 = ship('MC80 home one type star cruiser','MC80',150000000,112000000,10000,100,[],20000,1)

Sheathipede = ship("Sheathipede Class Transport Shuttle","sheathipede",16000,16000,160,6,[],30,0)

Delta7 = ship("Delta-7 Aethersprite","delta-7",180000,145000,100,7,[dual_light_laser,dual_light_laser],1,0)

Azure_Angel = ship("Modified Delta-7 Aethersprite","azure angel",0,0,250,12,[dual_heavy_laser,dual_heavy_laser],4,1)

Gravestone = ship("Gravestone Class Fleet Destroyer","gravestone",0,0,2500,25,[heavy_turbolaser,heavy_turbolaser,heavy_turbolaser,heavy_turbolaser,heavy_turbolaser,heavy_turbolaser,omnicannon],250,1)

Arwing = ship("Arwing","arwing",0,0,250,12,[dual_heavy_laser,dual_heavy_laser],2,0)

LAAT = ship("Low Altitude Assault Transport",'laat',58000,42000,400,10,[light_laser,light_laser,dual_heavy_laser,dual_heavy_laser,heavy_laser,heavy_laser],35,0)

G9 = ship("G9 Rigger- Class Light Frieghter",'G9',65000,40000,150,15,[dual_light_laser,dual_light_laser,light_laser,light_laser],70,3)

Arc170 = ship("Aggressive ReConnaissance-170 starfighter",'Arc-170',155000,120000,300,12,[heavy_laser,heavy_laser,light_laser,light_laser],4,1.5)

dreadnaught_cruiser = ship('Dreadnaught -class heavy cruiser','dreadnaught',7200000,35555000,3000,20,[capital_ion],9000,2)
for x in range(0,10):
  dreadnaught_cruiser.weapons.append(quad_capital_laser)
  dreadnaught_cruiser.weapons.append(quad_capital_laser)
  dreadnaught_cruiser.weapons.append(turbolaser)
  dreadnaught_cruiser.weapons.append(heavy_capital_laser)

def craft():
  pass


print("work")
def travel(user):
  userdata = open(user+'.txt','r+')
  

def get_profile(line,userdata):
  profile = ""
  text = userdata.readline()
  text = userdata.readline()
  lines = 0
  print("currect version")
  print(text)
  print(len(text))
  while(text!="hanger" and lines<=10):
    profile = profile+text
    lines+=1
    text = userdata.readline()
    print(text)
    print(len(text))
    print(lines)
    
  print("working1.5")
  return profile
def get_hanger(userdata):
  hanger = ""
  text = userdata.readline()
  while text[0:6]!="hanger":
    text = userdata.readline()
  text = userdata.readline()
  print("working3")
  while text[0:3]!="end":
    if text[0:4]=="name":
      hanger=hanger+"\n''"+text[5:len(text)-1]+"''"
    elif text[0:5]=="class":
      hanger=hanger+"\n"+text[6:len(text)-1]+""
    elif text[0:6]=="health":
      hanger=hanger+"\nhp = "+text[7:len(text)-1]
    elif text[0:7]=="shipend":
      hanger=hanger+"\n"
    text = userdata.readline()
  return(hanger)

loot_table = ['scrap','armor plates','engine parts','nav computer parts','Y-Wing engine','TIE cockpit','X-Wing cockpit','Eta-2 radiator wing','AT-AT cockpit']

def sqrt(x):
  return int(math.sqrt(x))

def explore(user):
  items = []
  user_file = open(user+'.txt','r+')
  inventory_start = 0
  line = user_file.readline()
  world = ''
  loot_table=[]
  print("explore is working 1")
  while line!="inventory\n":# and False:
    inventory_start+=1
    if line[4:9]=='world\n':
      world = line[11:len(line)]
  print("explore is working 2")
  for x in worlds:
    if x.name==world:
      world = x
      loot_table=x.loot_table
  print("explore is working 3")
  
  for x in range(int(x.loot_max/5),x.loot_max-int(math.sqrt(random.randint(0,x.loot_max**2-(x.loot_max/5)**2)))):
    items.append(loot_table[random.randint(0,len(loot_table)-1)])
  line = inventory_start
  text = ''
  start = False
  lines = ''
  for line in user_file:
    
    if "inventory" in line:
      start=True
    elif "garage" in line:
      start = False
    elif start:
      for item in items:
        if item in line:
          num = line[len(item)+3:len(line)]
          line = line.replace(str(num),str(int(num)+1)+'\n')
          #print(line)
          #print(line,num,str(int(num)+1))
          #print(isinstance(line,str))
    lines = lines+line
  user_file.close()
  user_file = open(user+'.txt','w')
  user_file.write(lines)
  user_file.close()
  final = ''
  for x in items:
    final = final + x +'\n'
  return final

newline = '\n'

def ship_catalog(channel):
  message = 'Ship Catalog:\n'
  for s in ships:
    message = message+s.classname+'\nnickname: '+s.name+'\nCost New: '+str(s.cost)+'   Cost Used: '+str(s.used_cost)+'\nHP: '+str(s.max_hp)+'\nMod Slots: '+str(s.mod_slots)+'\nCargo space: '+str(s.cargo)+'  m^3\nWeapon systems: '
    for w in s.weapons:
      message = message+'\n'+w.name
    message = message+'\n\n'
  return message
def buy_ship(text2,username):
  text = text2
  userfile = open(username+'.txt',"r+")
  usertext = userfile.read()
  #print(userfile.read())
  if "class "+text[7:len(text)] in usertext.lower():
    userfile.close()
    return "You already have this ship!"
    
  else:
    print('\n\n\n')
    print(usertext)
    print('\n\n\n')
    userfile.close()
    #print(userfile.read())
    text = text[7:len(text)]#.replace(' ','')
    s = 0
    print(text)
    for x in ships:
      if x.name==text or x.classname== text:
        s = x
    userfile = open(username+'.txt',"r+")
    print(userfile.read())
    
    if s==0:
      userfile.close()
      return "Invalid ship name. Check catalog for valid names"
    else:
      userfile.close()
      userfile = open(username+'.txt',"r+")
      lines = ''
      line = 0#line = userfile.readline(0)
      tries = 0
      print(username)
      print(userfile.read())
      with open(username+'.txt',"r+") as userfile:
        for line in userfile:#while linee!='end' and tries<=20:
          if line!="end":
            print(tries,line)#,userfile.readline())
            #line = userfile.readline()#tries)
            lines = lines+line#+'\n'
            tries+=1
      #print(lines)
      lines = lines+'name '+s.name+'\n'
      lines = lines+'class '+s.classname+'\n'
      lines = lines+'health '+str(s.max_hp)+'\n'
      lines = lines+'max_health '+str(s.max_hp)+'\n'
      for w in weapons:
        c = s.weapons.count(w)
        if c>0:
          lines = lines + w.name +' '+ str(c)+'\n'
      lines = lines+'shipend'+'\nend'
      print(lines)
      userfile.close()
      userfile = open(username+'.txt',"w")
      userfile.write(lines)
      userfile.close()
      return username+" bought a "+s.classname+"( not really, I just need to test this)"






s = 0
@client.event 
async def on_ready():
  print("Im in")
  print(client.user)

@client.event
async def on_message(message):
  global s
  if message.author != client.user:
    text = message.content.lower()
    print(text)
    print(message.author.id)
    if s==0:
      s = message.channel

    if text[0:4]=="test":
      await message.channel.send(message.content[::-1])
      log = open("test_log.txt","r+")
      log.write(message.content)
      log.close()
    elif text[0:2]=="pl":
      print("working")


      if text[3:7]=="help":
        await message.channel.send("I am Plagueis Bot and I don't do much yet.\n rpg commands: \n help: get this text \n profile: show your profile or create a profile if you don't have one \n ship: display information about your ship (wip)")


      
      if message.content[3:10]=="profile":
        users = open("users.txt","r+")
        userstext = users.read()
        if message.author.name+' ' in userstext:
          user_data = open(message.author.name+'.txt',"r")
          line = 0
          tries = 0
          '''
          while(line not in [message.author.name, message.author.name+'\n'] and tries<10):
            line = user_data.readline()
            tries+=1
            print(line)
          '''
          line = user_data.readline()
          if line[0:11]=="userversion" or True:
            print("working 0")
            if line[14:len(line)]=="1" or True:
              print("working1")
              await message.channel.send(message.author.name+"'s profile:\n"+get_profile(tries,user_data))
              print("working2")
              users.close()

        else:
          users.close()
          inventory = ''
          loot_table = []
          for x in worlds:
            for l in x.loot_table:
              if l not in loot_table:
                loot_table.append(l)
          for x in loot_table:
            inventory = inventory+x+' = 0\n'
          user_data = open(message.author.name+".txt","w+")
          user_data.write(message.author.name+'\n'+'userversion = 1\nsaber = training\nhealth = 100\nworld = jakku\ndestination = none\ntime started = 0\ntime ended = 0\ninventory\n'+inventory+'hanger\nend')
          user_data.close()
          users = open("users.txt",'r+')
          users.write(message.author.name+' \n')
          users.close()
          await message.channel.send(message.author.name+"'s profile has been set up")
        
      elif text[3:16]=='reset profile':
          inventory = ''
          loot_table = []
          for x in worlds:
            for l in x.loot_table:
              if l not in loot_table:
                loot_table.append(l)
          for x in loot_table:
            inventory = inventory+x+' = 0\n'
          user_data = open(message.author.name+".txt","w+")
          user_data.write(message.author.name+'\n'+'userversion = 1\nsaber = training\nhealth = 100\nworld = jakku\ndestination = none\ntime started = 0\ntime ended = 0\ninventory\n'+inventory+'hanger\nend')
          user_data.close()
          users = open("users.txt",'r+')
          users.write(message.author.name+' \n')
          users.close()
          await message.channel.send(message.author.name+"'s profile has been set up")
      elif text[3:9]=="hanger":
        await message.channel.send(message.author.name+"'s hanger\n"+get_hanger(open(message.author.name+".txt",'r')))#"no ships found")
      elif text[3:10]=="explore":
        print("still working")
        await message.channel.send(message.author.name+" found\n\n"+explore(message.author.name)+"\nwhile exploring")
        print("explore is working")
      elif text[3:15]=="ship catalog":
        await message.channel.send(ship_catalog(message.channel))
      elif text[3:6]=="buy":
        await message.channel.send(buy_ship(text,message.author.name))
      elif text[3:9]=='travel':
        pass
      elif text[3:7]=='duel':
        other = open(text[8:len(text)])

#write_data('TheArkMecha','soup',2)
          
          

token = os.environ.get("DISCORD_BOT_SECRET")
client.run(token)