This forum is in archive mode. You will not be able to post new content.

Author Topic: TechBot, an IRC bot  (Read 1244 times)

0 Members and 1 Guest are viewing this topic.

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
TechBot, an IRC bot
« on: July 25, 2015, 08:49:36 AM »
Wrote something that seems simpler than BeastBot, namespace aside, I think my solution seems to work out better. A global config file. IRC stuff stays in it's onwn class, the bot uses only what it needs, modules have a standard on what they get from the bot and also what they return, etc....

No docs yet, soon bro, but code doc strings and comments should tell you enough to get  started. Also, getting this up and running is simple, just run TechBot.py and as long as your config file is okay, your up and going.

Anyway, here is le github:
https://github.com/nulldigit90/TechBot

As far as dev goes. Fork it and send pull requests to me at nulldigit90/TechBot. If evilzone wants to use it they can handle my pull-requests to merge into upstream main.
>>>import this
-----------------------------

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: TechBot, an IRC bot
« Reply #1 on: July 31, 2015, 07:01:14 AM »
Bump:
Github https://github.com/nulldigit90/TechBot

Has been updated, there are some changes. The adons are much simpler now and will be even more clear soon.

SSL is being an issue at the moment. If it works reliably then let me know your setup or something. The issues I have with SSL is after the module has ran, it seems to kill the sockets out, but only when using SSL. Some others testing it might help narrow down the issue.

Anyway, things have been reworked a bit since you might have last looked or used it. I will try and keep an update on here as dev goes on. Doc-strings, commit history, and comments in code should be enough to help ya along. PM me here or on IRC for any questions. You run into any other issues, make a pull request and we'll handle it together.
>>>import this
-----------------------------

Offline khofo

  • EZ's Swashbuckler
  • Knight
  • **
  • Posts: 350
  • Cookies: 25
  • My humor is so black, it could go cotton picking.
    • View Profile
Re: TechBot, an IRC bot
« Reply #2 on: July 31, 2015, 05:10:06 PM »
I find this bot much much easier to work with, I got it up an running in a little to no time.
And created a module for it :p

It converts:

1. Kg/lb
2. Ft/m/yds
3. F/C

It's just an adaptation of my old module:
https://evilzone.org/projects-and-discussion/ezbot-conversion-module/
I already made a pull request, but for the community this is the code:


Module:
Code: (Python) [Select]
#!/usr/bin/python

'''
Adaptation of the convert.py (for BeastBot), for TechBot in python3
this module converts units after the command !convert,
For Evilzone IRC (irc.evilzone.org)

By: Khofo
'''


'''                    START CONVERSIONS                         '''

def kg_to_lb(number,send):
    result = number*float(2.2046)
    send(str(number) + " Kilograms = " + str(result) + " Pounds")

def lb_to_kg(number,send):
    result = number*float(0.453592)
    send(str(number) + " Pounds = " + str(result) + " Kilograms")
def f_to_c(number,send):
    result = (number-32)*float(0.555)
    send(str(number) + " Degrees Fahreinheit = " + str(result) + " Degrees Celsius")

def c_to_f(number,send):
    result = (number*float(1.)+32
    send(str(number) + " Degrees Celsius = " + str(result) + " Degrees Fahreinheit")

def m_to_ft(number,send):
    result = number*float(3.28084)
    send(str(number) + " Meters = " + str(result)+" Feet" )

def ft_to_m(number,send):
    result = number*float(0.3048)
    send(str(number) + " Feet = " + str(result)+" Meters")

def m_to_yds(number,send):
    result = number*float(1.09361)
    send(str(number) + " Meters = " + str(result)+" Yards")

def ft_to_yds(number,send):
    result = number*float(0.3333)
    send(str(number) + " Feet = " + str(result)+" Yards")

def yrds_to_m(number,send):
    result = number*float(0.9144)
    send(str(number) + " Yards = " + str(result)+" Meters")   

def yrds_to_ft(number,send):
    result = number*float(3)
    send(str(number) + " Yards = " + str(result)+" Feet")

'''               END OF CONVERSIONS                      '''

def main(nick, comargvs, chan, send):
    try:
        numArgs = comargvs.split()
        if numArgs != '':
            if comargvs == "help":
                send("Usage Example: 10 ft to m")
            else:
                pass
            number = numArgs[0] #the number to be converted
            unit_from = numArgs[1].lower() # unit to convert from
            unit_to = numArgs[3].lower() # unit to convert to
            send(conversion(unit_from, unit_to, number,send))
            pass
    except:
        pass

       
def conversion(unit_from, unit_to, number, send):   
       
    try:
        number = float(number.strip())
    except:
        send("Usage Example: 10 ft to m")
   
    linear = { ('m', 'ft')  : "m_to_ft", 
               ('m', 'yds') : "m_to_yds",   
               ("ft", "m")  : "ft_to_m",
               ("ft", "yds"): "ft_to_yds",
               ("yds", "m") : "yds_to_m",
               ("yds", "ft"): "yds_to_ft",
               ("kg", "lb") : "kg_to_lb",
               ("lb", "kg") : "lb_to_kg",
               ("f", "c")   : "f_to_c",
               ("c", "f")   : "c_to_f",
               }
    if (unit_from, unit_to) in linear:
        if linear[(unit_from, unit_to)] == "m_to_ft":
            send(m_to_ft(number,send))
       
        elif linear[(unit_from, unit_to)] == "m_to_yds":
            send(m_to_yds(number,send))
       
        elif linear[(unit_from, unit_to)] == "ft_to_m":
            send(ft_to_m(number,send))
       
        elif linear[(unit_from, unit_to)] == "ft_to_yds":
            send(ft_to_yds(number, send))
       
        elif linear[(unit_from, unit_to)] == "yds_to_m":
            send(yrds_to_m(number,send))
       
        elif linear[(unit_from, unit_to)] == "yds_to_ft":
            send(yrds_to_ft(number,send))
       
        elif linear[(unit_from, unit_to)] == "kg_to_lb":
            send(kg_to_lb(number,send))
       
        elif linear[(unit_from, unit_to)] == "lb_to_kg":
            send(lb_to_kg(number,send))
       
        elif linear[(unit_from, unit_to)] == "f_to_c":
            send(f_to_c(number,send))
       
        elif linear[(unit_from, unit_to)] == "c_to_f":
            send(c_to_f(number,send))
        else:
            pass
    else:
        error = "ERROR: For usage please refer to !convert help"
        send(error)

And here the test results from #bottest
Code: [Select]
<khofo> !convert help
<TechBot> Usage Example: 10 ft to m
<khofo> !convert 10 m to ft
<TechBot> 10.0 Meters = 32.8084 Feet
<khofo> !convert 10 m to yds
<TechBot> 10.0 Meters = 10.9361 Yards
<khofo> !convert 10 ft to m
<TechBot> 10.0 Feet = 3.048 Meters
<khofo> !convert 10 ft to yds
<TechBot> 10.0 Feet = 3.3329999999999997 Yards
<khofo> !convert 10 yds to m
<TechBot> 10.0 Yards = 9.144 Meters
<khofo> !convert 10 yds to ft
<TechBot> 10.0 Yards = 30.0 Feet
<khofo> !convert 10 lb to kg
<TechBot> 10.0 Pounds = 4.53592 Kilograms
<khofo> !convert 10 kg to lb
<TechBot> 10.0 Kilograms = 22.046 Pounds
<khofo> !convert 10 f to c
<TechBot> 10.0 Degrees Fahreinheit = -12.21 Degrees Celsius
<khofo> !convert 10 c to f
<TechBot> 10.0 Degrees Celsius = 50.0 Degrees Fahreinheit
<khofo> !convert sdgdv
<khofo> ^ to prevent 'help' floods
« Last Edit: July 31, 2015, 05:12:13 PM by Khofo »
Quote from: #Evilzone
<Spacecow18> priests are bad ppl
<Insanity> Holy crap
Of course God isnt dead. He's out there partying with the Easter Bunny, Santa Clause, Tooth Fairy, and the Man on the moon...
Some of my work: Introduction to Physical Security

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: TechBot, an IRC bot
« Reply #3 on: July 31, 2015, 08:42:03 PM »
Merged, also now it's using utf-8 so the issue you where having is fixed.
>>>import this
-----------------------------

Offline khofo

  • EZ's Swashbuckler
  • Knight
  • **
  • Posts: 350
  • Cookies: 25
  • My humor is so black, it could go cotton picking.
    • View Profile
Re: TechBot, an IRC bot
« Reply #4 on: July 31, 2015, 09:56:35 PM »
I'll try to convert the other modules already available, working with this bot is much easier to say the previous one
« Last Edit: July 31, 2015, 09:58:55 PM by Khofo »
Quote from: #Evilzone
<Spacecow18> priests are bad ppl
<Insanity> Holy crap
Of course God isnt dead. He's out there partying with the Easter Bunny, Santa Clause, Tooth Fairy, and the Man on the moon...
Some of my work: Introduction to Physical Security

Offline TheWormKill

  • EZ's Scripting Whore
  • Global Moderator
  • Knight
  • *
  • Posts: 257
  • Cookies: 66
  • The Grim Reaper of Worms
    • View Profile
Re: TechBot, an IRC bot
« Reply #5 on: July 31, 2015, 10:26:40 PM »
I'll try to convert the other modules already available, working with this bot is much easier to say the previous one
That's actually something I wanted to do when I come back in a week. :) Will do some testing, too.

UPDATE: I've read through the code and it looks quite clean. Apart from a few small weirdnesses
of the code, everything looks fine. I'll come up with examples etc. when I have access to my own box.
« Last Edit: August 01, 2015, 12:06:32 PM by TheWormKill »
Stuff I did: How to think like a superuser, Iridium

He should make that "Haskell"
Quote
<m0rph-is-gay> fuck you thewormkill you python coding mother fucker

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: TechBot, an IRC bot
« Reply #6 on: August 07, 2015, 09:32:15 AM »
SSL IS WORKING!!!!!!!!

I have ssl working now, the initial issue was passing the socket handle around to the multiprocessed plugin/adons. I am using queues now along with select, so CPU rape isn't a thing, and ssl works, and mulitprocessing works, and you get the point.

@Khofo:
In your module, instead of just send("your data") it will now be send.put("your data")
Small and simple. I am trying to keep core and plugin/addons separate, so this should be the only change anyone would need to do pre-fix.

I have added test2.py along with updating test.py in the adons folder to show examples on how to write plugings/addons and whatnot. Any questions ask here or on Github.
>>>import this
-----------------------------

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: TechBot, an IRC bot
« Reply #7 on: August 09, 2015, 06:14:50 AM »
I changed the delimiter from  "!" to "." to avoid conflicts in the channels, so instead of !test, you would do .test as an example.

Also, chris1's urban dictionary (!wtf/!ud) has been ported. It doesn't give the upvote/downvote score from the urban dictionary website because I didn't find the info useful.

I will also be working on other ports and some originals as time goes on. Once I'm happy with the state and addons I'll host it on my server.

So this is a call for addons/plugins. If you want to code something small and useful, do it. I'll help you port it and make it something IRC can benefit from. Here is an example of the test.py addon.

Code: (python) [Select]
# main() is what is executed. you can have any number of functions you want but main() is
# what will be executed, so keep what you want to send inside of main().

import time

def main(nick, comargs, chan, send):
    # example on sending a simple string to the default channel the bot is on
    print("[*] Testing simple default")
    time.sleep(1)
    send.put("Success!")
« Last Edit: August 09, 2015, 06:16:11 AM by techb »
>>>import this
-----------------------------

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.