mirror of
				https://github.com/pragma-/pbot.git
				synced 2025-10-31 06:37:35 +01:00 
			
		
		
		
	Add FactoidsSQLite
This is a subclass of DualIndexSQLiteObject with additional methods specific to Factoid-related functionality.
This commit is contained in:
		
							parent
							
								
									c93602a34e
								
							
						
					
					
						commit
						e73d890246
					
				
							
								
								
									
										77
									
								
								PBot/FactoidsSQLite.pm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								PBot/FactoidsSQLite.pm
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,77 @@ | ||||
| # File: FactoidsSQLite.pm | ||||
| # Author: pragma_ | ||||
| # | ||||
| # Purpose: SQLite backend for Factoids; adds factoid-specific functionality | ||||
| # to DualIndexSQLiteObject parent class. | ||||
| 
 | ||||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||
| 
 | ||||
| package PBot::FactoidsSQLite; | ||||
| 
 | ||||
| use parent 'PBot::DualIndexSQLiteObject'; | ||||
| 
 | ||||
| use warnings; use strict; | ||||
| use feature 'unicode_strings'; | ||||
| 
 | ||||
| sub new { | ||||
|     my ($proto, %conf) = @_; | ||||
|     my $class = ref($proto) || $proto; | ||||
|     my $self  = bless {}, $class; | ||||
|     Carp::croak("Missing pbot reference to " . __FILE__) unless exists $conf{pbot}; | ||||
|     $self->{pbot} = $conf{pbot}; | ||||
|     $self->SUPER::initialize(%conf); | ||||
|     return $self; | ||||
| } | ||||
| 
 | ||||
| sub get_all_by_trigger { | ||||
|     my ($self, $index2) = @_; | ||||
| 
 | ||||
|     my $data = eval { | ||||
|         my $sth = $self->{dbh}->prepare('SELECT index1, index2, action FROM Stuff WHERE index2 = ?'); | ||||
|         $sth->execute($index2); | ||||
|         return $sth->fetchall_arrayref({}); | ||||
|     }; | ||||
| 
 | ||||
|     if ($@) { | ||||
|         $self->{pbot}->{logger}->log("Error in get_all_by_trigger: $@\n"); | ||||
|         return undef; | ||||
|     } | ||||
| 
 | ||||
|     return $data; | ||||
| } | ||||
| 
 | ||||
| sub get_regex_by_channel { | ||||
|     my ($self, $channel) = @_; | ||||
| 
 | ||||
|     my $data = eval { | ||||
|         my $d = []; | ||||
|         my $sth; | ||||
|         if (defined $channel) { | ||||
|             $sth = $self->{dbh}->prepare('SELECT index1, index2, action FROM Stuff WHERE index1 = ? AND type = "regex"'); | ||||
|             $sth->execute($channel); | ||||
|             push @$d, @{$sth->fetchall_arrayref({})}; | ||||
| 
 | ||||
|             if ($channel ne '.*') { | ||||
|                 $sth->execute('.*'); | ||||
|                 push @$d, @{$sth->fetchall_arrayref({})}; | ||||
|             } | ||||
|         } else { | ||||
|             $sth = $self->{dbh}->prepare('SELECT index1, index2, action FROM Stuff WHERE type = "regex"'); | ||||
|             $sth->execute; | ||||
|             push @$d, @{$sth->fetchall_arrayref({})}; | ||||
|         } | ||||
| 
 | ||||
|         return $d; | ||||
|     }; | ||||
| 
 | ||||
|     if ($@) { | ||||
|         $self->{pbot}->{logger}->log("Error in get_regex_by_channel: $@\n"); | ||||
|         return undef; | ||||
|     } | ||||
| 
 | ||||
|     return $data; | ||||
| } | ||||
| 
 | ||||
| 1; | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Pragmatic Software
						Pragmatic Software