Init commit
This commit is contained in:
		
							
								
								
									
										53
									
								
								api.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								api.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					import requests as r
 | 
				
			||||||
 | 
					import conf
 | 
				
			||||||
 | 
					import bs4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					apiver=0.01
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					urls={}
 | 
				
			||||||
 | 
					urls['base']='https://us-moe-app.amz-aws.jp'
 | 
				
			||||||
 | 
					urls['refresh']='login.php'
 | 
				
			||||||
 | 
					urls['login']='change/check.php'
 | 
				
			||||||
 | 
					urls['loginconf']='change/conf.php'
 | 
				
			||||||
 | 
					urls['recremove']='give/del_chk.php'
 | 
				
			||||||
 | 
					urls['charstatus']='room/status.php'
 | 
				
			||||||
 | 
					urls['saralink']='friend/rand_get.php' # This doesn't work yet.
 | 
				
			||||||
 | 
					urls['item']='item/'
 | 
				
			||||||
 | 
					urls['iralink']='contact/irara_contact_conf.php'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get(url=None):
 | 
				
			||||||
 | 
						if url is not None: return r.get(f'{urls["base"]}/{urls[url]}',params={'P':conf.p}, headers={'User-Agent':uagent()})
 | 
				
			||||||
 | 
						return r.get(urls['base'],headers={'User-Agent':uagent()})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def post(url,stuff):
 | 
				
			||||||
 | 
						return r.post(f'{urls["base"]}/{urls[url]}?P={conf.p}', data=stuff, headers={'User-Agent':uagent()})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def uagent(uid=None):
 | 
				
			||||||
 | 
						if uid is None: uid=conf.uid
 | 
				
			||||||
 | 
						country='AU' # Let players spoof this, ofc.
 | 
				
			||||||
 | 
						ver=30 # Move this to config file for player to bump up at their leisure.
 | 
				
			||||||
 | 
						browse=f'MCCDV/{apiver}'
 | 
				
			||||||
 | 
						#browse="Mozilla/5.0 (Linux; Android 8.0.0; SHIFT6m Build/O00623; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/70.0.3538.110 Mobile Safari/537.36" TODO: Use this or similar for masking client
 | 
				
			||||||
 | 
						return f'{browse}/{country}/AMBITION_UA/GooglePlay/Android-/MOE_ver{ver}:{uid}'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def top():
 | 
				
			||||||
 | 
						pag=get()
 | 
				
			||||||
 | 
						stoof=pag.content.decode('utf-8')
 | 
				
			||||||
 | 
						start=stoof.index('?&P=')+4 # That needs a rewrite
 | 
				
			||||||
 | 
						end=stoof[start:].index('#')+start
 | 
				
			||||||
 | 
						conf.p=stoof[start:end]
 | 
				
			||||||
 | 
						return conf.p
 | 
				
			||||||
 | 
						# This function only really needs to return a P value (which it should actually just store in conf instead), and current login state. I suppose returning newsposts is good too, since they're there.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def login(un,pw):
 | 
				
			||||||
 | 
						pag=post('login',{'id':un,'pass':pw}) # We don't actually care about the result of this. We know exactly what comes next. Though this would be useful for error handling, I suppose.
 | 
				
			||||||
 | 
						pag2=post('loginconf',{'id':un,'pass':pw}) # We also don't care about this; if we got this far, it's guaranteed to succeed. Probably should still parse it and check, JUST IN CASE.
 | 
				
			||||||
 | 
						return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def myroom():
 | 
				
			||||||
 | 
						a=''
 | 
				
			||||||
 | 
						while 'alt="マイロイド"' not in a:
 | 
				
			||||||
 | 
							a=get('refresh').content.decode('utf-8')
 | 
				
			||||||
 | 
						b=bs4.BeautifulSoup(a)
 | 
				
			||||||
 | 
						myroidname=b.find(attrs={'class':'new_name1'}).find('div').contents[0]
 | 
				
			||||||
 | 
						myroidpic=b.find('img',attrs={'alt':'マイロイド'}).attrs['src']
 | 
				
			||||||
							
								
								
									
										26
									
								
								conf.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								conf.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					import uuid
 | 
				
			||||||
 | 
					import base64
 | 
				
			||||||
 | 
					from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
 | 
				
			||||||
 | 
					from cryptography.hazmat.primitives.padding import PKCS7
 | 
				
			||||||
 | 
					from cryptography.hazmat.backends import default_backend
 | 
				
			||||||
 | 
					backend=default_backend()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import json
 | 
				
			||||||
 | 
					with open('conf.json') as b:
 | 
				
			||||||
 | 
						conf=json.load(b)
 | 
				
			||||||
 | 
					uid=conf['uid']['prepared']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def generateuuid():
 | 
				
			||||||
 | 
						uid=uuid.uuid4()
 | 
				
			||||||
 | 
						return base64.b64encode(cipher_encode(str(uid))).decode('utf-8')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def cipher_encode(thing):
 | 
				
			||||||
 | 
						padder=PKCS7(128).padder()
 | 
				
			||||||
 | 
						thong=padder.update(thing.encode('utf-8'))
 | 
				
			||||||
 | 
						thong+=padder.finalize()
 | 
				
			||||||
 | 
						key=b'0123456789012345'
 | 
				
			||||||
 | 
						coph=Cipher(algorithms.AES(key), modes.ECB(), backend=backend)
 | 
				
			||||||
 | 
						e=coph.encryptor()
 | 
				
			||||||
 | 
						out=e.update(thong)
 | 
				
			||||||
 | 
						out+=e.finalize()
 | 
				
			||||||
 | 
						return out
 | 
				
			||||||
		Reference in New Issue
	
	Block a user