privmsg interface to ircbot in django admin
fill out the form, send a privmsg
This commit is contained in:
		
							parent
							
								
									56b495e8fb
								
							
						
					
					
						commit
						d9f905c691
					
				| @ -1,11 +1,41 @@ | ||||
| """Manage ircbot models in the admin interface.""" | ||||
| """Manage ircbot models and admin actions in the admin interface.""" | ||||
| 
 | ||||
| import logging | ||||
| import xmlrpclib | ||||
| 
 | ||||
| from django.conf import settings | ||||
| from django.contrib import admin | ||||
| from django.shortcuts import render | ||||
| 
 | ||||
| from ircbot.forms import PrivmsgForm | ||||
| from ircbot.models import Alias, BotAdmin, IrcChannel, IrcPlugin | ||||
| 
 | ||||
| 
 | ||||
| log = logging.getLogger('ircbot.admin') | ||||
| 
 | ||||
| 
 | ||||
| admin.site.register(Alias) | ||||
| admin.site.register(BotAdmin) | ||||
| admin.site.register(IrcChannel) | ||||
| admin.site.register(IrcPlugin) | ||||
| 
 | ||||
| 
 | ||||
| def send_privmsg(request): | ||||
|     """Send a privmsg over XML-RPC to the IRC bot.""" | ||||
| 
 | ||||
|     if request.method == 'POST': | ||||
|         form = PrivmsgForm(request.POST) | ||||
|         if form.is_valid(): | ||||
|             target = form.cleaned_data['target'] | ||||
|             message = form.cleaned_data['message'] | ||||
| 
 | ||||
|             bot_url = 'http://{0:s}:{1:d}/'.format(settings.IRCBOT_XMLRPC_HOST, settings.IRCBOT_XMLRPC_PORT) | ||||
|             bot = xmlrpclib.ServerProxy(bot_url) | ||||
|             bot.privmsg(target, message) | ||||
|             form = PrivmsgForm() | ||||
|     else: | ||||
|         form = PrivmsgForm() | ||||
| 
 | ||||
|     return render(request, 'privmsg.html', {'form': form}) | ||||
| 
 | ||||
| admin.site.register_view('ircbot/privmsg/', "Ircbot - privmsg", view=send_privmsg, urlname='ircbot_privmsg') | ||||
|  | ||||
							
								
								
									
										15
									
								
								dr_botzo/ircbot/forms.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								dr_botzo/ircbot/forms.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| """Forms for doing ircbot stuff.""" | ||||
| 
 | ||||
| import logging | ||||
| 
 | ||||
| from django.forms import Form, CharField | ||||
| 
 | ||||
| log = logging.getLogger('markov.forms') | ||||
| 
 | ||||
| 
 | ||||
| class PrivmsgForm(Form): | ||||
| 
 | ||||
|     """Accept a privmsg to send to the ircbot.""" | ||||
| 
 | ||||
|     target = CharField() | ||||
|     message = CharField() | ||||
							
								
								
									
										15
									
								
								dr_botzo/ircbot/templates/privmsg.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								dr_botzo/ircbot/templates/privmsg.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| {% extends 'adminplus/index.html' %} | ||||
| 
 | ||||
| {% block title %}Ircbot - Privmsg{% endblock %} | ||||
| 
 | ||||
| {% block content %} | ||||
| <div id="content-main"> | ||||
|     <form id="ircbot_privmsg_form" action="{% url 'admin:ircbot_privmsg' %}" method="post"> | ||||
|         {% csrf_token %} | ||||
|         <table> | ||||
|             {{ form }} | ||||
|         </table> | ||||
|         <input class="submit-button" type="submit" value="Privmsg"/> | ||||
|     </form> | ||||
| </div> | ||||
| {% endblock %} | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user