Esempio n. 1
0
    def work(self, message=None):
        if self.state == 0:
            job = storage.get_job_by_user_id(self.requester.id)
            if job:
                self.done = True
                return State.SKIP, Message(content=message_of(
                    'gettask', 'A', Tasks.get_name(Tasks, job.typus)),
                                           channel=self.channel)

            var = 'Aktuell gibt es folgende Dinge zu erledigen: \n' \
                + ''.join([f'[{i}] {Tasks.get_name(Tasks, task)} \n' \
                for i, task in enumerate(storage.available_tasks)])

            return State.OK, Message(content=message_of(
                'gettask', self.state, var),
                                     channel=self.channel)

        if self.state == 1:
            try:
                task_num = int(message.content[1])
                task = storage.available_tasks[task_num]
                storage.available_tasks.remove(task)
                storage.insert_new_job(self.requester.id, task, 0)
                construct_task(task, self.requester.id, self.client)
                return State.OK, Message(content=message_of(
                    'gettask', self.state, Tasks.get_name(Tasks, task)),
                                         channel=self.channel)
            except Exception as e:
                print(e)
                return State.FAILED, None
Esempio n. 2
0
    def work(self, message):
        if self.state == 0:
            parsed = self.parse_message(message)

            skeld = Message(
                content=
                'https://prod.cdn.earlygame.com/uploads/images/_imageBlock/SKELD_MAP-1.jpg?mtime=20201022122655&focal=none&tmtime=20201022132145',
                channel=self.channel)

            mirahq = Message(
                content=
                'https://prod.cdn.earlygame.com/uploads/images/_imageBlock/3900598/Mirahq.jpg?mtime=20201022124132&focal=none&tmtime=20201022132151',
                channel=self.channel)

            polus = Message(
                content=
                'https://prod.cdn.earlygame.com/uploads/images/_imageBlock/3904024/Polus.jpg?mtime=20201022125504&focal=none&tmtime=20201022132152',
                channel=self.channel)

            lazytown = Message(
                content='https://i.ytimg.com/vi/UTdSA_zPNmM/hqdefault.jpg',
                channel=self.channel)

            msg = {
                'skeld': skeld,
                'mirahq': mirahq,
                'polus': polus,
                'nuttensohn': lazytown
            }.get(parsed, [skeld, mirahq, polus])
            print(msg)
            return State.OK, msg
Esempio n. 3
0
 def validate_join(self, player): 
     for hand in self.hands: 
         if hand.player == player: 
             return False, (State.NO_UPDATE, Message(
                 content='du bist bereits in der Runde',
                 channel=self.channel))
     if len(self.hands) == 5: 
         return False, (State.NO_UPDATE, Message(
             content='die Runde ist bereits voll',
             channel=self.channel))
     return True, (None, None)
Esempio n. 4
0
    def work(self, message):
        if self.state == 0:

            parsed = self.parse_message(message)
            if not parsed:
                return State.FAILED, None
            _, category = parsed
            result = self.handle_request(category)
            print(result)
            if result:
                return State.OK, result
            else:
                return State.FAILED, None

        elif self.state == 1:
            parsed = self.parse_message(message)
            if parsed:
                command, params = parsed
                if command == '!info':
                    try:
                        i = int(params)
                        return State.NO_UPDATE, Message(
                            content=self.items[i].get_info(),
                            channel=self.channel)
                    except Exception as e:
                        print(e)
                        return State.SKIP, None
            if message.content == '!next':
                result = self.handle_request(self.category)
                return State.NO_UPDATE, Message(content=result,
                                                channel=self.channel)
            try:
                i = int(message.content[1])
                item = self.items[i]
            except Exception as e:
                print(e)
                return State.SKIP, None
            user = storage.get_user(self.requester.id)
            if self.validate_transaction(user, item):
                storage.insert_new_item(self.requester.id, self.category,
                                        item.objId)
                user.money(user.money.val - item.price)
                return State.OK, Message(
                    content=f'du hast {item.get_name()} gekauft, danke!',
                    channel=self.channel)
            else:
                return State.OK, Message(
                    content=
                    f'Du hast net genug Geld also verpiss dich. Geh mal lieber arbeiten du stück scheiße',
                    channel=self.channel)
