bots: Add incrementor bot.
This bot provides a sample implementation for updating existing messages sent by the bot.
This commit is contained in:
		
							parent
							
								
									6f88c2c9a2
								
							
						
					
					
						commit
						854416b725
					
				
					 2 changed files with 36 additions and 0 deletions
				
			
		
							
								
								
									
										30
									
								
								contrib_bots/bots/incrementor/incrementor.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								contrib_bots/bots/incrementor/incrementor.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,30 @@
 | 
				
			||||||
 | 
					# See readme.md for instructions on running this code.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class IncrementorHandler(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __init__(self):
 | 
				
			||||||
 | 
					        self.number = 0
 | 
				
			||||||
 | 
					        self.message_id = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def usage(self):
 | 
				
			||||||
 | 
					        return '''
 | 
				
			||||||
 | 
					        This is a boilerplate bot that makes use of the
 | 
				
			||||||
 | 
					        update_message function. For the first @-mention, it initially
 | 
				
			||||||
 | 
					        replies with one message containing a `1`. Every time the bot
 | 
				
			||||||
 | 
					        is @-mentioned, this number will be incremented in the same message.
 | 
				
			||||||
 | 
					        '''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def handle_message(self, message, client, state_handler):
 | 
				
			||||||
 | 
					        self.number += 1
 | 
				
			||||||
 | 
					        if self.message_id is None:
 | 
				
			||||||
 | 
					            result = client.send_reply(message, str(self.number))
 | 
				
			||||||
 | 
					            self.message_id = result['id']
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            client.update_message(dict(
 | 
				
			||||||
 | 
					                message_id=self.message_id,
 | 
				
			||||||
 | 
					                content=str(self.number),
 | 
				
			||||||
 | 
					            ))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					handler_class = IncrementorHandler
 | 
				
			||||||
							
								
								
									
										6
									
								
								contrib_bots/bots/incrementor/readme.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								contrib_bots/bots/incrementor/readme.md
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					# Incrementor bot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This is a boilerplate bot that makes use of the
 | 
				
			||||||
 | 
					update_message function. For the first @-mention, it initially
 | 
				
			||||||
 | 
					replies with one message containing a `1`. Every time the bot
 | 
				
			||||||
 | 
					is @-mentioned, this number will be incremented in the same message.
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue