### Run Factorion Bot (Binary) Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-bot-reddit/README.md Commands to run the Factorion bot binary. The first example assumes the bot was installed globally via 'cargo install', making 'factorion-bot-reddit' available in the system's PATH. The second example is for running the binary from a local Nix build. ```bash # If in path (cargo install) factorion-bot-reddit # If local nix build result/bin/factorion-bot-reddit ``` -------------------------------- ### Build and Install Factorion Bot Manually Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-bot-reddit/README.md Provides instructions for building and installing the Factorion bot from a local clone of the repository. It covers cloning the repository, navigating into the directory, building the release version, and installing it globally with Cargo. ```bash git clone https://github.com/tolik518/factorion-bot.git cd factorion-bot # To just build cargo build -r # The binaries will be in target/release # To install cargo install --path . ``` -------------------------------- ### Install Factorion Bot with Nix Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-bot-reddit/README.md Builds the Factorion bot using Nix, a reproducible package manager. This command downloads and builds the project specified by the GitHub URL, placing the binaries in the 'result/bin' directory. ```bash nix build github:tolik518/factorion-bot # The binaries will be in result/bin ``` -------------------------------- ### Install Factorion Bot with Cargo Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-bot-reddit/README.md Installs the Factorion bot from crates.io using Cargo, Rust's package manager. This is a straightforward way to get the bot running if you have Rust and Cargo set up. ```bash cargo install --locked factorion-bot-reddit ``` -------------------------------- ### Factorion Bot Configuration (.env file) Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-bot-reddit/README.md Example of the .env file used to configure the Factorion bot. It lists all the necessary environment variables for API credentials, bot behavior, rate limiting, and logging. Some variables are optional and use default values if omitted. ```env APP_CLIENT_ID= APP_SECRET= REDDIT_USERNAME= REDDIT_PASSWORD= SLEEP_BETWEEN_REQUESTS= SUBREDDITS= TERMIAL_SUBREDDITS= CHECK_MENTIONS= CHECK_POSTS= MENTIONS_EVERY= POSTS_EVERY= FLOAT_PRECISION= 1024 UPPER_CALCULATION_LIMIT= 1000000 UPPER_APPROXIMATION_LIMIT= 300 UPPER_SUBFACTORIAL_LIMIT= 1000000 UPPER_TERMIAL_LIMIT= 10000 UPPER_TERMIAL_APPROXIMATION_LIMIT= 1073741822 INTEGER_CONSTRUCTION_LIMIT= 100000000 NUMBER_DECIMALS_SCIENTIFIC= 30 INFLUXDB_HOST=localhost:8889 INFLUXDB_BUCKET=factorion-test INFLUXDB_TOKEN= RUST_LOG= ``` -------------------------------- ### Install Factorion Bot Discord with Cargo Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-bot-discord/README.md This command builds the factorion-bot-discord binary using Cargo from a workspace. It's a release build, meaning it's optimized for performance. The resulting executable will be found in the target/release directory. ```bash cd factorion-bot cargo build --release -p factorion-bot-discord # The binary will be in target/release/factorion-bot-discord ``` -------------------------------- ### Manual Factorion Bot Calculation Parsing and Execution in Rust Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-lib/README.md Illustrates the manual steps for parsing and calculating factorials using the factorion-bot library in Rust. It shows how to initialize the library, parse text to get `CalculationJob` objects, execute these jobs, and format the resulting `Calculation` objects. This method provides more granular control over the process. ```rust use factorion_lib::{parse::parse, calculation_tasks::{CalculationJob, CalculationBase}, calculation_results::{Calculation, CalculationResult, Number}}; // You need to initialize first factorion_lib::init_default().unwrap(); // Parse the text for calculations let calculations: Vec = parse("Some text with factorial 4!", true); // These are given in an intemediate format for delayed calculation assert_eq!(calculations, [CalculationJob { // The base may be a number or another job base: CalculationBase::Num(Number::Exact(4.into())), // Type of calculation level: 1, // how many minus signs were encountered negative: 0, }]); // Calculate that let mut results: Vec = calculations.into_iter().flat_map(|job| job.execute(false)).filter_map(|x| x).collect(); // The result is given in another format. assert_eq!(results, [ Calculation { // The original value (innermost base) value: Number::Exact(4.into()), // The steps taken to get the result steps: vec![(1, 0)], // The result in different formats result: CalculationResult::Exact(24.into()), } ]); let result = results.remove(0); let mut formatted = String::new(); // Write the formatted result to a string (for efficiency). We don't want to shorten anything below that huge number result.format(&mut formatted, false, false, &10000000000000000000u128.into()).unwrap(); assert_eq!(formatted, "The factorial of 4 is 24 \n\n"); ``` -------------------------------- ### Run Discord Bot with Token Configuration in Rust Source: https://context7.com/tolik518/factorion-bot/llms.txt This example shows how to run the Factorion Discord bot. It specifies the required environment variable for the Discord bot token and other configuration parameters like float precision and calculation limits. The bot listens for slash commands and specific messages containing factorial expressions. ```rust // In your .env file: // DISCORD_TOKEN=your_discord_bot_token // FLOAT_PRECISION=1000 // UPPER_CALCULATION_LIMIT=3000 // NUMBER_DECIMALS_SCIENTIFIC=5 use factorion_bot_discord::main; #[tokio::main] async fn main() -> Result<(), Box> { // The Discord bot listens for slash commands and messages // containing factorial expressions // Commands and configuration are similar to Reddit bot // but adapted for Discord's API and message format main().await } ``` -------------------------------- ### Factorion Bot Comment Processing with Rust Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-lib/README.md Demonstrates how to use the factorion-bot library to process comments. It covers initializing the library, constructing a comment object from text, parsing and extracting factorial calculations, performing the calculations, and formatting the reply. This example utilizes the abstracted comment processing flow. ```rust use factorion_lib::comment::{Comment, CommentConstructed, CommentExtracted, CommentCalculated, Commands, Status}; // You need to initialize first factorion_lib::init_default().unwrap(); // Construct a comment from the text, metadata (generic), commands and maximum comment length let comment: CommentConstructed<&str> = Comment::new("Here might be a factorial 5!?", "meta", Commands::TERMIAL, 10_000); // Here we just checked if it might contain a factorial and put things in the correct form. // Now to parse and extract any calculations let comment: CommentExtracted<&str> = comment.extract(); // Do all extracted calculations. let mut comment: CommentCalculated<&str> = comment.calc(); // Set flag, so a user will be notified (used when summoning on someone else) comment.notify = Some("@you".to_owned()); // Format the reply let reply = comment.get_reply(); // Metadata is retained throughout assert_eq!(comment.meta, "meta"); // Useful status assert_eq!(comment.status, Status::FACTORIALS_FOUND); // Good looking reply (reddit markdown formatting). assert_eq!(reply, "Hey @you! \n\nThe termial of the factorial of 5 is 7260 \n\n\n*^(This action was performed by a bot.)*"); ``` -------------------------------- ### Configure and Run Reddit Bot with Environment Variables in Rust Source: https://context7.com/tolik518/factorion-bot/llms.txt This snippet illustrates how to configure and run the Factorion Reddit bot. It outlines the necessary environment variables for authentication, subreddit configuration, and feature toggles. The bot polls Reddit for new comments, parses expressions, calculates results, and replies. Example `.env` variables are provided. ```rust // In your .env file: // APP_CLIENT_ID=your_reddit_client_id // APP_SECRET=your_reddit_secret // REDDIT_USERNAME=your_bot_username // REDDIT_PASSWORD=your_bot_password // SUBREDDITS=mathmemes:shorten,termial+ProgrammerHumor // CHECK_MENTIONS=true // CHECK_POSTS=true // FLOAT_PRECISION=1024 // UPPER_CALCULATION_LIMIT=1000000 use factorion_bot_reddit::main; #[tokio::main] async fn main() -> Result<(), Box> { // The bot reads configuration from environment variables // and starts polling Reddit for new comments // Subreddit configuration format: // SUBREDDITS=subreddit1:command1,command2+subreddit2:command3 // Commands: shorten, termial, steps, no_note, post_only // The bot will: // 1. Poll subreddits for new comments/posts/mentions // 2. Parse text for factorial expressions // 3. Calculate results with appropriate precision // 4. Reply with formatted answers // 5. Track replied IDs to avoid duplicates main().await } ``` -------------------------------- ### Execute Calculations Directly with Factorion Lib in Rust Source: https://context7.com/tolik518/factorion-bot/llms.txt This example shows how to execute calculations directly using the Factorion library without involving comment processing. It covers calculating factorials, subfactorials, termials, and nested calculations, optionally displaying intermediate steps. The `CalculationJob` struct is used to define the calculation parameters. ```rust use factorion_lib::{CalculationJob, calculation_tasks::{CalculationBase}, calculation_results::Number}; use factorion_lib::rug::Integer; fn main() { factorion_lib::init_default().unwrap(); // Calculate factorial of 50 let job = CalculationJob { base: CalculationBase::Num(Number::Exact(50.into())), level: 1, // 1 for factorial, 2 for double-factorial, etc. negative: 0 }; let results = job.execute(false); if let Some(Some(calc)) = results.first() { println!("50! = {:?}", calc.result); } // Calculate subfactorial (derangements) let subfact_job = CalculationJob { base: CalculationBase::Num(Number::Exact(10.into())), level: 0, // 0 for subfactorial negative: 0 }; let results = subfact_job.execute(false); // Calculate termial (triangular number) let termial_job = CalculationJob { base: CalculationBase::Num(Number::Exact(100.into())), level: -1, // -1 for termial, -2 for double-termial, etc. negative: 0 }; let results = termial_job.execute(false); // Calculate with intermediate steps let nested_job = CalculationJob { base: CalculationBase::Calc(Box::new(CalculationJob { base: CalculationBase::Num(Number::Exact(5.into())), level: 1, negative: 0 })), level: 1, negative: 0 }; let all_steps = nested_job.execute(true); println!("Intermediate steps: {}", all_steps.len()); } ``` -------------------------------- ### Run Factorion Bot Discord Binary Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-bot-discord/README.md These commands show how to execute the compiled Factorion Discord Bot binary. The first command assumes you are in the project's root directory and the binary was built using 'cargo build'. The second command uses 'cargo run' for convenience, also specifying the release profile. ```bash # If built from workspace ./target/release/factorion-bot-discord # Or with cargo run cargo run --release -p factorion-bot-discord ``` -------------------------------- ### Build and Run Factorio Bot with Docker Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-bot-reddit/README.md Instructions for cloning the Factorio Bot repository, building the Docker image, and running the bot using Docker Compose. This method requires setting environment variables for version and SSH path. ```bash git clone https://github.com/tolik518/factorion-bot docker build -t factorion-bot . # either create a network called `service-network` or remove the network if not needed export VERSION= export SSH_PATH= docker compose up -d ``` -------------------------------- ### Run Factorion Bot (Manual Build) Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-bot-reddit/README.md Command to run the Factorion bot after building it manually using Cargo. This command executes the bot directly from the project directory. ```bash cargo run ``` -------------------------------- ### Enter Nix Development Shell Source: https://github.com/tolik518/factorion-bot/blob/master/README.md This command allows users who utilize the Nix package manager to enter a development shell environment. This shell pre-configures all necessary dependencies for contributing to or developing the Factorio bot project. ```bash nix develop ``` -------------------------------- ### Initialize Factorion Library with Custom Limits Source: https://context7.com/tolik518/factorion-bot/llms.txt Initializes the factorion-lib with specified calculation limits and precision settings. This function allows fine-tuning for different mathematical operations, including exact calculations, approximations, and handling of large numbers. It's crucial for setting up the bot's computational boundaries. ```rust use factorion_lib; fn main() { // Initialize with default recommended values factorion_lib::init_default() .expect("Failed to initialize library"); // Or initialize with custom limits factorion_lib::init( 1024, // FLOAT_PRECISION: bits for floating point calculations 1_000_000u128.into(), // UPPER_CALCULATION_LIMIT: max for exact calculation 10u128.pow(300).into(), // UPPER_APPROXIMATION_LIMIT: max for approximation 1_000_000u128.into(), // UPPER_SUBFACTORIAL_LIMIT: max for exact subfactorial 10u128.pow(10000).into(),// UPPER_TERMIAL_LIMIT: max for exact termial 1073741822u32, // UPPER_TERMIAL_APPROXIMATION_LIMIT: bits limit 100_000_000u128.into(), // INTEGER_CONSTRUCTION_LIMIT: max integer parse size 30 // NUMBER_DECIMALS_SCIENTIFIC: decimal places in output ).expect("Already initialized or invalid parameters"); } ``` -------------------------------- ### Factorion Bot Discord Environment Configuration Source: https://github.com/tolik518/factorion-bot/blob/master/factorion-bot-discord/README.md This snippet shows the required and optional environment variables for configuring the Factorion Discord Bot. DISCORD_TOKEN is mandatory, while RUST_LOG controls logging verbosity. Other variables allow customization of calculation limits and number formatting. ```env # Required DISCORD_TOKEN= # Logging (recommended to reduce verbosity from serenity) RUST_LOG=info,serenity=warn,tracing=warn # Optional (with defaults shown) FLOAT_PRECISION=1000 UPPER_CALCULATION_LIMIT=3000 UPPER_APPROXIMATION_LIMIT=1000000 UPPER_SUBFACTORIAL_LIMIT=100000 UPPER_TERMIAL_LIMIT=100000 UPPER_TERMIAL_APPROXIMATION_LIMIT=1000000 INTEGER_CONSTRUCTION_LIMIT=100000 NUMBER_DECIMALS_SCIENTIFIC=5 ``` -------------------------------- ### Factorion Bot Configuration File (.env) Source: https://github.com/tolik518/factorion-bot/blob/master/README.md Defines the environment variables required to configure the Factorion bot. This includes Reddit API credentials, operational settings like sleep intervals and subreddits to monitor, calculation limits, and optional InfluxDB connection details. ```env APP_CLIENT_ID= APP_SECRET= REDDIT_USERNAME= REDDIT_PASSWORD= SLEEP_BETWEEN_REQUESTS= SUBREDDITS= TERMIAL_SUBREDDITS= CHECK_MENTIONS= CHECK_POSTS= MENTIONS_EVERY= POSTS_EVERY= FLOAT_PRECISION= 1024 UPPER_CALCULATION_LIMIT= 1000000 UPPER_APPROXIMATION_LIMIT= 300 UPPER_SUBFACTORIAL_LIMIT= 1000000 UPPER_TERMIAL_LIMIT= 10000 UPPER_TERMIAL_APPROXIMATION_LIMIT= 1073741822 INTEGER_CONSTRUCTION_LIMIT= 100000000 NUMBER_DECIMALS_SCIENTIFIC= 30 INFLUXDB_HOST=localhost:8889 INFLUXDB_BUCKET=factorion-test INFLUXDB_TOKEN= RUST_LOG= ``` -------------------------------- ### Format Calculation Results in Rust Source: https://context7.com/tolik518/factorion-bot/llms.txt Demonstrates formatting calculation results in Rust using the factorion_lib crate. It covers exact results, forced shortening with scientific notation, and approximate results. This function is essential for presenting mathematical outcomes in a human-readable format. ```rust use factorion_lib::{Calculation, calculation_results::CalculationResult}; use factorion_lib::rug::{Integer, Float}; fn main() { factorion_lib::init_default().unwrap(); let mut output = String::new(); let too_big = Integer::from(10u128.pow(9999)); // Format exact result let calc = Calculation { value: 5.into(), steps: vec![(1, 0)], result: CalculationResult::Exact(120.into()) }; calc.format(&mut output, false, false, &too_big).unwrap(); // Output: "The factorial of 5 is 120 " // Format with forced shortening let large = Calculation { value: 100.into(), steps: vec![(1, 0)], result: CalculationResult::Exact(Integer::from(10u128.pow(157))) }; large.format(&mut output, true, false, &too_big).unwrap(); // Output uses scientific notation // Format approximation let approx = Calculation { value: 100000.into(), steps: vec![(1, 0)], result: CalculationResult::Approximate( Float::with_val(1024, 2.824).into(), 456574.into() ) }; approx.format(&mut output, false, false, &too_big).unwrap(); // Output: "The factorial of 100000 is approximately 2.824 × 10^456574 " // Check calculation properties if calc.is_approximate() { println!("Result is approximate"); } if calc.is_too_long(&too_big) { println!("Result exceeds length limit"); } } ``` -------------------------------- ### Configure Output and Behavior with Command Flags in Rust Source: https://context7.com/tolik518/factorion-bot/llms.txt This snippet demonstrates how to use command flags to control output formatting and behavior in the Factorion Bot. It shows combining multiple commands using bitwise OR and parsing commands from comment text. Available flags include SHORTEN, STEPS, TERMIAL, NO_NOTE, and POST_ONLY. ```rust use factorion_lib::{Comment, Commands}; fn main() { factorion_lib::init_default().unwrap(); // Combine multiple commands with bitwise OR let commands = Commands::SHORTEN | Commands::STEPS | Commands::TERMIAL; // Parse commands from comment text let text = "Calculate 10! [shorten] [steps] [no_note]"; let extracted_commands = Commands::from_comment_text(text); // Available command flags: // - SHORTEN: Convert large numbers to scientific notation // - STEPS: Show all intermediate calculation steps // - TERMIAL: Enable parsing of termial (n?) expressions // - NO_NOTE: Disable explanatory notes in replies // - POST_ONLY: Only respond to posts, not comments let comment = Comment::new(text, (), commands, 10000); let comment = comment.extract().calc(); let reply = comment.get_reply(); // Commands can be overridden let override_text = "Calculate 5! [shorten] but actually long"; let overrides = Commands::overrides_from_comment_text(override_text); let final_commands = commands & overrides; } ``` -------------------------------- ### Handle Large Numbers and Edge Cases in Rust Source: https://context7.com/tolik518/factorion-bot/llms.txt Illustrates handling arbitrary-precision integers and approximations in Rust. This includes parsing and executing calculations for very large numbers, and processing various edge cases like 0!, 1!, negative factorials, and subfactorials. It demonstrates how to match and interpret different result types from the factorion_lib. ```rust use factorion_lib::{parse, rug::Integer}; fn main() { factorion_lib::init_default().unwrap(); // Parse and calculate very large factorials let huge = "What is 100000! ?"; let jobs = parse(huge, false); for job in jobs { let results = job.execute(false); for result in results.flatten() { match result.result { factorion_lib::Calculation::Exact(n) => { println!("Exact result with {} digits", n.to_string().len()); } factorion_lib::Calculation::Approximate(base, exp) => { println!("Approximate: {} × 10^{}", base.as_float(), exp); } factorion_lib::Calculation::ApproximateDigits(neg, digits) => { println!("Number has {} {} digits", if neg { "negative" } else { "positive" }, digits); } factorion_lib::Calculation::ApproximateDigitsTower(_, neg, depth, base) => { println!("Tower: 10^({}depth) with base {}", if neg { "-" } else { "" }, base); } _ => {} // Handle other cases if necessary } } } // Handle edge cases let edge_cases = vec![ "0!", // 1 "1!", // 1 "(-5)!", // Complex infinity "0.5!", // Uses gamma function "!5", // Subfactorial (derangements) "5?", // Termial (triangular number) ]; for case in edge_cases { let jobs = parse(case, true); println!("Parsed: {}", case); } } ``` -------------------------------- ### Process Comments for Calculations and Replies Source: https://context7.com/tolik518/factorion-bot/llms.txt Processes comments by extracting mathematical expressions, performing calculations, and generating appropriate replies. This workflow involves creating a `Comment` object, extracting calculable jobs, executing the calculations, and finally formatting the result into a human-readable reply string. It supports command modifiers like `[shorten]`. ```rust use factorion_lib::{Comment, Commands}; fn main() { factorion_lib::init_default().unwrap(); // Create and process a comment let text = "What is 24! [shorten]"; let metadata = (); // Your custom metadata type let pre_commands = Commands::NONE; let max_length = 10000; // Step 1: Construct comment from raw text let comment = Comment::new(text, metadata, pre_commands, max_length); // Step 2: Extract calculations let comment = comment.extract(); println!("Found {} calculations", comment.calculation_list.len()); // Step 3: Execute calculations let comment = comment.calc(); if comment.status.factorials_found { println!("Calculations completed successfully"); } // Step 4: Generate reply text let reply: String = comment.get_reply(); println!("Reply: {}", reply); // Output: "The factorial of 24 is 6.204484017332394 × 10^23\n\n*^(This action was performed by a bot.)*" } ``` -------------------------------- ### Parse Factorial Expressions from Text Source: https://context7.com/tolik518/factorion-bot/llms.txt Parses input text to extract various factorial expressions, including standard factorials, termials, nested expressions, constants, multifactorials, and subfactorials. It returns a vector of `CalculationJob` structs, each representing a mathematical operation to be performed. The `parse` function supports different mathematical notations and can be configured for termial support. ```rust use factorion_lib::{parse, CalculationJob}; fn main() { factorion_lib::init_default().unwrap(); // Parse factorial expressions from text let text = "The answer is 5! which equals 120"; let jobs: Vec = parse(text, false); // Returns: [CalculationJob { base: Num(5), level: 1, negative: 0 }] // Parse with termial support enabled let text_termial = "Calculate 10? for the triangular number"; let jobs = parse(text_termial, true); // Returns: [CalculationJob { base: Num(10), level: -1, negative: 0 }] // Parse nested expressions let nested = "Try (5!)! for a factorial of a factorial"; let jobs = parse(nested, false); // Returns nested CalculationJob with Calc(Box) structure // Parse with constants let constants = "Calculate pi! and e!"; let jobs = parse(constants, false); // Extracts pi and e as Number::Float values // Parse multifactorials let multi = "The triple factorial 10!!!"; let jobs = parse(multi, false); // Returns: [CalculationJob { base: Num(10), level: 3, negative: 0 }] // Parse subfactorial (derangements) let subfact = "Derangements !5 equals 44"; let jobs = parse(subfact, false); // Returns: [CalculationJob { base: Num(5), level: 0, negative: 0 }] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.