Skip to content

Incorrectone/Python-in-Reddit-BOT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Reddit-Python-Execute-BOT

What this is about?

So ummmmm API access is gone so lol, but will keep my shit code public still

I am new to Reddit Bots and wanted to create a bot that could execute Python Commands/Run Saved Functions
I don't write much in Github pages so I don't know how to source much of this but I will try!

The bot will only recognise commands from markdown mode.

Warning! This bot can extract your accounts password! It has moderator access to the bot account as much as you! You will be basically giving access to anyone who tries execute python! Be carefull.. Even the client secret and ID

This BOT uses PRAW and mysql-connector

Details

Every Single Screenshot is from here, here and here

Setup

image
MySQL server Setup

image
Praw Connection Setup

image
Databases Setup

Testing/Commands

I took the easy route and used regex to search for commands in reddit comments

Looking for the call code

(\$\!(define|execute)\.function\$\n\:(\w{7,20})\:\n\:\n([\S|\s]+)\n\:\n\$\!(mod|user)\.console\.end\$)
image

(\$\!(ser|run)\.([\w]{7,20}|all)[\$|\(]([\d|\w| |\,|\']+|)(\)\$|))
image

The define/execute Function is given priority over search/run Function

Syntax

Everything other than the explained part is just to add value to the looks and create a syntax which people may not use reguraly and holds no special and meaning/value.

define/execute

  • These commands are only available to the Moderators of a given Subreddit
$!execute.function$
:functionname:
:
def here(x,y):
    return x+y
x=5
y=2
z = 10
print(z*here(x,y))
:
$!mod.console.end$
$!define.function$
:functionname:
:
def here(x,y):
    return x+y
x=5
y=2
z = 10
print(z*here(x,y))
:
$!mod.console.end$

Explanation:

$!execute.function$

$!define.function$

  • 'execute' helps in identifying the following code is for execution
    • Only one restriction don't end with the end...
  • 'define' helps in identifying the following code is for saving
    • While saving, code will not be executed.
    • This function has some restrictions which will be discussed later.

:functionname:

  • 'functionname' is the function name that will be stored in the database while saving the code
    • This is only useful in define function.
    • Function name in database is Unique.
    • While it is required in execute function, it is useless as it is not used (Because I am too lazy and am not making it case specific.)

$!mod.console.end$

  • In this line 'mod' part can be replace with 'user'
  • While this too is required in execute function, it is useless as it is not used (Because I am too lazy and am not making it case specific.)
  • In define function however:
    • This line defines what the permissions of a saved function should be, when called the code checks if it is allowed to be executed by a 'Normal User' or a 'Moderator.'

search/run

$!ser.functi2onname$
$!run.functi2onname(1,5)$
$!run.functi2onname$
  • Pretty self explanatory
  • For the search function:
    • No need for any Input only function name is needed
    • Output -> check Output section
  • For the run function:
    • May or may not need Input
    • For knowledge use search function

Output

screencapture-github-Incorrectone-Reddit-Python-Execute-BOT-edit-main-README-md-2021-08-28-19_20_40
Main Output List

For execute command:

Everything in that will be shown in the output will be the print function. As seen in the second python file:

  • It records every single thing printed and then replies to the comment with that.
  • Any error will be reported in the comment if it occurs.
  • Everything done is recorded in the second table, This is for bug checking.
Example:
  • Without Error:
    image
  • With Error:
    image

For define command:

  • Only confirmation whether the new function has been stored
    • Shows the error(outside of the code) if occurs.
    • Will not even check whether the code is wrong or not.
Example:
  • If the name is available:
    image
  • If the name is not available:
    image

For search command:

  • Outputs will be:
    image
Example

image

Meanwhile in Log:

image

In localhost/phpmyadmin/

Input

  • The execute function does not have any restrictions in the general sense

    • Just don't use the end phrase anywhere other than at the end (:p)
  • The define function does have other wise it will not work

    • Don't use the phrase

      ^^^INPUT^^^

    • Since the define command is not executed upon saving this will not show up an error
    • No use of %s formating in functions where input is to be taken! Otherwise it is fine!
$!run.functioname(1,2)$
  • The run function just need to have
    • This part is enough to have '([Value],[Value])' for Inputing
    • If there are no inputs, Don't put it!
Example:
  • Defining
    image

    image

     $!define.function$
     :functionname4:
     :
     def here(x,y):
         return x+y
     x=^^^INPUT^^^
     y= ^^^INPUT^^^
     z = 10
     print(z*here(x,y))
     :
     $!mod.console.end$
  • Executing
    image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages