======Project: My Bot does Math====== A project for Unix/Linux Programing by Corey Forman during the Fall 2011. This project was begun on October 4th and took a week to complete. =====Objectives===== Make my irc bot perform basic tasks such as say hello and tell how many people are on. The real project is making it do basic math. =====Prerequisites===== In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved: * experience in basic scripting * experience in looping * experience in if statements * experience in killing programs helps =====Background===== State the idea or purpose of the project. What are you attempting to pursue? Upon approval, you'll want to fill this section out with more detailed background information. DO NOT JUST PROVIDE A LINK. Providing any links to original source material, such as from a project page, is a good idea. You'll want to give a general overview of what is going to be accomplished (for example, if your project is about installing a web server, do a little write-up on web servers. What is it, why do we need one, how does it work, etc.) =====Scope===== Give a general overview of your anticipated implementation of the project. Address any areas where you are making upfront assumptions or curtailing potential detail. State the focus you will be taking in implementation. =====Attributes===== State and justify the attributes you'd like to receive upon successful approval and completion of this project. * commands : i am using commands * files and directories : my bot sends information into a file + i am using files * text processing : i am using the vi editor * UNIX shell : i am working in the unix shell * job control : my bot runs in the background * scripting : i am scripting my bot * regular expressions : im using regular expressions to grab entered commands so my bot can respond =====Procedure===== I sat down and thought of how it should work. I started with just a loop that would activate when the command "math" is given. Next, I adjusted the loop to perform the math only when numbers are given. After that i set up flags to moderate when the bot does anything within the loop. finally I created a quit command for the math loop so it can be ended. Frequently through out the project I got our teachers help to work out kinks during the process. #!/bin/bash -x pkill ii 2>/dev/null BOT="DOOMONU" #replace chan with #botchan2 CHAN="#bottest" SERV="irc" ii -s $SERV -n $BOT & PID=$$ cd ~/irc/irc echo "/join $CHAN" > in cd "$CHAN" CMD="`cat out|grep $BOT|tail -1|cut -d':' -f3`" while [ ! "$CMD" = " quit" ]; do if [ "$CMD" = " hi" ]; then echo "Hello, `cat out|grep $BOT|tail -1|cut -d'>' -f1 | cut -d'<' -f2` , Welcome to my MASTERS abode enjoy your stay <'__'>" > in fi if [ "$CMD" = " how many users are active" ]; then echo " There are `who | wc -l` users on the system." > in fi if [ "$CMD" = " math" ]; then FLAG=1 until [ "$CMD" = " stop math" ]; do if [ "$FLAG" = 2 ]; then echo "The resault of `cat out| grep $BOT|tail -1|cut -d':' -f3` is `cat out| grep $BOT|tail -1|cut -d':' -f3| bc`" > in FLAG=1 fi if [ "$CMD" = " stop math" ]; then FLAG=0 elif [ "`echo $CMD | cut -c1`" -ge 0 ] && [ "`echo $CMD | cut -c1`" -le 9 ]; then FLAG=2 elif [ "`echo $CMD | cut -c2`" -ge 0 ] && [ "`echo $CMD | cut -c2`" -le 9 ]; then Flag=2 else FLAG=1 fi CMD="`cat out|grep $BOT|tail -1|cut -d':' -f3`" sleep 5 done fi sleep 4 CMD="`cat out|grep $BOT|tail -1|cut -d':' -f3`" done echo "/quit" > in exit =====Execution===== 15:33 -!- DOOMONU [~DOOMONU@lab46.corning-cc.edu] has joined #bottest 15:34 <@gidron> DOOMONU: hello 15:34 <@gidron> DOOMONU: hi 15:34 < DOOMONU> Hello, gidron , Welcome to my MASTERS abode enjoy your stay <'__'> 15:34 <@gidron> DOOMONU: math 15:34 <@gidron> DOOMONU: 2+2 15:34 < DOOMONU> The resault of 2+2 is 4 15:34 <@gidron> DOOMONU: quit math 15:34 < DOOMONU> The resault of quit math is 15:34 <@gidron> DOOMONU: stop math 15:35 <@gidron> DOOMONU: quit 15:35 -!- DOOMONU [~DOOMONU@lab46.corning-cc.edu] has quit [DOOMONU] My bot does math yahoo <(^^,)> =====Reflection===== During this process controlling the loops was highly difficult to keep it from spamming the channel. The flags we added worked wonderfully controlling the results that the bot spits out into the chat room. This is a very fun project and covers a large field of requirements for the course and comes highly recommended by me. =====References===== In performing this project, the following resources were referenced: * Matthew Haas