def openSession(props): """ Log in to the KoL servers. """ log = logging.getLogger() s = Session() s.login(props.userName, props.password) log.info("Logged in.") return s
def go(self): """ Actually run the bot. """ self.log('Logging in.') self.__session = Session() self.__session.login(self.username, self.password) self.__chat = ChatManager(self.__session) while True: for msg in self.__fetch_chat_messages(): if msg['type'] == 'private' and self.caps.get('sign', False): # Got a blue message! Report "KICK ME" sign status self.log('{userName} (#{userId}) sent me ' 'a blue message: "{text}"'.format(**msg)) self.__sign(msg['userId']) elif msg['type'] == 'notification:kmail': # Got a green message! self.log('{userName} (#{userId}) sent me ' 'a green message.'.format(**msg)) # Fetch it and examine it kmail = self.__get_kmail(msg['userName']) if kmail['text']: self.log('They said: "{}"'.format(kmail['text'])) if kmail['meat'] > 0: self.log('They sent {} meat.'.format(kmail['meat'])) # Look at the items they sent for item in kmail['items']: self.log('They sent {} {}.'.format( item['quantity'], item['name'] if item['quantity'] == 1 else item['plural'])) if item['id'] == 7698 and self.caps.get( 'spider', False): # Rubber spider self.__use_spider(msg['userId']) elif item['id'] == 4939 and self.caps.get( 'arrow', False): # Time's arrow self.__use_arrow(msg['userId']) # Don't keep it self.__del_kmail(kmail['id']) time.sleep(1)
def go(self): """ Actually run the bot. """ global active self.log('Logging in.') self.__session = Session() self.__session.login(self.username, self.password) self.__chat = ChatManager(self.__session) active = time.time() # Check pending kmails for kmail in self.__get_kmails(): self.__handle_kmail(kmail) while True: if time.time() - active > 3600: # Chat occasionally dies quietly. Maybe that happened. raise Exception("Inactive for too long.") for msg in self.__fetch_chat_messages(): if msg['type'] == 'private' and self.caps['sign']: # Got a blue message! Report "KICK ME" sign status self.log('{userName} (#{userId}) sent me ' 'a blue message: "{text}"'.format(**msg)) self.__sign(msg['userName'], msg['userId']) elif msg['type'] == 'notification:kmail': # Got a green message! self.log('{userName} (#{userId}) sent me ' 'a green message.'.format(**msg)) # Fetch it and examine it for kmail in self.__get_kmails(msg['userName'], 1): self.__handle_kmail(kmail) active = time.time() time.sleep(1)
# Kingdom of Loathing MallBot by KevZho (#2434890) # make sure to edit the options first on lines 15 to 27 # TODO: fix hitting the limits from kol.database import ItemDatabase from kol.Session import Session from kol.request.MallItemSearchRequest import MallItemSearchRequest from kol.request.MallItemPurchaseRequest import MallItemPurchaseRequest from kol.request.CocktailcraftingRequest import CocktailcraftingRequest from kol.request.AddItemsToStoreRequest import PutItemInStoreRequest #from kol.Error import Error as Error #import logging s = Session() # add booze terms here, make sure to use the same capitalization as in the recipe dictionary # searchTerms = ['parisian cathouse', 'prussian cathouse', 'vodka martini', 'rockin\' wagon', 'soft green echo eyedrop antidote martini', 'sangria de menthe'] searchTerms = ['soft green echo eyedrop antidote martini'] # add the ingredients as an array to the dictionary term recipe = { 'parisian cathouse': ['raspberry', 'boxed champagne'], 'prussian cathouse': ['parisian cathouse', 'magical ice cubes'], 'vodka martini': ['olive', 'bottle of vodka'], 'rockin\' wagon': ['vodka martini', 'magical ice cubes'], 'soft green echo eyedrop antidote martini': ['rockin\' wagon', 'soft green echo eyedrop antidote'], 'sangria de menthe': ['peppermint twist', 'boxed wine'] } # meat you are willing to spend in on each type booze meatLimit = 100000 # how much you want to undercut the lowest price on the market underCut = 1
def login(username, password): global _session _session = Session() _session.login(username, password)
def runTest(self): s = Session() s.login(TestData.data["userName"], TestData.data["password"]) self.assert_(s.isConnected == True) TestData.data["session"] = s