Esempio n. 5
0
 def check_task(self, message):
     for task in open_tasks:    
         if task.user == message.author.id:
             job = storage.get_job_by_user_id(task.user)
             result = task.validate_work(message=message)
             if type(result) == Message:
                 communicator.append(result)
             if not result or task.done:
                 storage.del_job(job)
                 open_tasks.remove(task)
                 if task.done:
                     self.add_workdone(job.user_id.val)
     
     for user in storage.users: 
         try:
             if user.work_done.val % salary_threshold == 0 and user.work_done.val != 0: 
                 user.money(user.money.val + salary_of(user.role.val))
                 dcuser = self.client_reference.guilds[0].get_member(user.id.val)
                 channel = discord.utils.get(self.client_reference.guilds[0].channels, name='straubel')
                 communicator.append(Message(
                     content=f"```hey @{dcuser.name}!\ndu warst fleißig, du erhälst {salary_of(user.role.val)}$! ```", 
                     channel=channel))
                 user.work_done(0)
         except Exception as e:
             pass 
Esempio n. 6
0
 def food(self):
     self.items = item_handler.get_random(3, Food)
     messages = []
     for i, item in enumerate(self.items):
         messages.append(
             Message(content=item.get_image(num=i), channel=self.channel))
     return messages
Esempio n. 7
0
    def work(self, message=None):
        command, params = self.parse_message(message)
        if self.state == 0:
            items = storage.get_items_by_user_id(self.requester.id)
            item_objs = [item_handler.construct_item(item) for item in items]
            embed = discord.Embed(title='Inventory', color=0xffc800)
            inventory = Inventory(item_objs)

            if params:
                for field in inventory.fields:
                    print(params)
                    print(field.name.lower())
                    if params.lower() in field.name.lower():
                        print('yeess')
                        field_string = ''
                        for item in field.get_set():
                            field_string += f'{item.name} ×{inventory.count(item)} \n'
                        embed.add_field(name=field.name, value=field_string)
                        break
            else:
                for field in inventory.fields:
                    field_string = ''
                    for i, item in enumerate(field.get_set()):
                        if i > 3:
                            field_string += '...'
                            break
                        field_string += f'{item.name} ×{inventory.count(item)} \n'
                    embed.add_field(name=field.name, value=field_string)

            return State.OK, Message(content=embed, channel=self.channel)
Esempio n. 8
0
 def update(self):
     while True:
         article = self.toparticle()
         if article:
             communicator.append(
                 Message(content=article.attrs['href'],
                         channel=self.channel))
         time.sleep(NEWS_TIME)
Esempio n. 9
0
 def work(self, message=None):
     if self.state == 0:  
         print('hallo')
         items = storage.get_items_by_user_id(self.requester.id)
         item_objs = [item_handler.construct_item(item) for item in items]
         names = [item.get_name() for item in item_objs]
         # names = [item_handler.name(item) for item in items]
         answer = ''.join([f'• {name}\n' for name in names])
         return State.OK, Message(
             content=f'```{answer}```',
             channel=self.channel)
Esempio n. 10
0
 def validate_work(self, message):
     try:
         if self.state.val == 0:
             return State.OK, Message(
                 content=
                 'Du hast es geschafft eine Nachricht zu versenden! Geiles Ding!',
                 channel=message.channel)
         if message.author.id == self.user:
             return State.OK, True
     except Exception as e:
         print(e)
         return State.FAILED, False
Esempio n. 11
0
    def validate_work(self, message):
        try:
            user = storage.get_random_user()
            user = self.client_refrence.guilds[0].get_member(user.id.val)
            return State.OK, Message(
                content=f'@{user.name} bedankt sich! Du erhaelst 10$',
                channel=message.channel)
            worker = storage.get_user(self.user.id)
            worker.money(worker.money.val + 10)

        except Exception as e:
            print(e)
            return State.FAILED, None
Esempio n. 12
0
 def possession(self):
     self.items = storage.get(ItemCats.POSSESSION)
     self.items = [
         item_handler.construct_item(item, user_id=item.user_id.val)
         for item in self.items
     ]
     self.items = list(filter(self.for_sale, self.items))
     messages = []
     for i, item in enumerate(self.items[self.possession_pointer:]):
         self.possession_pointer += 1
         messages.append(
             Message(content=item.get_image(num=i), channel=self.channel))
         if self.possession_pointer % 3 == 0:
             return messages
     return messages
Esempio n. 13
0
 def validate_work(self, message):
     try:
         coffee, found = self.find_coffee(message.content)
         if found:
             user = storage.get_random_user()
             user = self.client_refrence.guilds[0].get_member(user.id.val)
             return State.OK, Message(
                 content=
                 f'Du hast @{user.name} einen {coffee} gemacht! Formidable.',
                 channel=message.channel)
         else:
             return State.NO_UPDATE, True
     except Exception as e:
         print(e)
         return State.FAILED, None
Esempio n. 14
0
    def work(self, message): 
        if self.state == 0:
            if message.content == '!blackjack': 
                return State.NO_UPDATE, Message(
                    content='waiting for players', 
                    channel=self.channel)
            if message.content == '!join': 
                player = storage.get_user(message.author.id)
                join_validation, payload = self.validate_join(player)
                if join_validation: 
                    self.hands.append(Hand(player))
                    return State.NO_UPDATE, Message(
                        content=f'{len(self.hands)}/5 Spieler!',
                        channel=self.channel)
                else: 
                    return State.NO_UPDATE, payload

            elif message.content == '!start' and len(self.hands) >= 1:
                first = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name
                self.pointer += 1
                return State.OK, [
                Message(
                    content='initialisiere Spiel..',
                    channel=self.channel),
                Message(
                    content=f'@{first} was setzen Sie?',
                    channel=self.channel) 
                ]
            else: 
                return State.SKIP, None
                    
        elif self.state == 1:
            try: 
                commitment = int(message.content[1:])
                if commitment > self.hands[self.pointer-1].player.money.val: 
                    return State.NO_UPDATE, Message(
                        content=f'dein Geld reicht nicht aus',
                        channel=self.channel) 
                else: 
                    self.commitcommitment(self.hands[self.pointer-1], commitment)
                if len(self.hands) == self.pointer:
                    msg = ''
                    for hand in self.hands: 
                        name = self.client_reference.guilds[0].get_member(hand.player.id.val).name
                        self.givecards(hand)
                        card_string = ' '.join([self.getimage(card) for card in hand.cards])
                        msg += f'{name}: {card_string} \n'
                    dealer_string = ' '.join([self.getimage(card) for card in self.dealer_hand.cards])
                    msg += f'dealer hand: {dealer_string}'

                    self.pointer = 0
                    first = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name

                    return State.OK, [
                        Message(
                            content=f'```{msg}```',
                            channel=self.channel), 
                        Message(
                            content=f'@{first} haetten Sie gerne noch eine Karte?',
                            channel=self.channel
                    )]
                    
                name = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name
                self.pointer += 1
                return State.NO_UPDATE, Message(
                    content=f'@{name} was setzen Sie?',
                    channel=self.channel
                )
            except ValueError as e:  
                print(e)
                return State.NO_UPDATE, None
            pointer +=1
        elif self.state == 2: 
            if message.content[1:] == 'ja': 
                self.givecard(self.hands[self.pointer])
                msg = ''
                for hand in self.hands: 
                    name = self.client_reference.guilds[0].get_member(hand.player.id.val).name
                    card_string = ' '.join([self.getimage(card) for card in hand.cards])
                    msg += f'{name}: {card_string} \n'
                dealer_string = ' '.join([self.getimage(card) for card in self.dealer_hand.cards])
                msg += f'dealer hand: {dealer_string}'

                if self.validate_hand(self.hands[self.pointer]): 
                    name = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name
                    return State.NO_UPDATE, [
                        Message(
                            content=f'```{msg}```',
                            channel=self.channel),
                        Message(
                            content=f'@{name} haetten Sie gerne noch eine Karte?',
                            channel=self.channel)]
                else: 
                    self.hands.remove(self.hands[self.pointer])
                    self.pointer += 1
                    name = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name
                    return State.NO_UPDATE, [
                        Message(
                            content='schade!',
                            channel=self.channel),
                        Message(
                            content=f'```{msg}```',
                            channel=self.channel), 
                        Message(
                            content=f'@{name} haetten Sie gerne noch eine Karte?',
                            channel=self.channel)]

            else: 
                self.pointer += 1
                name = self.client_reference.guilds[0].get_member(self.hands[self.pointer].player.id.val).name
                return Message(
                    content=f'{name} haetten Sie gerne noch eine Karte?',
                    channel=self.channel
                )    
Esempio n. 15
0
 def work(self, message=None):
     for u in storage.users:
         if u.id.val == self.requester.id:
             return True, Message(content=message_of(
                 'balance', self.state, u.money.val),
                                  channel=self.channel)
Esempio n. 16
0
 def work(self, message=None):
     for u in storage.users:
         if u.id.val == self.requester.id:
             return True, Message(content=message_of(
                 'salary', self.state, salary_of(u.role.val)),
                                  channel=self.channel)
Esempio n. 17
0
 def work(self, message=None): 
     print('nice')
     return State.OK, Message(
         content=f'```@{self.member.name} Willkommen bei Mesla Totors!```',
         channel=self.channel)